Skip to content

Commit 256bfb7

Browse files
authored
Merge pull request #404 from Flow-Launcher/save_shell_cmd_history
save Shell plugin cmd history
2 parents 3110c87 + 5791cd4 commit 256bfb7

File tree

8 files changed

+71
-11
lines changed

8 files changed

+71
-11
lines changed

Flow.Launcher/Languages/en.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<system:String x:Key="hideNotifyIcon">Hide tray icon</system:String>
3737
<system:String x:Key="querySearchPrecision">Query Search Precision</system:String>
3838
<system:String x:Key="ShouldUsePinyin">Should Use Pinyin</system:String>
39+
<system:String x:Key="ShouldUsePinyinToolTip">Allows using Pinyin to search. Pinyin is the standard system of romanized spelling for transliterating Chinese</system:String>
3940

4041
<!--Setting Plugin-->
4142
<system:String x:Key="plugin">Plugin</system:String>

Flow.Launcher/SettingWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
<ui:ToggleSwitch Margin="10" IsOn="{Binding AutoUpdates}">
6464
<TextBlock Text="{DynamicResource autoUpdates}" />
6565
</ui:ToggleSwitch>
66-
<CheckBox Margin="10" IsChecked="{Binding ShouldUsePinyin}">
66+
<CheckBox Margin="10" IsChecked="{Binding ShouldUsePinyin}" ToolTip="{DynamicResource ShouldUsePinyinToolTip}">
6767
<TextBlock Text="{DynamicResource ShouldUsePinyin}" />
6868
</CheckBox>
6969
<StackPanel Margin="10" Orientation="Horizontal">

Plugins/Flow.Launcher.Plugin.Shell/Languages/en.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@
1212
<system:String x:Key="flowlauncher_plugin_cmd_execute_through_shell">execute command through command shell</system:String>
1313
<system:String x:Key="flowlauncher_plugin_cmd_run_as_administrator">Run As Administrator</system:String>
1414
<system:String x:Key="flowlauncher_plugin_cmd_copy">Copy the command</system:String>
15+
<system:String x:Key="flowlauncher_plugin_cmd_history">Only show number of most used commands:</system:String>
1516
</ResourceDictionary>

Plugins/Flow.Launcher.Plugin.Shell/Main.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public List<Result> Query(Query query)
102102

103103
private List<Result> GetHistoryCmds(string cmd, Result result)
104104
{
105-
IEnumerable<Result> history = _settings.Count.Where(o => o.Key.Contains(cmd))
105+
IEnumerable<Result> history = _settings.CommandHistory.Where(o => o.Key.Contains(cmd))
106106
.OrderByDescending(o => o.Value)
107107
.Select(m =>
108108
{
@@ -124,7 +124,11 @@ private List<Result> GetHistoryCmds(string cmd, Result result)
124124
}
125125
};
126126
return ret;
127-
}).Where(o => o != null).Take(4);
127+
}).Where(o => o != null);
128+
129+
if (_settings.ShowOnlyMostUsedCMDs)
130+
return history.Take(_settings.ShowOnlyMostUsedCMDsNumber).ToList();
131+
128132
return history.ToList();
129133
}
130134

@@ -148,7 +152,7 @@ private Result GetCurrentCmd(string cmd)
148152

149153
private List<Result> ResultsFromlHistory()
150154
{
151-
IEnumerable<Result> history = _settings.Count.OrderByDescending(o => o.Value)
155+
IEnumerable<Result> history = _settings.CommandHistory.OrderByDescending(o => o.Value)
152156
.Select(m => new Result
153157
{
154158
Title = m.Key,
@@ -159,7 +163,11 @@ private List<Result> ResultsFromlHistory()
159163
Execute(Process.Start, PrepareProcessStartInfo(m.Key));
160164
return true;
161165
}
162-
}).Take(5);
166+
});
167+
168+
if (_settings.ShowOnlyMostUsedCMDs)
169+
return history.Take(_settings.ShowOnlyMostUsedCMDsNumber).ToList();
170+
163171
return history.ToList();
164172
}
165173

Plugins/Flow.Launcher.Plugin.Shell/Settings.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,28 @@ namespace Flow.Launcher.Plugin.Shell
55
public class Settings
66
{
77
public Shell Shell { get; set; } = Shell.Cmd;
8+
89
public bool ReplaceWinR { get; set; } = true;
10+
911
public bool LeaveShellOpen { get; set; }
12+
1013
public bool RunAsAdministrator { get; set; } = true;
1114

12-
public Dictionary<string, int> Count = new Dictionary<string, int>();
15+
public bool ShowOnlyMostUsedCMDs { get; set; }
16+
17+
public int ShowOnlyMostUsedCMDsNumber { get; set; }
18+
19+
public Dictionary<string, int> CommandHistory { get; set; } = new Dictionary<string, int>();
1320

1421
public void AddCmdHistory(string cmdName)
1522
{
16-
if (Count.ContainsKey(cmdName))
23+
if (CommandHistory.ContainsKey(cmdName))
1724
{
18-
Count[cmdName] += 1;
25+
CommandHistory[cmdName] += 1;
1926
}
2027
else
2128
{
22-
Count.Add(cmdName, 1);
29+
CommandHistory.Add(cmdName, 1);
2330
}
2431
}
2532
}

