From 67097864faafb98ad9f621eca013799e6b2ac0b0 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Mon, 12 Apr 2021 19:06:44 +1000 Subject: [PATCH] add settings for number of most used cmds option --- .../Languages/en.xaml | 1 + .../Flow.Launcher.Plugin.Shell/Settings.cs | 7 ++++ .../ShellSetting.xaml | 3 ++ .../ShellSetting.xaml.cs | 42 ++++++++++++++++++- 4 files changed, 52 insertions(+), 1 deletion(-) diff --git a/Plugins/Flow.Launcher.Plugin.Shell/Languages/en.xaml b/Plugins/Flow.Launcher.Plugin.Shell/Languages/en.xaml index 8665e17bb..8b312bc93 100644 --- a/Plugins/Flow.Launcher.Plugin.Shell/Languages/en.xaml +++ b/Plugins/Flow.Launcher.Plugin.Shell/Languages/en.xaml @@ -12,4 +12,5 @@ execute command through command shell Run As Administrator Copy the command + Only show number of most used commands: \ No newline at end of file diff --git a/Plugins/Flow.Launcher.Plugin.Shell/Settings.cs b/Plugins/Flow.Launcher.Plugin.Shell/Settings.cs index 58ac41fc3..042fd0dd3 100644 --- a/Plugins/Flow.Launcher.Plugin.Shell/Settings.cs +++ b/Plugins/Flow.Launcher.Plugin.Shell/Settings.cs @@ -5,10 +5,17 @@ namespace Flow.Launcher.Plugin.Shell public class Settings { public Shell Shell { get; set; } = Shell.Cmd; + public bool ReplaceWinR { get; set; } = true; + public bool LeaveShellOpen { get; set; } + public bool RunAsAdministrator { get; set; } = true; + public bool ShowOnlyMostUsedCMDs { get; set; } + + public int ShowOnlyMostUsedCMDsNumber { get; set; } + public Dictionary CommandHistory { get; set; } = new Dictionary(); public void AddCmdHistory(string cmdName) diff --git a/Plugins/Flow.Launcher.Plugin.Shell/ShellSetting.xaml b/Plugins/Flow.Launcher.Plugin.Shell/ShellSetting.xaml index e27297e05..4cd4d8fa3 100644 --- a/Plugins/Flow.Launcher.Plugin.Shell/ShellSetting.xaml +++ b/Plugins/Flow.Launcher.Plugin.Shell/ShellSetting.xaml @@ -12,6 +12,7 @@ + @@ -21,5 +22,7 @@ PowerShell RunCommand + + diff --git a/Plugins/Flow.Launcher.Plugin.Shell/ShellSetting.xaml.cs b/Plugins/Flow.Launcher.Plugin.Shell/ShellSetting.xaml.cs index 82260fcad..749e9ec80 100644 --- a/Plugins/Flow.Launcher.Plugin.Shell/ShellSetting.xaml.cs +++ b/Plugins/Flow.Launcher.Plugin.Shell/ShellSetting.xaml.cs @@ -1,4 +1,5 @@ -using System.Windows; +using System.Collections.Generic; +using System.Windows; using System.Windows.Controls; namespace Flow.Launcher.Plugin.Shell @@ -16,9 +17,26 @@ namespace Flow.Launcher.Plugin.Shell private void CMDSetting_OnLoaded(object sender, RoutedEventArgs re) { ReplaceWinR.IsChecked = _settings.ReplaceWinR; + LeaveShellOpen.IsChecked = _settings.LeaveShellOpen; + AlwaysRunAsAdministrator.IsChecked = _settings.RunAsAdministrator; + LeaveShellOpen.IsEnabled = _settings.Shell != Shell.RunCommand; + + ShowOnlyMostUsedCMDs.IsChecked = _settings.ShowOnlyMostUsedCMDs; + + if ((bool)!ShowOnlyMostUsedCMDs.IsChecked) + ShowOnlyMostUsedCMDsNumber.IsEnabled = false; + + ShowOnlyMostUsedCMDsNumber.ItemsSource = new List() { 5, 10, 20 }; + + if (_settings.ShowOnlyMostUsedCMDsNumber == 0) + { + ShowOnlyMostUsedCMDsNumber.SelectedIndex = 0; + + _settings.ShowOnlyMostUsedCMDsNumber = (int)ShowOnlyMostUsedCMDsNumber.SelectedItem; + } LeaveShellOpen.Checked += (o, e) => { @@ -44,6 +62,7 @@ namespace Flow.Launcher.Plugin.Shell { _settings.ReplaceWinR = true; }; + ReplaceWinR.Unchecked += (o, e) => { _settings.ReplaceWinR = false; @@ -55,6 +74,27 @@ namespace Flow.Launcher.Plugin.Shell _settings.Shell = (Shell) ShellComboBox.SelectedIndex; LeaveShellOpen.IsEnabled = _settings.Shell != Shell.RunCommand; }; + + ShowOnlyMostUsedCMDs.Checked += (o, e) => + { + _settings.ShowOnlyMostUsedCMDs = true; + + ShowOnlyMostUsedCMDsNumber.IsEnabled = true; + }; + + ShowOnlyMostUsedCMDs.Unchecked += (o, e) => + { + _settings.ShowOnlyMostUsedCMDs = false; + + ShowOnlyMostUsedCMDsNumber.IsEnabled = false; + }; + + ShowOnlyMostUsedCMDsNumber.SelectedItem = _settings.ShowOnlyMostUsedCMDsNumber; + ShowOnlyMostUsedCMDsNumber.SelectionChanged += (o, e) => + { + _settings.ShowOnlyMostUsedCMDsNumber = (int)ShowOnlyMostUsedCMDsNumber.SelectedItem; + }; + } } }