-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pt run - Shell selection #28121
Pt run - Shell selection #28121
Changes from 9 commits
d0f1268
9bec422
50dca83
5211135
1155b31
09cc544
f263c85
bf8cdba
11e9ea6
83c7911
8aae265
32ec073
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
using System.Reflection; | ||
using System.Windows.Input; | ||
using ManagedCommon; | ||
using Microsoft.Plugin.Folder.Sources; | ||
using Microsoft.Plugin.Shell.Properties; | ||
using Microsoft.PowerToys.Settings.UI.Library; | ||
using Wox.Infrastructure.Storage; | ||
|
@@ -47,6 +48,18 @@ 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, | ||
Option = (int)_settings.Shell, | ||
|
||
ComboBoxOptions = Enum.GetValues(typeof(ExecutionShell)) | ||
.Cast<ExecutionShell>() | ||
.Select(shellEnumValue => ShellPluginSettings.GetDescription(shellEnumValue)) | ||
.ToList(), | ||
}, | ||
}; | ||
|
||
private PluginInitContext _context; | ||
|
@@ -418,12 +431,17 @@ public List<ContextMenuResult> LoadContextMenus(Result selectedResult) | |
public void UpdateSettings(PowerLauncherPluginSettings settings) | ||
{ | ||
var leaveShellOpen = false; | ||
var shellOption = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What was the default before implementing this? I thought it was ShellExecute. We should keep the old default behavior as new default. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
|
||
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(); | ||
|
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 |
---|---|---|
|
@@ -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 | ||
{ | ||
|
@@ -31,13 +34,34 @@ public void AddCmdHistory(string cmdName) | |
Count.Add(cmdName, 1); | ||
} | ||
} | ||
|
||
public static string GetDescription(Enum value) | ||
{ | ||
FieldInfo fi = value.GetType().GetField(value.ToString()); | ||
|
||
DescriptionAttribute[] attributes = | ||
(DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false); | ||
|
||
if (attributes != null && attributes.Length > 0) | ||
{ | ||
return attributes[0].Description; | ||
} | ||
else | ||
{ | ||
return value.ToString(); | ||
} | ||
} | ||
} | ||
|
||
public enum ExecutionShell | ||
{ | ||
[Description("Run command in Command Prompt (cmd.exe)")] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are user-facing strings and have to be localized There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
Cmd = 0, | ||
[Description("Run command in PowerShell (PowerShell.exe)")] | ||
Powershell = 1, | ||
[Description("Find executable file and run it")] | ||
RunCommand = 2, | ||
[Description("Run command in Windows Terminal (wt.exe)")] | ||
WindowsTerminal = 3, | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please make sure that it is possible to go without description. Current it is optional. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Its optional. Not used |
||
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" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +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.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Runtime.CompilerServices; | ||
using System.Windows.Input; | ||
using Microsoft.PowerToys.Settings.UI.Library; | ||
|
||
namespace Microsoft.PowerToys.Settings.UI.ViewModels | ||
|
@@ -17,9 +19,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 | ||
{ | ||
|
@@ -34,6 +36,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.ComboBoxOptions != null && _additionalOption.ComboBoxOptions.Count > 0; | ||
|
||
public bool ShowCheckBox => ShowComboBox == false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we make this more flexible by supporting checkbox value ( This allows us to have three different settings combinations: DropDown, Checkbox, Checkbox&DropDown There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Value is bool and its non-nullable. So a new bool HideCheckBox added and used. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can't use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After thinking about this some time I am wondering if we it makes sense. 🤔 We have only one name and description and I think it's more common to have different names/descriptions for checkbox and drop-down. Maybe we should revert this change. What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree. We are saving data in JSON file. One combobox or checkbox only responsible for one field in that JSON file. Changes are reverted. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at this, I think it's not very flexible to adding new types in the future. Can we add a field that's a sort of enum for the type of option this is? Currently there's two option types we're using, a "BooleanCheckboxOption" type (which would be default, so we don't need to change current code and still support the third party plugins we currently do) and a "SelectionDropDownOption" type. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is the PR #25326 for adding a string type setting which I think we can close. I am waiting for this drop-down feature to merge before implementing the string setting. In the other PR I mentioned the exact same idea with the enum. And it would make single type (string, checkbox, drop-down, ...) settings easier to implement. (Currently I have the idea to check for So I don't know if it makes sense to add so complex setting definitions. I mean you still can use two different |
||
|
||
public event PropertyChangedEventHandler PropertyChanged; | ||
|
||
private void NotifyPropertyChanged([CallerMemberName] string propertyName = "") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be here. One plugin should not depend on another
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.