From 6604710a3ffc1c0f7a46be890fb65978b07f115e Mon Sep 17 00:00:00 2001 From: Yusyuriv Date: Sun, 3 Nov 2024 12:42:14 +0600 Subject: [PATCH 1/2] Fix `inputWithFileBtn` not working in SettingsTemplate.yml --- .../Plugin/JsonRPCPluginSettings.cs | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Flow.Launcher.Core/Plugin/JsonRPCPluginSettings.cs b/Flow.Launcher.Core/Plugin/JsonRPCPluginSettings.cs index 408d9785d60..53b8bf5d600 100644 --- a/Flow.Launcher.Core/Plugin/JsonRPCPluginSettings.cs +++ b/Flow.Launcher.Core/Plugin/JsonRPCPluginSettings.cs @@ -4,8 +4,15 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Documents; +using System.Windows.Forms; using Flow.Launcher.Infrastructure.Storage; using Flow.Launcher.Plugin; +using CheckBox = System.Windows.Controls.CheckBox; +using ComboBox = System.Windows.Controls.ComboBox; +using Control = System.Windows.Controls.Control; +using Orientation = System.Windows.Controls.Orientation; +using TextBox = System.Windows.Controls.TextBox; +using UserControl = System.Windows.Controls.UserControl; namespace Flow.Launcher.Core.Plugin { @@ -224,6 +231,7 @@ public Control CreateSettingPanel() break; } case "inputWithFileBtn": + case "inputWithFolderBtn": { var textBox = new TextBox() { @@ -243,6 +251,24 @@ public Control CreateSettingPanel() Margin = new Thickness(10, 0, 0, 0), Content = "Browse" }; + Btn.Click += (_, _) => + { + CommonDialog dialog = type switch + { + "inputWithFolderBtn" => new FolderBrowserDialog(), + _ => new OpenFileDialog(), + }; + if (dialog.ShowDialog() != DialogResult.OK) return; + + var path = dialog switch + { + FolderBrowserDialog folderDialog => folderDialog.SelectedPath, + OpenFileDialog fileDialog => fileDialog.FileName, + }; + textBox.Text = path; + Settings[attribute.Name] = path; + }; + var dockPanel = new DockPanel() { Margin = settingControlMargin }; DockPanel.SetDock(Btn, Dock.Right); From 1bdfc3009d4f0f21f892cc65584a19882b14de8e Mon Sep 17 00:00:00 2001 From: Yusyuriv Date: Sun, 3 Nov 2024 13:28:24 +0600 Subject: [PATCH 2/2] Add `using` when creating a file/folder dialog --- Flow.Launcher.Core/Plugin/JsonRPCPluginSettings.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flow.Launcher.Core/Plugin/JsonRPCPluginSettings.cs b/Flow.Launcher.Core/Plugin/JsonRPCPluginSettings.cs index 53b8bf5d600..50eb30998d3 100644 --- a/Flow.Launcher.Core/Plugin/JsonRPCPluginSettings.cs +++ b/Flow.Launcher.Core/Plugin/JsonRPCPluginSettings.cs @@ -253,7 +253,7 @@ public Control CreateSettingPanel() Btn.Click += (_, _) => { - CommonDialog dialog = type switch + using CommonDialog dialog = type switch { "inputWithFolderBtn" => new FolderBrowserDialog(), _ => new OpenFileDialog(),