[PTRun][Shell]Shell selection and combobox improvements (#28972)

* Make combobox items sortable

* Update plugin settings

* settings description

* fix settings hang on outdated plugin code

* spell fixes, shell implementation, translation improvements

* rename property

* backward compatibility

* comment changes

* comment changes

* review feedback 1

* review feedback 2

* Code clean up
This commit is contained in:
Heiko
2023-10-11 14:54:49 +02:00
committed by GitHub
parent 5d669df21a
commit 19827d0093
7 changed files with 175 additions and 49 deletions

View File

@@ -43,24 +43,28 @@ namespace Microsoft.Plugin.Shell
{ {
new PluginAdditionalOption() new PluginAdditionalOption()
{ {
Key = "LeaveShellOpen", Key = "ShellCommandExecution",
DisplayLabel = Resources.wox_leave_shell_open, DisplayLabel = Resources.wox_shell_command_execution,
Value = _settings.LeaveShellOpen, DisplayDescription = Resources.wox_shell_command_execution_description,
PluginOptionType = PluginAdditionalOption.AdditionalOptionType.Combobox,
ComboBoxItems = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>(Resources.find_executable_file_and_run_it, "2"),
new KeyValuePair<string, string>(Resources.run_command_in_command_prompt, "0"),
new KeyValuePair<string, string>(Resources.run_command_in_powershell, "1"),
new KeyValuePair<string, string>(Resources.run_command_in_powershell_seven, "6"),
new KeyValuePair<string, string>(Resources.run_command_in_windows_terminal_cmd, "5"),
new KeyValuePair<string, string>(Resources.run_command_in_windows_terminal_powershell, "3"),
new KeyValuePair<string, string>(Resources.run_command_in_windows_terminal_powershell_seven, "4"),
},
ComboBoxValue = (int)_settings.Shell,
}, },
new PluginAdditionalOption() new PluginAdditionalOption()
{ {
Key = "ShellCommandExecution", Key = "LeaveShellOpen",
DisplayLabel = Resources.wox_shell_command_execution, DisplayLabel = Resources.wox_leave_shell_open,
PluginOptionType = PluginAdditionalOption.AdditionalOptionType.Combobox, Value = _settings.LeaveShellOpen,
ComboBoxOptions = new List<string>
{
Resources.run_command_in_command_prompt,
Resources.run_command_in_powershell,
Resources.find_executable_file_and_run_it,
Resources.run_command_in_windows_terminal,
},
ComboBoxValue = (int)_settings.Shell,
}, },
}; };
@@ -212,21 +216,63 @@ namespace Microsoft.Plugin.Shell
} }
else else
{ {
arguments = $"\"{command} ; Read-Host -Prompt \\\"Press Enter to continue\\\"\""; arguments = $"\"{command} ; Read-Host -Prompt \\\"{Resources.run_plugin_cmd_wait_message}\\\"\"";
} }
info = ShellCommand.SetProcessStartInfo("powershell.exe", workingDirectory, arguments, runAsVerbArg); info = ShellCommand.SetProcessStartInfo("powershell.exe", workingDirectory, arguments, runAsVerbArg);
} }
else if (_settings.Shell == ExecutionShell.WindowsTerminal) else if (_settings.Shell == ExecutionShell.PowerShellSeven)
{ {
string arguments; string arguments;
if (_settings.LeaveShellOpen) if (_settings.LeaveShellOpen)
{ {
arguments = $"powershell -NoExit \"{command}\""; arguments = $"-NoExit -C \"{command}\"";
} }
else else
{ {
arguments = $"powershell \"{command}\""; arguments = $"-C \"{command} ; Read-Host -Prompt \\\"{Resources.run_plugin_cmd_wait_message}\\\"\"";
}
info = ShellCommand.SetProcessStartInfo("pwsh.exe", workingDirectory, arguments, runAsVerbArg);
}
else if (_settings.Shell == ExecutionShell.WindowsTerminalCmd)
{
string arguments;
if (_settings.LeaveShellOpen)
{
arguments = $"cmd.exe /k \"{command}\"";
}
else
{
arguments = $"cmd.exe /c \"{command}\" & pause";
}
info = ShellCommand.SetProcessStartInfo("wt.exe", workingDirectory, arguments, runAsVerbArg);
}
else if (_settings.Shell == ExecutionShell.WindowsTerminalPowerShell)
{
string arguments;
if (_settings.LeaveShellOpen)
{
arguments = $"powershell -NoExit -C \"{command}\"";
}
else
{
arguments = $"powershell -C \"{command}\"";
}
info = ShellCommand.SetProcessStartInfo("wt.exe", workingDirectory, arguments, runAsVerbArg);
}
else if (_settings.Shell == ExecutionShell.WindowsTerminalPowerShellSeven)
{
string arguments;
if (_settings.LeaveShellOpen)
{
arguments = $"pwsh.exe -NoExit -C \"{command}\"";
}
else
{
arguments = $"pwsh.exe -C \"{command}\"";
} }
info = ShellCommand.SetProcessStartInfo("wt.exe", workingDirectory, arguments, runAsVerbArg); info = ShellCommand.SetProcessStartInfo("wt.exe", workingDirectory, arguments, runAsVerbArg);

View File

@@ -61,7 +61,7 @@ namespace Microsoft.Plugin.Shell.Properties {
} }
/// <summary> /// <summary>
/// Looks up a localized string similar to Find executable file and run it. /// Looks up a localized string similar to Find and run executable file.
/// </summary> /// </summary>
public static string find_executable_file_and_run_it { public static string find_executable_file_and_run_it {
get { get {
@@ -70,7 +70,7 @@ namespace Microsoft.Plugin.Shell.Properties {
} }
/// <summary> /// <summary>
/// Looks up a localized string similar to Run command in Command Prompt (cmd.exe). /// Looks up a localized string similar to Run in Command Prompt (cmd.exe).
/// </summary> /// </summary>
public static string run_command_in_command_prompt { public static string run_command_in_command_prompt {
get { get {
@@ -79,7 +79,7 @@ namespace Microsoft.Plugin.Shell.Properties {
} }
/// <summary> /// <summary>
/// Looks up a localized string similar to Run command in PowerShell (PowerShell.exe). /// Looks up a localized string similar to Run in PowerShell (PowerShell.exe).
/// </summary> /// </summary>
public static string run_command_in_powershell { public static string run_command_in_powershell {
get { get {
@@ -88,11 +88,47 @@ namespace Microsoft.Plugin.Shell.Properties {
} }
/// <summary> /// <summary>
/// Looks up a localized string similar to Run command in Windows Terminal (wt.exe). /// Looks up a localized string similar to Run in PowerShell 7 (pwsh.exe).
/// </summary> /// </summary>
public static string run_command_in_windows_terminal { public static string run_command_in_powershell_seven {
get { get {
return ResourceManager.GetString("run_command_in_windows_terminal", resourceCulture); return ResourceManager.GetString("run_command_in_powershell_seven", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Run in Command Prompt (cmd.exe) using Windows Terminal.
/// </summary>
public static string run_command_in_windows_terminal_cmd {
get {
return ResourceManager.GetString("run_command_in_windows_terminal_cmd", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Run in PowerShell (PowerShell.exe) using Windows Terminal.
/// </summary>
public static string run_command_in_windows_terminal_powershell {
get {
return ResourceManager.GetString("run_command_in_windows_terminal_powershell", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Run in PowerShell 7 (pwsh.exe) using Windows Terminal.
/// </summary>
public static string run_command_in_windows_terminal_powershell_seven {
get {
return ResourceManager.GetString("run_command_in_windows_terminal_powershell_seven", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Press Enter to continue.
/// </summary>
public static string run_plugin_cmd_wait_message {
get {
return ResourceManager.GetString("run_plugin_cmd_wait_message", resourceCulture);
} }
} }
@@ -178,12 +214,21 @@ namespace Microsoft.Plugin.Shell.Properties {
} }
/// <summary> /// <summary>
/// Looks up a localized string similar to Shell command execution. /// Looks up a localized string similar to Command execution.
/// </summary> /// </summary>
public static string wox_shell_command_execution { public static string wox_shell_command_execution {
get { get {
return ResourceManager.GetString("wox_shell_command_execution", resourceCulture); return ResourceManager.GetString("wox_shell_command_execution", resourceCulture);
} }
} }
/// <summary>
/// Looks up a localized string similar to All entries that using the Windows Terminal forcing the Windows Terminal as console host regardless of the system setting.
/// </summary>
public static string wox_shell_command_execution_description {
get {
return ResourceManager.GetString("wox_shell_command_execution_description", resourceCulture);
}
}
} }
} }

View File

@@ -145,18 +145,34 @@
<value>Keep shell open</value> <value>Keep shell open</value>
</data> </data>
<data name="wox_shell_command_execution" xml:space="preserve"> <data name="wox_shell_command_execution" xml:space="preserve">
<value>Shell command execution</value> <value>Command execution</value>
</data> </data>
<data name="run_command_in_command_prompt" xml:space="preserve"> <data name="run_command_in_command_prompt" xml:space="preserve">
<value>Run command in Command Prompt (cmd.exe)</value> <value>Run in Command Prompt (cmd.exe)</value>
</data> </data>
<data name="run_command_in_powershell" xml:space="preserve"> <data name="run_command_in_powershell" xml:space="preserve">
<value>Run command in PowerShell (PowerShell.exe)</value> <value>Run in PowerShell (PowerShell.exe)</value>
</data> </data>
<data name="find_executable_file_and_run_it" xml:space="preserve"> <data name="find_executable_file_and_run_it" xml:space="preserve">
<value>Find executable file and run it</value> <value>Find and run the executable file</value>
</data> </data>
<data name="run_command_in_windows_terminal" xml:space="preserve"> <data name="run_command_in_powershell_seven" xml:space="preserve">
<value>Run command in Windows Terminal (wt.exe)</value> <value>Run in PowerShell 7 (pwsh.exe)</value>
</data>
<data name="run_command_in_windows_terminal_cmd" xml:space="preserve">
<value>Run in Command Prompt (cmd.exe) using Windows Terminal</value>
</data>
<data name="run_command_in_windows_terminal_powershell" xml:space="preserve">
<value>Run in PowerShell (PowerShell.exe) using Windows Terminal</value>
</data>
<data name="run_command_in_windows_terminal_powershell_seven" xml:space="preserve">
<value>Run in PowerShell 7 (pwsh.exe) using Windows Terminal</value>
</data>
<data name="run_plugin_cmd_wait_message" xml:space="preserve">
<value>Press Enter to continue</value>
<comment>"Enter" means the Enter key on the keyboard.</comment>
</data>
<data name="wox_shell_command_execution_description" xml:space="preserve">
<value>All entries using the Windows Terminal force the Windows Terminal as the console host regardless of the system settings</value>
</data> </data>
</root> </root>

View File

@@ -41,6 +41,9 @@ namespace Microsoft.Plugin.Shell
Cmd = 0, Cmd = 0,
Powershell = 1, Powershell = 1,
RunCommand = 2, RunCommand = 2,
WindowsTerminal = 3, WindowsTerminalPowerShell = 3,
WindowsTerminalPowerShellSeven = 4,
WindowsTerminalCmd = 5,
PowerShellSeven = 6,
} }
} }

View File

@@ -54,8 +54,13 @@ namespace Microsoft.PowerToys.Settings.UI.Library
public int ComboBoxValue { get; set; } public int ComboBoxValue { get; set; }
/// <summary>
/// Gets or sets the list of dropdown items for the ComboBox. Please use the item name as Key and an integer as Value.
/// The value gets converted in settings UI to an integer and will be saved in <see cref="ComboBoxValue"/>.
/// You can define the visibility order in settings ui by arranging the list items.
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public List<string> ComboBoxOptions { get; set; } public List<KeyValuePair<string, string>> ComboBoxItems { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string TextValue { get; set; } public string TextValue { get; set; }
@@ -91,5 +96,15 @@ namespace Microsoft.PowerToys.Settings.UI.Library
/// </summary> /// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public double? NumberBoxLargeChange { get; set; } public double? NumberBoxLargeChange { get; set; }
// Outdated properties kept for backward compatibility with third-party plugins. (They are only required to not have old third-party plugins crashing when propagating their plugin options.)
#pragma warning disable SA1623 // Property summary documentation should match accessors
/// <summary>
/// PLEASE DON'T USE ANYMORE!! (The property was used for the list of combobox items in the past and is not functional anymore.)
/// </summary>
[JsonIgnore]
public List<string> ComboBoxOptions { get; set; }
#pragma warning restore SA1623 // Property summary documentation should match accessors
} }
} }

View File

@@ -153,12 +153,8 @@
<ToggleSwitch x:Uid="ToggleSwitch" IsOn="{x:Bind ViewModel.TabSelectsContextButtons, Mode=TwoWay}" /> <ToggleSwitch x:Uid="ToggleSwitch" IsOn="{x:Bind ViewModel.TabSelectsContextButtons, Mode=TwoWay}" />
</controls:SettingsCard> </controls:SettingsCard>
<controls:SettingsCard <controls:SettingsCard x:Uid="PowerLauncher_UsePinyin" HeaderIcon="{ui:FontIcon FontFamily={StaticResource SymbolThemeFontFamily}, Glyph=&#xE98A;}">
x:Uid="PowerLauncher_UsePinyin" <ToggleSwitch x:Uid="ToggleSwitch" IsOn="{x:Bind ViewModel.UsePinyin, Mode=TwoWay}" />
HeaderIcon="{ui:FontIcon FontFamily={StaticResource SymbolThemeFontFamily}, Glyph=&#xE98A;}">
<ToggleSwitch
x:Uid="ToggleSwitch"
IsOn="{x:Bind ViewModel.UsePinyin, Mode=TwoWay}" />
</controls:SettingsCard> </controls:SettingsCard>
<controls:SettingsCard x:Uid="PowerLauncher_GenerateThumbnailsFromFiles"> <controls:SettingsCard x:Uid="PowerLauncher_GenerateThumbnailsFromFiles">
@@ -388,8 +384,10 @@
Visibility="{x:Bind Path=ShowComboBox, Converter={StaticResource BoolToVisibilityConverter}}"> Visibility="{x:Bind Path=ShowComboBox, Converter={StaticResource BoolToVisibilityConverter}}">
<ComboBox <ComboBox
MinWidth="{StaticResource SettingActionControlMinWidth}" MinWidth="{StaticResource SettingActionControlMinWidth}"
ItemsSource="{x:Bind Path=ComboBoxOptions}" DisplayMemberPath="Key"
SelectedIndex="{x:Bind Path=ComboBoxValue, Mode=TwoWay}" /> ItemsSource="{x:Bind Path=ComboBoxItems}"
SelectedValue="{x:Bind Path=ComboBoxValue, Mode=TwoWay}"
SelectedValuePath="Value" />
</controls:SettingsCard> </controls:SettingsCard>
<!-- TextBox setting --> <!-- TextBox setting -->
<controls:SettingsCard <controls:SettingsCard
@@ -456,8 +454,10 @@
IsEnabled="{x:Bind Path=SecondSettingIsEnabled, Mode=OneWay}"> IsEnabled="{x:Bind Path=SecondSettingIsEnabled, Mode=OneWay}">
<ComboBox <ComboBox
MinWidth="{StaticResource SettingActionControlMinWidth}" MinWidth="{StaticResource SettingActionControlMinWidth}"
ItemsSource="{x:Bind Path=ComboBoxOptions}" DisplayMemberPath="Key"
SelectedIndex="{x:Bind Path=ComboBoxValue, Mode=TwoWay}" /> ItemsSource="{x:Bind Path=ComboBoxItems}"
SelectedValue="{x:Bind Path=ComboBoxValue, Mode=TwoWay}"
SelectedValuePath="Value" />
</controls:SettingsCard> </controls:SettingsCard>
</StackPanel> </StackPanel>
<!-- Checkbox And TextBox setting --> <!-- Checkbox And TextBox setting -->

View File

@@ -4,6 +4,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Globalization;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using Microsoft.PowerToys.Settings.UI.Library; using Microsoft.PowerToys.Settings.UI.Library;
@@ -47,18 +48,18 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
// ComboBox setting // ComboBox setting
public bool ShowComboBox => _additionalOption.PluginOptionType == PluginAdditionalOption.AdditionalOptionType.Combobox && public bool ShowComboBox => _additionalOption.PluginOptionType == PluginAdditionalOption.AdditionalOptionType.Combobox &&
_additionalOption.ComboBoxOptions != null && _additionalOption.ComboBoxOptions.Count > 0; _additionalOption.ComboBoxItems != null && _additionalOption.ComboBoxItems.Count > 0;
public List<string> ComboBoxOptions => _additionalOption.ComboBoxOptions; public List<KeyValuePair<string, string>> ComboBoxItems => _additionalOption.ComboBoxItems;
public int ComboBoxValue public string ComboBoxValue
{ {
get => _additionalOption.ComboBoxValue; get => _additionalOption.ComboBoxValue.ToString(CultureInfo.InvariantCulture);
set set
{ {
if (value != _additionalOption.ComboBoxValue) if (int.Parse(value, CultureInfo.InvariantCulture) != _additionalOption.ComboBoxValue)
{ {
_additionalOption.ComboBoxValue = value; _additionalOption.ComboBoxValue = int.Parse(value, CultureInfo.InvariantCulture);
NotifyPropertyChanged(); NotifyPropertyChanged();
} }
} }