Skip to content

Commit

Permalink
Add: Use modern directory/file selector dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotrekol committed Jun 7, 2022
1 parent 5f0955a commit 0990e6d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 21 deletions.
2 changes: 1 addition & 1 deletion App/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions GuiComponents/GuiComponents.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft-WindowsAPICodePack-Shell" Version="1.1.4" />
<PackageReference Include="System.Data.DataSetExtensions" Version="4.*" />
<PackageReference Include="Microsoft.CSharp" Version="4.*" />
</ItemGroup>
Expand Down
47 changes: 27 additions & 20 deletions GuiComponents/UserDialogs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Windows.Forms;
using Common;
using GuiComponents.Interfaces;
using Microsoft.WindowsAPICodePack.Dialogs;

namespace GuiComponents
{
Expand All @@ -16,37 +17,43 @@ public bool IsThisPathCorrect(string path)
return dialogResult == DialogResult.Yes;
}


public string SelectDirectory(string text)
{
return SelectDirectory(text, false);
}

public string SelectDirectory(string text, bool showNewFolder = false)
{
FolderBrowserDialog dialog = new FolderBrowserDialog();
//set description and base folder for browsing

dialog.ShowNewFolderButton = true;
dialog.Description = text;
dialog.RootFolder = Environment.SpecialFolder.MyComputer;
if (dialog.ShowDialog() == DialogResult.OK && Directory.Exists((dialog.SelectedPath)))
var dialog = new CommonOpenFileDialog
{
return dialog.SelectedPath;
}
IsFolderPicker = true,
Title = text
};
if (dialog.ShowDialog() == CommonFileDialogResult.Ok && Directory.Exists(dialog.FileName))
return dialog.FileName;

return string.Empty;
}
public string SelectFile(string text, string types = "", string filename = "")

public string SelectFile(string text, string filters = "", string filename = "")
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = types; //"Collection database (*.db)|*.db";
openFileDialog.FileName = filename; //"collection.db";
openFileDialog.Multiselect = false;
var result = openFileDialog.ShowDialog();
if (result == DialogResult.OK)
return openFileDialog.FileName;
else
return string.Empty;
var dialog = new CommonOpenFileDialog
{
Multiselect = false,
Title = text
};
if (!string.IsNullOrEmpty(filters))
{
var split = filters.Split(new[] { '|' }, 2);
dialog.Filters.Add(new CommonFileDialogFilter(split[0], split[1]));
}

if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
return dialog.FileName;

return string.Empty;
}

public string SaveFile(string title, string types = "all|*.*")
{
SaveFileDialog saveFileDialog = new SaveFileDialog
Expand Down
2 changes: 2 additions & 0 deletions InnoSetup/script.iss
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ Source: "..\App\bin\Release\net48\Microsoft.Win32.Registry.dll"; DestDir: "{app}
Source: "..\App\bin\Release\net48\System.Security.AccessControl.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\App\bin\Release\net48\SharpCompress.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\App\bin\Release\net48\CommandLine.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\App\bin\Release\net48\Microsoft.WindowsAPICodePack.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\App\bin\Release\net48\Microsoft.WindowsAPICodePack.Shell.dll"; DestDir: "{app}"; Flags: ignoreversion
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Icons]
Expand Down

0 comments on commit 0990e6d

Please sign in to comment.