mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
[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:
@@ -43,24 +43,28 @@ namespace Microsoft.Plugin.Shell
|
||||
{
|
||||
new PluginAdditionalOption()
|
||||
{
|
||||
Key = "LeaveShellOpen",
|
||||
DisplayLabel = Resources.wox_leave_shell_open,
|
||||
Value = _settings.LeaveShellOpen,
|
||||
Key = "ShellCommandExecution",
|
||||
DisplayLabel = Resources.wox_shell_command_execution,
|
||||
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()
|
||||
{
|
||||
Key = "ShellCommandExecution",
|
||||
DisplayLabel = Resources.wox_shell_command_execution,
|
||||
PluginOptionType = PluginAdditionalOption.AdditionalOptionType.Combobox,
|
||||
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,
|
||||
Key = "LeaveShellOpen",
|
||||
DisplayLabel = Resources.wox_leave_shell_open,
|
||||
Value = _settings.LeaveShellOpen,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -212,21 +216,63 @@ namespace Microsoft.Plugin.Shell
|
||||
}
|
||||
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);
|
||||
}
|
||||
else if (_settings.Shell == ExecutionShell.WindowsTerminal)
|
||||
else if (_settings.Shell == ExecutionShell.PowerShellSeven)
|
||||
{
|
||||
string arguments;
|
||||
if (_settings.LeaveShellOpen)
|
||||
{
|
||||
arguments = $"powershell -NoExit \"{command}\"";
|
||||
arguments = $"-NoExit -C \"{command}\"";
|
||||
}
|
||||
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);
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace Microsoft.Plugin.Shell.Properties {
|
||||
}
|
||||
|
||||
/// <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>
|
||||
public static string find_executable_file_and_run_it {
|
||||
get {
|
||||
@@ -70,7 +70,7 @@ namespace Microsoft.Plugin.Shell.Properties {
|
||||
}
|
||||
|
||||
/// <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>
|
||||
public static string run_command_in_command_prompt {
|
||||
get {
|
||||
@@ -79,7 +79,7 @@ namespace Microsoft.Plugin.Shell.Properties {
|
||||
}
|
||||
|
||||
/// <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>
|
||||
public static string run_command_in_powershell {
|
||||
get {
|
||||
@@ -88,11 +88,47 @@ namespace Microsoft.Plugin.Shell.Properties {
|
||||
}
|
||||
|
||||
/// <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>
|
||||
public static string run_command_in_windows_terminal {
|
||||
public static string run_command_in_powershell_seven {
|
||||
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>
|
||||
/// Looks up a localized string similar to Shell command execution.
|
||||
/// Looks up a localized string similar to Command execution.
|
||||
/// </summary>
|
||||
public static string wox_shell_command_execution {
|
||||
get {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,18 +145,34 @@
|
||||
<value>Keep shell open</value>
|
||||
</data>
|
||||
<data name="wox_shell_command_execution" xml:space="preserve">
|
||||
<value>Shell command execution</value>
|
||||
<value>Command execution</value>
|
||||
</data>
|
||||
<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 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 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 name="run_command_in_windows_terminal" xml:space="preserve">
|
||||
<value>Run command in Windows Terminal (wt.exe)</value>
|
||||
<data name="run_command_in_powershell_seven" xml:space="preserve">
|
||||
<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>
|
||||
</root>
|
||||
@@ -41,6 +41,9 @@ namespace Microsoft.Plugin.Shell
|
||||
Cmd = 0,
|
||||
Powershell = 1,
|
||||
RunCommand = 2,
|
||||
WindowsTerminal = 3,
|
||||
WindowsTerminalPowerShell = 3,
|
||||
WindowsTerminalPowerShellSeven = 4,
|
||||
WindowsTerminalCmd = 5,
|
||||
PowerShellSeven = 6,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,8 +54,13 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
|
||||
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)]
|
||||
public List<string> ComboBoxOptions { get; set; }
|
||||
public List<KeyValuePair<string, string>> ComboBoxItems { get; set; }
|
||||
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
public string TextValue { get; set; }
|
||||
@@ -91,5 +96,15 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
/// </summary>
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,12 +153,8 @@
|
||||
<ToggleSwitch x:Uid="ToggleSwitch" IsOn="{x:Bind ViewModel.TabSelectsContextButtons, Mode=TwoWay}" />
|
||||
</controls:SettingsCard>
|
||||
|
||||
<controls:SettingsCard
|
||||
x:Uid="PowerLauncher_UsePinyin"
|
||||
HeaderIcon="{ui:FontIcon FontFamily={StaticResource SymbolThemeFontFamily}, Glyph=}">
|
||||
<ToggleSwitch
|
||||
x:Uid="ToggleSwitch"
|
||||
IsOn="{x:Bind ViewModel.UsePinyin, Mode=TwoWay}" />
|
||||
<controls:SettingsCard x:Uid="PowerLauncher_UsePinyin" HeaderIcon="{ui:FontIcon FontFamily={StaticResource SymbolThemeFontFamily}, Glyph=}">
|
||||
<ToggleSwitch x:Uid="ToggleSwitch" IsOn="{x:Bind ViewModel.UsePinyin, Mode=TwoWay}" />
|
||||
</controls:SettingsCard>
|
||||
|
||||
<controls:SettingsCard x:Uid="PowerLauncher_GenerateThumbnailsFromFiles">
|
||||
@@ -388,8 +384,10 @@
|
||||
Visibility="{x:Bind Path=ShowComboBox, Converter={StaticResource BoolToVisibilityConverter}}">
|
||||
<ComboBox
|
||||
MinWidth="{StaticResource SettingActionControlMinWidth}"
|
||||
ItemsSource="{x:Bind Path=ComboBoxOptions}"
|
||||
SelectedIndex="{x:Bind Path=ComboBoxValue, Mode=TwoWay}" />
|
||||
DisplayMemberPath="Key"
|
||||
ItemsSource="{x:Bind Path=ComboBoxItems}"
|
||||
SelectedValue="{x:Bind Path=ComboBoxValue, Mode=TwoWay}"
|
||||
SelectedValuePath="Value" />
|
||||
</controls:SettingsCard>
|
||||
<!-- TextBox setting -->
|
||||
<controls:SettingsCard
|
||||
@@ -456,8 +454,10 @@
|
||||
IsEnabled="{x:Bind Path=SecondSettingIsEnabled, Mode=OneWay}">
|
||||
<ComboBox
|
||||
MinWidth="{StaticResource SettingActionControlMinWidth}"
|
||||
ItemsSource="{x:Bind Path=ComboBoxOptions}"
|
||||
SelectedIndex="{x:Bind Path=ComboBoxValue, Mode=TwoWay}" />
|
||||
DisplayMemberPath="Key"
|
||||
ItemsSource="{x:Bind Path=ComboBoxItems}"
|
||||
SelectedValue="{x:Bind Path=ComboBoxValue, Mode=TwoWay}"
|
||||
SelectedValuePath="Value" />
|
||||
</controls:SettingsCard>
|
||||
</StackPanel>
|
||||
<!-- Checkbox And TextBox setting -->
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
|
||||
@@ -47,18 +48,18 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
|
||||
// ComboBox setting
|
||||
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
|
||||
{
|
||||
if (value != _additionalOption.ComboBoxValue)
|
||||
if (int.Parse(value, CultureInfo.InvariantCulture) != _additionalOption.ComboBoxValue)
|
||||
{
|
||||
_additionalOption.ComboBoxValue = value;
|
||||
_additionalOption.ComboBoxValue = int.Parse(value, CultureInfo.InvariantCulture);
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user