Skip to content

Commit

Permalink
[PTRun][Shell]Select which shell is used (#28121)
Browse files Browse the repository at this point in the history
* [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.
  • Loading branch information
gokcekantarci authored Sep 11, 2023
1 parent 6ee326b commit e856e05
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 7 deletions.
20 changes: 20 additions & 0 deletions src/modules/launcher/Plugins/Microsoft.Plugin.Shell/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<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,
},
Option = (int)_settings.Shell,
},
};

private PluginInitContext _context;
Expand Down Expand Up @@ -418,12 +433,17 @@ public List<ContextMenuResult> 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();
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,19 @@
<data name="wox_leave_shell_open" xml:space="preserve">
<value>Keep shell open</value>
</data>
<data name="wox_shell_command_execution" xml:space="preserve">
<value>Shell command execution</value>
</data>
<data name="run_command_in_command_prompt" xml:space="preserve">
<value>Run command in Command Prompt (cmd.exe)</value>
</data>
<data name="run_command_in_powershell" xml:space="preserve">
<value>Run command 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>
</data>
<data name="run_command_in_windows_terminal" xml:space="preserve">
<value>Run command in Windows Terminal (wt.exe)</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
14 changes: 14 additions & 0 deletions src/settings-ui/Settings.UI.Library/PluginAdditionalOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -16,5 +24,11 @@ public class PluginAdditionalOption
public string DisplayDescription { get; set; }

public bool Value { get; set; }

public List<string> ComboBoxOptions { get; set; }

public int Option { get; set; }

public int SelectionTypeValue { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -444,11 +444,21 @@
BorderThickness="0,0,0,0"
ContentAlignment="Left"
CornerRadius="0">
<controls:CheckBoxWithDescriptionControl
Margin="56,0,0,0"
Description="{x:Bind Path=DisplayDescription}"
Header="{x:Bind Path=DisplayLabel}"
IsChecked="{x:Bind Path=Value, Mode=TwoWay}" />
<StackPanel Orientation="Vertical">
<controls:CheckBoxWithDescriptionControl
Margin="56,0,0,0"
Description="{x:Bind Path=DisplayDescription}"
Header="{x:Bind Path=DisplayLabel}"
IsChecked="{x:Bind Path=Value, Mode=TwoWay}"
Visibility="{x:Bind Path=ShowCheckBox, Converter={StaticResource BoolToVisibilityConverter}}"/>
<ComboBox
Margin="56,0,0,0"
Description="{x:Bind Path=DisplayDescription}"
Header="{x:Bind Path=DisplayLabel}"
ItemsSource="{x:Bind Path=ComboBoxOptions}"
SelectedIndex="{x:Bind Path=Option, Mode=TwoWay}"
Visibility="{x:Bind Path=ShowComboBox, Converter={StaticResource BoolToVisibilityConverter}}" />
</StackPanel>
</labs:SettingsCard>
<Rectangle
Height="1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// 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;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using Microsoft.PowerToys.Settings.UI.Library;
Expand All @@ -17,9 +18,9 @@ internal PluginAdditionalOptionViewModel(PluginAdditionalOption additionalOption
_additionalOption = additionalOption;
}

public string DisplayLabel { get => _additionalOption.DisplayLabel; }
public string DisplayLabel => _additionalOption.DisplayLabel;

public string DisplayDescription { get => _additionalOption.DisplayDescription; }
public string DisplayDescription => _additionalOption.DisplayDescription;

public bool Value
{
Expand All @@ -34,6 +35,25 @@ public bool Value
}
}

public List<string> 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 = "")
Expand Down

0 comments on commit e856e05

Please sign in to comment.