Skip to content

Commit c950a68

Browse files
committed
- Convert Garulf's Query Cycle feature
- Add Reset CycleIndex when close window
1 parent 106760c commit c950a68

File tree

4 files changed

+101
-1
lines changed

4 files changed

+101
-1
lines changed

Flow.Launcher.Infrastructure/UserSettings/Settings.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public class Settings : BaseModel, IHotkeySettings
3131
public string SelectPrevPageHotkey { get; set; } = $"PageDown";
3232
public string OpenContextMenuHotkey { get; set; } = $"Ctrl+O";
3333
public string SettingWindowHotkey { get; set; } = $"Ctrl+I";
34+
public string CycleHistoryUpHotkey { get; set; } = $"{KeyConstant.Alt} + Up";
35+
public string CycleHistoryDownHotkey { get; set; } = $"{KeyConstant.Alt} + Down";
3436

3537
public string Language
3638
{
@@ -340,6 +342,10 @@ public List<RegisteredHotkeyData> RegisteredHotkeys
340342
list.Add(new(SelectNextPageHotkey, "SelectNextPageHotkey", () => SelectNextPageHotkey = ""));
341343
if(!string.IsNullOrEmpty(SelectPrevPageHotkey))
342344
list.Add(new(SelectPrevPageHotkey, "SelectPrevPageHotkey", () => SelectPrevPageHotkey = ""));
345+
if (!string.IsNullOrEmpty(CycleHistoryUpHotkey))
346+
list.Add(new(CycleHistoryUpHotkey, "CycleHistoryUpHotkey", () => CycleHistoryUpHotkey = ""));
347+
if (!string.IsNullOrEmpty(CycleHistoryDownHotkey))
348+
list.Add(new(CycleHistoryDownHotkey, "CycleHistoryDownHotkey", () => CycleHistoryDownHotkey = ""));
343349

344350
foreach (var customPluginHotkey in CustomPluginHotkeys)
345351
{

Flow.Launcher/MainWindow.xaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,14 @@
197197
Key="{Binding SelectPrevPageHotkey, Converter={StaticResource StringToKeyBindingConverter}, ConverterParameter='key'}"
198198
Command="{Binding SelectPrevPageCommand}"
199199
Modifiers="{Binding SelectPrevPageHotkey, Converter={StaticResource StringToKeyBindingConverter}, ConverterParameter='modifiers'}" />
200+
<KeyBinding
201+
Key="{Binding CycleHistoryUpHotkey, Converter={StaticResource StringToKeyBindingConverter}, ConverterParameter='key'}"
202+
Command="{Binding ReverseHistoryCommand}"
203+
Modifiers="{Binding CycleHistoryUpHotkey, Converter={StaticResource StringToKeyBindingConverter}, ConverterParameter='modifiers'}" />
204+
<KeyBinding
205+
Key="{Binding CycleHistoryDownHotkey, Converter={StaticResource StringToKeyBindingConverter}, ConverterParameter='key'}"
206+
Command="{Binding ForwardHistoryCommand}"
207+
Modifiers="{Binding CycleHistoryDownHotkey, Converter={StaticResource StringToKeyBindingConverter}, ConverterParameter='modifiers'}" />
200208
</Window.InputBindings>
201209
<Grid>
202210
<Border MouseDown="OnMouseDown" Style="{DynamicResource WindowBorderStyle}">

Flow.Launcher/SettingWindow.xaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2810,6 +2810,26 @@
28102810
Type="Inside">
28112811
<cc:HotkeyDisplay Keys="Ctrl+R" />
28122812
</cc:Card>
2813+
<cc:Card
2814+
Title="Cycle History Up"
2815+
Icon="&#xf0ad;"
2816+
Type="Inside">
2817+
<flowlauncher:HotkeyControl
2818+
DefaultHotkey="Alt+Up"
2819+
Hotkey="{Binding Settings.CycleHistoryUpHotkey}"
2820+
HotkeySettings="{Binding Settings}"
2821+
ValidateKeyGesture="False" />
2822+
</cc:Card>
2823+
<cc:Card
2824+
Title="Cycle History Down"
2825+
Icon="&#xf0ad;"
2826+
Type="Inside">
2827+
<flowlauncher:HotkeyControl
2828+
DefaultHotkey="Alt+Down"
2829+
Hotkey="{Binding Settings.CycleHistoryDownHotkey}"
2830+
HotkeySettings="{Binding Settings}"
2831+
ValidateKeyGesture="False" />
2832+
</cc:Card>
28132833
<cc:Card
28142834
Title="{DynamicResource ReloadPluginHotkey}"
28152835
Icon="&#xe72c;"

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public partial class MainViewModel : BaseModel, ISavable
4242
private readonly FlowLauncherJsonStorage<UserSelectedRecord> _userSelectedRecordStorage;
4343
private readonly FlowLauncherJsonStorage<TopMostRecord> _topMostRecordStorage;
4444
private readonly History _history;
45+
private int lasthistoryindex = 1;
4546
private readonly UserSelectedRecord _userSelectedRecord;
4647
private readonly TopMostRecord _topMostRecord;
4748

@@ -83,6 +84,12 @@ public MainViewModel(Settings settings)
8384
case nameof(Settings.AutoCompleteHotkey):
8485
OnPropertyChanged(nameof(AutoCompleteHotkey));
8586
break;
87+
case nameof(Settings.CycleHistoryUpHotkey):
88+
OnPropertyChanged(nameof(CycleHistoryUpHotkey));
89+
break;
90+
case nameof(Settings.CycleHistoryDownHotkey):
91+
OnPropertyChanged(nameof(CycleHistoryDownHotkey));
92+
break;
8693
case nameof(Settings.AutoCompleteHotkey2):
8794
OnPropertyChanged(nameof(AutoCompleteHotkey2));
8895
break;
@@ -256,6 +263,49 @@ public void ReQuery(bool reselect)
256263
}
257264
}
258265

