Skip to content

Commit

Permalink
Fix behavior for "Default File Path"
Browse files Browse the repository at this point in the history
  • Loading branch information
cyanfish committed Oct 7, 2023
1 parent ff22458 commit 745b274
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions NAPS2.Lib/EtoForms/EtoDialogHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ public override bool PromptToSavePdfOrImage(string? defaultPath, out string? sav
{
lastExt = "pdf";
}
var defaultFileName = _addExt ? $".{lastExt}" : null;
var sd = new SaveFileDialog
{
FileName = Path.IsPathRooted(defaultPath) ? Path.GetFileName(defaultPath) : defaultFileName
FileName = GetDefaultFileName(defaultPath, lastExt)
};
_fileFilters.Set(sd, FileFilterGroup.Pdf | FileFilterGroup.Image, lastExt);
SetDir(sd, defaultPath);
Expand All @@ -40,10 +39,9 @@ public override bool PromptToSavePdfOrImage(string? defaultPath, out string? sav

public override bool PromptToSavePdf(string? defaultPath, out string? savePath)
{
var defaultFileName = _addExt ? $".pdf" : null;
var sd = new SaveFileDialog
{
FileName = Path.IsPathRooted(defaultPath) ? Path.GetFileName(defaultPath) : defaultFileName
FileName = GetDefaultFileName(defaultPath, "pdf")
};
_fileFilters.Set(sd, FileFilterGroup.Pdf);
SetDir(sd, defaultPath);
Expand All @@ -63,10 +61,9 @@ public override bool PromptToSaveImage(string? defaultPath, out string? savePath
{
lastExt = "jpg";
}
var defaultFileName = _addExt ? $".{lastExt}" : null;
var sd = new SaveFileDialog
{
FileName = Path.IsPathRooted(defaultPath) ? Path.GetFileName(defaultPath) : defaultFileName
FileName = GetDefaultFileName(defaultPath, lastExt)
};
var filterGroups = EtoPlatform.Current.IsGtk
? FileFilterGroup.AllImages | FileFilterGroup.Image
Expand All @@ -83,6 +80,15 @@ public override bool PromptToSaveImage(string? defaultPath, out string? savePath
return false;
}

private string? GetDefaultFileName(string? defaultPath, string ext)
{
if (string.IsNullOrEmpty(defaultPath))
{
return _addExt ? $".{ext}" : null;
}
return defaultPath;
}

private void SetDir(SaveFileDialog dialog, string? defaultPath)
{
string? path;
Expand Down

0 comments on commit 745b274

Please sign in to comment.