mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Merge pull request #404 from Flow-Launcher/save_shell_cmd_history
save Shell plugin cmd history
This commit is contained in:
commit
256bfb7237
8 changed files with 71 additions and 11 deletions
|
|
@ -36,6 +36,7 @@
|
|||
<system:String x:Key="hideNotifyIcon">Hide tray icon</system:String>
|
||||
<system:String x:Key="querySearchPrecision">Query Search Precision</system:String>
|
||||
<system:String x:Key="ShouldUsePinyin">Should Use Pinyin</system:String>
|
||||
<system:String x:Key="ShouldUsePinyinToolTip">Allows using Pinyin to search. Pinyin is the standard system of romanized spelling for transliterating Chinese</system:String>
|
||||
|
||||
<!--Setting Plugin-->
|
||||
<system:String x:Key="plugin">Plugin</system:String>
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@
|
|||
<ui:ToggleSwitch Margin="10" IsOn="{Binding AutoUpdates}">
|
||||
<TextBlock Text="{DynamicResource autoUpdates}" />
|
||||
</ui:ToggleSwitch>
|
||||
<CheckBox Margin="10" IsChecked="{Binding ShouldUsePinyin}">
|
||||
<CheckBox Margin="10" IsChecked="{Binding ShouldUsePinyin}" ToolTip="{DynamicResource ShouldUsePinyinToolTip}">
|
||||
<TextBlock Text="{DynamicResource ShouldUsePinyin}" />
|
||||
</CheckBox>
|
||||
<StackPanel Margin="10" Orientation="Horizontal">
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
@ -102,7 +102,7 @@ namespace Flow.Launcher.Plugin.Shell
|
|||
|
||||
private List<Result> GetHistoryCmds(string cmd, Result result)
|
||||
{
|
||||
IEnumerable<Result> history = _settings.Count.Where(o => o.Key.Contains(cmd))
|
||||
IEnumerable<Result> history = _settings.CommandHistory.Where(o => o.Key.Contains(cmd))
|
||||
.OrderByDescending(o => o.Value)
|
||||
.Select(m =>
|
||||
{
|
||||
|
|
@ -124,7 +124,11 @@ namespace Flow.Launcher.Plugin.Shell
|
|||
}
|
||||
};
|
||||
return ret;
|
||||
}).Where(o => o != null).Take(4);
|
||||
}).Where(o => o != null);
|
||||
|
||||
if (_settings.ShowOnlyMostUsedCMDs)
|
||||
return history.Take(_settings.ShowOnlyMostUsedCMDsNumber).ToList();
|
||||
|
||||
return history.ToList();
|
||||
}
|
||||
|
||||
|
|
@ -148,7 +152,7 @@ namespace Flow.Launcher.Plugin.Shell
|
|||
|
||||
private List<Result> ResultsFromlHistory()
|
||||
{
|
||||
IEnumerable<Result> history = _settings.Count.OrderByDescending(o => o.Value)
|
||||
IEnumerable<Result> history = _settings.CommandHistory.OrderByDescending(o => o.Value)
|
||||
.Select(m => new Result
|
||||
{
|
||||
Title = m.Key,
|
||||
|
|
@ -159,7 +163,11 @@ namespace Flow.Launcher.Plugin.Shell
|
|||
Execute(Process.Start, PrepareProcessStartInfo(m.Key));
|
||||
return true;
|
||||
}
|
||||
}).Take(5);
|
||||
});
|
||||
|
||||
if (_settings.ShowOnlyMostUsedCMDs)
|
||||
return history.Take(_settings.ShowOnlyMostUsedCMDsNumber).ToList();
|
||||
|
||||
return history.ToList();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,21 +5,28 @@ 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 Dictionary<string, int> Count = new Dictionary<string, int>();
|
||||
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)
|
||||
{
|
||||
if (Count.ContainsKey(cmdName))
|
||||
if (CommandHistory.ContainsKey(cmdName))
|
||||
{
|
||||
Count[cmdName] += 1;
|
||||
CommandHistory[cmdName] += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
Count.Add(cmdName, 1);
|
||||
CommandHistory.Add(cmdName, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
"Name": "Shell",
|
||||
"Description": "Provide executing commands from Flow Launcher",
|
||||
"Author": "qianlifeng",
|
||||
"Version": "1.2.0",
|
||||
"Version": "1.3.0",
|
||||
"Language": "csharp",
|
||||
"Website": "https://github.com/Flow-Launcher/Flow.Launcher",
|
||||
"ExecuteFileName": "Flow.Launcher.Plugin.Shell.dll",
|
||||
|
|
|
|||
Loading…
Reference in a new issue