From e856e05fad210f3fb243b40ec7bbf5b746b487ea Mon Sep 17 00:00:00 2001 From: gokcekantarci <115616017+gokcekantarci@users.noreply.github.com> Date: Mon, 11 Sep 2023 13:54:06 +0300 Subject: [PATCH] [PTRun][Shell]Select which shell is used (#28121) * [PTRun] LeaveShellOpen condition added to run command * [PTRun] Keep shell open added to shell plugin settings. * [PTRun] Unnecessary variable deleted. Formatting. * [PTRun] Variable name changed. * [PTRun] Shell selection * [PTRun] Bugfix * [PTRun] Review comments. * [PTRun] Revert commit * [PTRun] An enumaration is added to PluginAdditionalOption for selection types. --- .../Plugins/Microsoft.Plugin.Shell/Main.cs | 20 +++++++++ .../Properties/Resources.Designer.cs | 45 +++++++++++++++++++ .../Properties/Resources.resx | 15 +++++++ .../ShellPluginSettings.cs | 3 ++ .../PluginAdditionalOption.cs | 14 ++++++ .../SettingsXAML/Views/PowerLauncherPage.xaml | 20 ++++++--- .../PluginAdditionalOptionViewModel.cs | 24 +++++++++- 7 files changed, 134 insertions(+), 7 deletions(-) diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Shell/Main.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.Shell/Main.cs index 28441e0b7346..d458b7996a42 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Shell/Main.cs +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Shell/Main.cs @@ -47,6 +47,21 @@ public class Main : IPlugin, IPluginI18n, ISettingProvider, IContextMenu, ISavab DisplayLabel = Resources.wox_leave_shell_open, Value = _settings.LeaveShellOpen, }, + + new PluginAdditionalOption() + { + Key = "ShellCommandExecution", + DisplayLabel = Resources.wox_shell_command_execution, + SelectionTypeValue = (int)PluginAdditionalOption.SelectionType.Combobox, + ComboBoxOptions = new List + { + Resources.run_command_in_command_prompt, + Resources.run_command_in_powershell, + Resources.find_executable_file_and_run_it, + Resources.run_command_in_windows_terminal, + }, + Option = (int)_settings.Shell, + }, }; private PluginInitContext _context; @@ -418,12 +433,17 @@ public List LoadContextMenus(Result selectedResult) public void UpdateSettings(PowerLauncherPluginSettings settings) { var leaveShellOpen = false; + var shellOption = 2; if (settings != null && settings.AdditionalOptions != null) { var optionLeaveShellOpen = settings.AdditionalOptions.FirstOrDefault(x => x.Key == "LeaveShellOpen"); leaveShellOpen = optionLeaveShellOpen?.Value ?? leaveShellOpen; _settings.LeaveShellOpen = leaveShellOpen; + + var optionShell = settings.AdditionalOptions.FirstOrDefault(x => x.Key == "ShellCommandExecution"); + shellOption = optionShell?.Option ?? shellOption; + _settings.Shell = (ExecutionShell)shellOption; } Save(); diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Shell/Properties/Resources.Designer.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.Shell/Properties/Resources.Designer.cs index 0917fb2ed416..a120d9ec9b3d 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Shell/Properties/Resources.Designer.cs +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Shell/Properties/Resources.Designer.cs @@ -60,6 +60,42 @@ internal Resources() { } } + /// + /// Looks up a localized string similar to Find executable file and run it. + /// + public static string find_executable_file_and_run_it { + get { + return ResourceManager.GetString("find_executable_file_and_run_it", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Run command in Command Prompt (cmd.exe). + /// + public static string run_command_in_command_prompt { + get { + return ResourceManager.GetString("run_command_in_command_prompt", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Run command in PowerShell (PowerShell.exe). + /// + public static string run_command_in_powershell { + get { + return ResourceManager.GetString("run_command_in_powershell", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Run command in Windows Terminal (wt.exe). + /// + public static string run_command_in_windows_terminal { + get { + return ResourceManager.GetString("run_command_in_windows_terminal", resourceCulture); + } + } + /// /// Looks up a localized string similar to Keep shell open. /// @@ -140,5 +176,14 @@ public static string wox_plugin_cmd_run_as_user { return ResourceManager.GetString("wox_plugin_cmd_run_as_user", resourceCulture); } } + + /// + /// Looks up a localized string similar to Shell command execution. + /// + public static string wox_shell_command_execution { + get { + return ResourceManager.GetString("wox_shell_command_execution", resourceCulture); + } + } } } diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Shell/Properties/Resources.resx b/src/modules/launcher/Plugins/Microsoft.Plugin.Shell/Properties/Resources.resx index 78be67207714..dbc287304635 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Shell/Properties/Resources.resx +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Shell/Properties/Resources.resx @@ -144,4 +144,19 @@ Keep shell open + + Shell command execution + + + Run command in Command Prompt (cmd.exe) + + + Run command in PowerShell (PowerShell.exe) + + + Find executable file and run it + + + Run command in Windows Terminal (wt.exe) + \ No newline at end of file diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Shell/ShellPluginSettings.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.Shell/ShellPluginSettings.cs index 494f652a37d3..7785d0c07649 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Shell/ShellPluginSettings.cs +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Shell/ShellPluginSettings.cs @@ -2,7 +2,10 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System; using System.Collections.Generic; +using System.ComponentModel; +using System.Reflection; namespace Microsoft.Plugin.Shell { diff --git a/src/settings-ui/Settings.UI.Library/PluginAdditionalOption.cs b/src/settings-ui/Settings.UI.Library/PluginAdditionalOption.cs index e08e2d7eb6d5..362384c5346a 100644 --- a/src/settings-ui/Settings.UI.Library/PluginAdditionalOption.cs +++ b/src/settings-ui/Settings.UI.Library/PluginAdditionalOption.cs @@ -2,10 +2,18 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Collections.Generic; + namespace Microsoft.PowerToys.Settings.UI.Library { public class PluginAdditionalOption { + public enum SelectionType + { + Checkbox = 0, + Combobox = 1, + } + public string Key { get; set; } public string DisplayLabel { get; set; } @@ -16,5 +24,11 @@ public class PluginAdditionalOption public string DisplayDescription { get; set; } public bool Value { get; set; } + + public List ComboBoxOptions { get; set; } + + public int Option { get; set; } + + public int SelectionTypeValue { get; set; } } } diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Views/PowerLauncherPage.xaml b/src/settings-ui/Settings.UI/SettingsXAML/Views/PowerLauncherPage.xaml index 9eaa02f9c293..8df089122a69 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Views/PowerLauncherPage.xaml +++ b/src/settings-ui/Settings.UI/SettingsXAML/Views/PowerLauncherPage.xaml @@ -444,11 +444,21 @@ BorderThickness="0,0,0,0" ContentAlignment="Left" CornerRadius="0"> - + + + + _additionalOption.DisplayLabel; } + public string DisplayLabel => _additionalOption.DisplayLabel; - public string DisplayDescription { get => _additionalOption.DisplayDescription; } + public string DisplayDescription => _additionalOption.DisplayDescription; public bool Value { @@ -34,6 +35,25 @@ public bool Value } } + public List ComboBoxOptions => _additionalOption.ComboBoxOptions; + + public int Option + { + get => _additionalOption.Option; + set + { + if (value != _additionalOption.Option) + { + _additionalOption.Option = value; + NotifyPropertyChanged(); + } + } + } + + public bool ShowComboBox => _additionalOption.SelectionTypeValue == (int)PluginAdditionalOption.SelectionType.Combobox && _additionalOption.ComboBoxOptions != null && _additionalOption.ComboBoxOptions.Count > 0; + + public bool ShowCheckBox => _additionalOption.SelectionTypeValue == (int)PluginAdditionalOption.SelectionType.Checkbox; + public event PropertyChangedEventHandler PropertyChanged; private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")