Plugins/Flow.Launcher.Plugin.Shell/ShellSetting.xaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<RowDefinition/>
1313
<RowDefinition/>
1414
<RowDefinition/>
15+
<RowDefinition/>
1516
</Grid.RowDefinitions>
1617
<CheckBox Grid.Row="0" x:Name="ReplaceWinR" Content="{DynamicResource flowlauncher_plugin_cmd_relace_winr}" Margin="10" HorizontalAlignment="Left"/>
1718
<CheckBox Grid.Row="1" x:Name="LeaveShellOpen" Content="{DynamicResource flowlauncher_plugin_cmd_leave_cmd_open}" Margin="10" HorizontalAlignment="Left"/>
@@ -21,5 +22,7 @@
2122
<ComboBoxItem>PowerShell</ComboBoxItem>
2223
<ComboBoxItem>RunCommand</ComboBoxItem>
2324
</ComboBox>
25+
<CheckBox Grid.Row ="4" x:Name="ShowOnlyMostUsedCMDs" Content="{DynamicResource flowlauncher_plugin_cmd_history}" Margin="10 10 0 0"/>
26+
<ComboBox Grid.Row="4" x:Name="ShowOnlyMostUsedCMDsNumber" Margin="330 20 10 10" HorizontalAlignment="Left" />
2427
</Grid>
2528
</UserControl>

Plugins/Flow.Launcher.Plugin.Shell/ShellSetting.xaml.cs

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Windows;
1+
using System.Collections.Generic;
2+
using System.Windows;
23
using System.Windows.Controls;
34

45
namespace Flow.Launcher.Plugin.Shell
@@ -16,9 +17,26 @@ public CMDSetting(Settings settings)
1617
private void CMDSetting_OnLoaded(object sender, RoutedEventArgs re)
1718
{
1819
ReplaceWinR.IsChecked = _settings.ReplaceWinR;
20+
1921
LeaveShellOpen.IsChecked = _settings.LeaveShellOpen;
22+
2023
AlwaysRunAsAdministrator.IsChecked = _settings.RunAsAdministrator;
24+
2125
LeaveShellOpen.IsEnabled = _settings.Shell != Shell.RunCommand;
26+
27+
ShowOnlyMostUsedCMDs.IsChecked = _settings.ShowOnlyMostUsedCMDs;
28+
29+
if ((bool)!ShowOnlyMostUsedCMDs.IsChecked)
30+
ShowOnlyMostUsedCMDsNumber.IsEnabled = false;
31+
32+
ShowOnlyMostUsedCMDsNumber.ItemsSource = new List<int>() { 5, 10, 20 };
33+
34+
if (_settings.ShowOnlyMostUsedCMDsNumber == 0)
35+
{
36+
ShowOnlyMostUsedCMDsNumber.SelectedIndex = 0;
37+
38+
_settings.ShowOnlyMostUsedCMDsNumber = (int)ShowOnlyMostUsedCMDsNumber.SelectedItem;
39+
}
2240

2341
LeaveShellOpen.Checked += (o, e) =>
2442
{
@@ -44,6 +62,7 @@ private void CMDSetting_OnLoaded(object sender, RoutedEventArgs re)
4462
{
4563
_settings.ReplaceWinR = true;
4664
};
65+
4766
ReplaceWinR.Unchecked += (o, e) =>
4867
{
4968
_settings.ReplaceWinR = false;
@@ -55,6 +74,27 @@ private void CMDSetting_OnLoaded(object sender, RoutedEventArgs re)
5574
_settings.Shell = (Shell) ShellComboBox.SelectedIndex;
5675
LeaveShellOpen.IsEnabled = _settings.Shell != Shell.RunCommand;
5776
};
77+
78+
ShowOnlyMostUsedCMDs.Checked += (o, e) =>
79+
{
80+
_settings.ShowOnlyMostUsedCMDs = true;
81+
82+
ShowOnlyMostUsedCMDsNumber.IsEnabled = true;
83+
};
84+
85+
ShowOnlyMostUsedCMDs.Unchecked += (o, e) =>
86+
{
87+
_settings.ShowOnlyMostUsedCMDs = false;
88+
89+
ShowOnlyMostUsedCMDsNumber.IsEnabled = false;
90+
};
91+
92+
ShowOnlyMostUsedCMDsNumber.SelectedItem = _settings.ShowOnlyMostUsedCMDsNumber;
93+
ShowOnlyMostUsedCMDsNumber.SelectionChanged += (o, e) =>
94+
{
95+
_settings.ShowOnlyMostUsedCMDsNumber = (int)ShowOnlyMostUsedCMDsNumber.SelectedItem;
96+
};
97+
5898
}
5999
}
60100
}

Plugins/Flow.Launcher.Plugin.Shell/plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"Name": "Shell",
55
"Description": "Provide executing commands from Flow Launcher",
66
"Author": "qianlifeng",
7-
"Version": "1.2.0",
7+
"Version": "1.3.0",
88
"Language": "csharp",
99
"Website": "https://github.com/Flow-Launcher/Flow.Launcher",
1010
"ExecuteFileName": "Flow.Launcher.Plugin.Shell.dll",

0 commit comments

Comments
 (0)