add settings for number of most used cmds option

This commit is contained in:
Jeremy Wu 2021-04-12 19:06:44 +10:00
parent 04156d7f83
commit 67097864fa
4 changed files with 52 additions and 1 deletions

View file

@ -12,4 +12,5 @@
<system:String x:Key="flowlauncher_plugin_cmd_execute_through_shell">execute command through command shell</system:String>
<system:String x:Key="flowlauncher_plugin_cmd_run_as_administrator">Run As Administrator</system:String>
<system:String x:Key="flowlauncher_plugin_cmd_copy">Copy the command</system:String>
<system:String x:Key="flowlauncher_plugin_cmd_history">Only show number of most used commands:</system:String>
</ResourceDictionary>

View file

@ -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<string, int> CommandHistory { get; set; } = new Dictionary<string, int>();
public void AddCmdHistory(string cmdName)

View file

@ -12,6 +12,7 @@
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<CheckBox Grid.Row="0" x:Name="ReplaceWinR" Content="{DynamicResource flowlauncher_plugin_cmd_relace_winr}" Margin="10" HorizontalAlignment="Left"/>
<CheckBox Grid.Row="1" x:Name="LeaveShellOpen" Content="{DynamicResource flowlauncher_plugin_cmd_leave_cmd_open}" Margin="10" HorizontalAlignment="Left"/>
@ -21,5 +22,7 @@
<ComboBoxItem>PowerShell</ComboBoxItem>
<ComboBoxItem>RunCommand</ComboBoxItem>
</ComboBox>
<CheckBox Grid.Row ="4" x:Name="ShowOnlyMostUsedCMDs" Content="{DynamicResource flowlauncher_plugin_cmd_history}" Margin="10 10 0 0"/>
<ComboBox Grid.Row="4" x:Name="ShowOnlyMostUsedCMDsNumber" Margin="330 20 10 10" HorizontalAlignment="Left" />
</Grid>
</UserControl>

View file

@ -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<int>() { 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;
};
}
}
}