266+
[RelayCommand]
267+
public void ReverseHistory()
268+
{
269+
if (_history.Items.Count > 0)
270+
{
271+
ChangeQueryText(_history.Items[_history.Items.Count - lasthistoryindex].Query.ToString());
272+
if (lasthistoryindex < _history.Items.Count)
273+
{
274+
lasthistoryindex++;
275+
}
276+
}
277+
}
278+
279+
[RelayCommand]
280+
public void ForwardHistory()
281+
{
282+
if (_history.Items.Count > 0)
283+
{
284+
ChangeQueryText(_history.Items[_history.Items.Count - lasthistoryindex].Query.ToString());
285+
if (lasthistoryindex > 1)
286+
{
287+
lasthistoryindex--;
288+
}
289+
}
290+
}
291+
292+
[RelayCommand]
293+
public void ReverseHistoryOnEmptyQuery()
294+
{
295+
var results = SelectedResults;
296+
if (_history.Items.Count > 0
297+
&& _queryText == String.Empty
298+
&& !HistorySelected()
299+
&& !ContextMenuSelected())
300+
{
301+
ReverseHistory();
302+
}
303+
else
304+
{
305+
SelectedResults.SelectPrevResult();
306+
}
307+
}
308+
259309
[RelayCommand]
260310
private void LoadContextMenu()
261311
{
@@ -394,7 +444,20 @@ private void SelectNextPage()
394444
[RelayCommand]
395445
private void SelectPrevItem()
396446
{
397-
SelectedResults.SelectPrevResult();
447+
var results = SelectedResults;
448+
if (_history.Items.Count > 0
449+
&& _queryText == String.Empty
450+
&& !HistorySelected()
451+
&& !ContextMenuSelected())
452+
{
453+
lasthistoryindex = 1;
454+
ReverseHistory();
455+
}
456+
else
457+
{
458+
SelectedResults.SelectPrevResult();
459+
}
460+
398461
}
399462

400463
[RelayCommand]
@@ -690,6 +753,8 @@ public string VerifyOrSetDefaultHotkey(string hotkey, string defaultHotkey)
690753
public string SelectPrevPageHotkey => VerifyOrSetDefaultHotkey(Settings.SelectPrevPageHotkey, "");
691754
public string OpenContextMenuHotkey => VerifyOrSetDefaultHotkey(Settings.OpenContextMenuHotkey, "Ctrl+O");
692755
public string SettingWindowHotkey => VerifyOrSetDefaultHotkey(Settings.SettingWindowHotkey, "Ctrl+I");
756+
public string CycleHistoryUpHotkey => VerifyOrSetDefaultHotkey(Settings.CycleHistoryUpHotkey, "Alt+Up");
757+
public string CycleHistoryDownHotkey => VerifyOrSetDefaultHotkey(Settings.CycleHistoryDownHotkey, "Alt+Down");
693758

694759

695760
public string Image => Constant.QueryTextBoxIconImagePath;
@@ -1116,6 +1181,7 @@ public void Show()
11161181

11171182
public async void Hide()
11181183
{
1184+
lasthistoryindex = 1;
11191185
// Trick for no delay
11201186
MainWindowOpacity = 0;
11211187
lastContextMenuResult = new Result();

0 commit comments

Comments
 (0)