From 0990e6d005426fd1b5f41be0a435df5dd73b0f92 Mon Sep 17 00:00:00 2001
From: Piotrekol <4990365+Piotrekol@users.noreply.github.com>
Date: Tue, 7 Jun 2022 21:17:08 +0200
Subject: [PATCH] Add: Use modern directory/file selector dialogs
---
App/Properties/Resources.Designer.cs | 2 +-
GuiComponents/GuiComponents.csproj | 1 +
GuiComponents/UserDialogs.cs | 47 ++++++++++++++++------------
InnoSetup/script.iss | 2 ++
4 files changed, 31 insertions(+), 21 deletions(-)
diff --git a/App/Properties/Resources.Designer.cs b/App/Properties/Resources.Designer.cs
index 5881f1b..b1229d8 100644
--- a/App/Properties/Resources.Designer.cs
+++ b/App/Properties/Resources.Designer.cs
@@ -19,7 +19,7 @@ namespace App.Properties {
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
diff --git a/GuiComponents/GuiComponents.csproj b/GuiComponents/GuiComponents.csproj
index 0b35996..03ec3b8 100644
--- a/GuiComponents/GuiComponents.csproj
+++ b/GuiComponents/GuiComponents.csproj
@@ -11,6 +11,7 @@
true
+
diff --git a/GuiComponents/UserDialogs.cs b/GuiComponents/UserDialogs.cs
index c87d72e..fa70270 100644
--- a/GuiComponents/UserDialogs.cs
+++ b/GuiComponents/UserDialogs.cs
@@ -3,6 +3,7 @@
using System.Windows.Forms;
using Common;
using GuiComponents.Interfaces;
+using Microsoft.WindowsAPICodePack.Dialogs;
namespace GuiComponents
{
@@ -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
diff --git a/InnoSetup/script.iss b/InnoSetup/script.iss
index 3bc072b..f7ab9fe 100644
--- a/InnoSetup/script.iss
+++ b/InnoSetup/script.iss
@@ -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]