Skip to content

Commit 177f8fe

Browse files
authored
Merge pull request #2696 from onesounds/240516GarulfQueryCycle
Ported "Up Arrow key cycles through Query history" PR
2 parents 1bbe030 + 8632d1d commit 177f8fe

File tree

5 files changed

+127
-36
lines changed

5 files changed

+127
-36
lines changed

Flow.Launcher.Infrastructure/UserSettings/Settings.cs

Lines changed: 48 additions & 35 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
{
@@ -280,42 +282,9 @@ public List<RegisteredHotkeyData> RegisteredHotkeys
280282
{
281283
get
282284
{
283-
var list = new List<RegisteredHotkeyData>
284-
{
285-
new("Up", "HotkeyLeftRightDesc"),
286-
new("Down", "HotkeyLeftRightDesc"),
287-
new("Left", "HotkeyUpDownDesc"),
288-
new("Right", "HotkeyUpDownDesc"),
289-
new("Escape", "HotkeyESCDesc"),
290-
new("F5", "ReloadPluginHotkey"),
291-
new("Alt+Home", "HotkeySelectFirstResult"),
292-
new("Alt+End", "HotkeySelectLastResult"),
293-
new("Ctrl+R", "HotkeyRequery"),
294-
new("Ctrl+H", "ToggleHistoryHotkey"),
295-
new("Ctrl+OemCloseBrackets", "QuickWidthHotkey"),
296-
new("Ctrl+OemOpenBrackets", "QuickWidthHotkey"),
297-
new("Ctrl+OemPlus", "QuickHeightHotkey"),
298-
new("Ctrl+OemMinus", "QuickHeightHotkey"),
299-
new("Ctrl+Shift+Enter", "HotkeyCtrlShiftEnterDesc"),
300-
new("Shift+Enter", "OpenContextMenuHotkey"),
301-
new("Enter", "HotkeyRunDesc"),
302-
new("Ctrl+Enter", "OpenContainFolderHotkey"),
303-
new("Alt+Enter", "HotkeyOpenResult"),
304-
new("Ctrl+F12", "ToggleGameModeHotkey"),
305-
new("Ctrl+Shift+C", "CopyFilePathHotkey"),
306-
307-
new($"{OpenResultModifiers}+D1", "HotkeyOpenResultN", 1),
308-
new($"{OpenResultModifiers}+D2", "HotkeyOpenResultN", 2),
309-
new($"{OpenResultModifiers}+D3", "HotkeyOpenResultN", 3),
310-
new($"{OpenResultModifiers}+D4", "HotkeyOpenResultN", 4),
311-
new($"{OpenResultModifiers}+D5", "HotkeyOpenResultN", 5),
312-
new($"{OpenResultModifiers}+D6", "HotkeyOpenResultN", 6),
313-
new($"{OpenResultModifiers}+D7", "HotkeyOpenResultN", 7),
314-
new($"{OpenResultModifiers}+D8", "HotkeyOpenResultN", 8),
315-
new($"{OpenResultModifiers}+D9", "HotkeyOpenResultN", 9),
316-
new($"{OpenResultModifiers}+D0", "HotkeyOpenResultN", 10)
317-
};
285+
var list = FixedHotkeys();
318286

287+
// Customizeable hotkeys
319288
if(!string.IsNullOrEmpty(Hotkey))
320289
list.Add(new(Hotkey, "flowlauncherHotkey", () => Hotkey = ""));
321290
if(!string.IsNullOrEmpty(PreviewHotkey))
@@ -340,7 +309,12 @@ public List<RegisteredHotkeyData> RegisteredHotkeys
340309
list.Add(new(SelectNextPageHotkey, "SelectNextPageHotkey", () => SelectNextPageHotkey = ""));
341310
if(!string.IsNullOrEmpty(SelectPrevPageHotkey))
342311
list.Add(new(SelectPrevPageHotkey, "SelectPrevPageHotkey", () => SelectPrevPageHotkey = ""));
312+
if (!string.IsNullOrEmpty(CycleHistoryUpHotkey))
313+
list.Add(new(CycleHistoryUpHotkey, "CycleHistoryUpHotkey", () => CycleHistoryUpHotkey = ""));
314+
if (!string.IsNullOrEmpty(CycleHistoryDownHotkey))
315+
list.Add(new(CycleHistoryDownHotkey, "CycleHistoryDownHotkey", () => CycleHistoryDownHotkey = ""));
343316

317+
// Custom Query Hotkeys
344318
foreach (var customPluginHotkey in CustomPluginHotkeys)
345319
{
346320
if (!string.IsNullOrEmpty(customPluginHotkey.Hotkey))
@@ -350,6 +324,45 @@ public List<RegisteredHotkeyData> RegisteredHotkeys
350324
return list;
351325
}
352326
}
327+
328+
private List<RegisteredHotkeyData> FixedHotkeys()
329+
{
330+
return new List<RegisteredHotkeyData>
331+
{
332+
new("Up", "HotkeyLeftRightDesc"),
333+
new("Down", "HotkeyLeftRightDesc"),
334+
new("Left", "HotkeyUpDownDesc"),
335+
new("Right", "HotkeyUpDownDesc"),
336+
new("Escape", "HotkeyESCDesc"),
337+
new("F5", "ReloadPluginHotkey"),
338+
new("Alt+Home", "HotkeySelectFirstResult"),
339+
new("Alt+End", "HotkeySelectLastResult"),
340+
new("Ctrl+R", "HotkeyRequery"),
341+
new("Ctrl+H", "ToggleHistoryHotkey"),
342+
new("Ctrl+OemCloseBrackets", "QuickWidthHotkey"),
343+
new("Ctrl+OemOpenBrackets", "QuickWidthHotkey"),
344+
new("Ctrl+OemPlus", "QuickHeightHotkey"),
345+
new("Ctrl+OemMinus", "QuickHeightHotkey"),
346+
new("Ctrl+Shift+Enter", "HotkeyCtrlShiftEnterDesc"),
347+
new("Shift+Enter", "OpenContextMenuHotkey"),
348+
new("Enter", "HotkeyRunDesc"),
349+
new("Ctrl+Enter", "OpenContainFolderHotkey"),
350+
new("Alt+Enter", "HotkeyOpenResult"),
351+
new("Ctrl+F12", "ToggleGameModeHotkey"),
352+
new("Ctrl+Shift+C", "CopyFilePathHotkey"),
353+
354+
new($"{OpenResultModifiers}+D1", "HotkeyOpenResultN", 1),
355+
new($"{OpenResultModifiers}+D2", "HotkeyOpenResultN", 2),
356+
new($"{OpenResultModifiers}+D3", "HotkeyOpenResultN", 3),
357+
new($"{OpenResultModifiers}+D4", "HotkeyOpenResultN", 4),
358+
new($"{OpenResultModifiers}+D5", "HotkeyOpenResultN", 5),
359+
new($"{OpenResultModifiers}+D6", "HotkeyOpenResultN", 6),
360+
new($"{OpenResultModifiers}+D7", "HotkeyOpenResultN", 7),
361+
new($"{OpenResultModifiers}+D8", "HotkeyOpenResultN", 8),
362+
new($"{OpenResultModifiers}+D9", "HotkeyOpenResultN", 9),
363+
new($"{OpenResultModifiers}+D0", "HotkeyOpenResultN", 10)
364+
};
365+
}
353366
}
354367

355368
public enum LastQueryMode

Flow.Launcher/Languages/en.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@
188188
<system:String x:Key="SelectPrevItemHotkey">Select Previous Item</system:String>
189189
<system:String x:Key="SelectNextPageHotkey">Next Page</system:String>
190190
<system:String x:Key="SelectPrevPageHotkey">Previous Page</system:String>
191+
<system:String x:Key="CycleHistoryUpHotkey">Cycle Previous Query</system:String>
192+
<system:String x:Key="CycleHistoryDownHotkey">Cycle Next Query</system:String>
191193
<system:String x:Key="OpenContextMenuHotkey">Open Context Menu</system:String>
192194
<system:String x:Key="SettingWindowHotkey">Open Setting Window</system:String>
193195
<system:String x:Key="CopyFilePathHotkey">Copy File Path</system:String>

Flow.Launcher/MainWindow.xaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,14 @@
198198
Key="{Binding SelectPrevPageHotkey, Converter={StaticResource StringToKeyBindingConverter}, ConverterParameter='key'}"
199199
Command="{Binding SelectPrevPageCommand}"
200200
Modifiers="{Binding SelectPrevPageHotkey, Converter={StaticResource StringToKeyBindingConverter}, ConverterParameter='modifiers'}" />
201+
<KeyBinding
202+
Key="{Binding CycleHistoryUpHotkey, Converter={StaticResource StringToKeyBindingConverter}, ConverterParameter='key'}"
203+
Command="{Binding ReverseHistoryCommand}"
204+
Modifiers="{Binding CycleHistoryUpHotkey, Converter={StaticResource StringToKeyBindingConverter}, ConverterParameter='modifiers'}" />
205+
<KeyBinding
206+
Key="{Binding CycleHistoryDownHotkey, Converter={StaticResource StringToKeyBindingConverter}, ConverterParameter='key'}"
207+
Command="{Binding ForwardHistoryCommand}"
208+
Modifiers="{Binding CycleHistoryDownHotkey, Converter={StaticResource StringToKeyBindingConverter}, ConverterParameter='modifiers'}" />
201209
</Window.InputBindings>
202210
<Grid>
203211
<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="{DynamicResource CycleHistoryUpHotkey}"
2815+
Icon="&#xe70e;"
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="{DynamicResource CycleHistoryDownHotkey}"
2825+
Icon="&#xe70d;"
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: 49 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,32 @@ 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+
259292
[RelayCommand]
260293
private void LoadContextMenu()
261294
{
@@ -346,6 +379,7 @@ private async Task OpenResultAsync(string index)
346379
{
347380
_userSelectedRecord.Add(result);
348381
_history.Add(result.OriginQuery.RawQuery);
382+
lastHistoryIndex = 1;
349383
}
350384

351385
if (hideWindow)
@@ -394,7 +428,18 @@ private void SelectNextPage()
394428
[RelayCommand]
395429
private void SelectPrevItem()
396430
{
397-
SelectedResults.SelectPrevResult();
431+
if (_history.Items.Count > 0
432+
&& QueryText == string.Empty
433+
&& SelectedIsFromQueryResults())
434+
{
435+
lastHistoryIndex = 1;
436+
ReverseHistory();
437+
}
438+
else
439+
{
440+
SelectedResults.SelectPrevResult();
441+
}
442+
398443
}
399444

400445
[RelayCommand]
@@ -690,6 +735,8 @@ public string VerifyOrSetDefaultHotkey(string hotkey, string defaultHotkey)
690735
public string SelectPrevPageHotkey => VerifyOrSetDefaultHotkey(Settings.SelectPrevPageHotkey, "");
691736
public string OpenContextMenuHotkey => VerifyOrSetDefaultHotkey(Settings.OpenContextMenuHotkey, "Ctrl+O");
692737
public string SettingWindowHotkey => VerifyOrSetDefaultHotkey(Settings.SettingWindowHotkey, "Ctrl+I");
738+
public string CycleHistoryUpHotkey => VerifyOrSetDefaultHotkey(Settings.CycleHistoryUpHotkey, "Alt+Up");
739+
public string CycleHistoryDownHotkey => VerifyOrSetDefaultHotkey(Settings.CycleHistoryDownHotkey, "Alt+Down");
693740

694741

695742
public string Image => Constant.QueryTextBoxIconImagePath;
@@ -1116,6 +1163,7 @@ public void Show()
11161163

11171164
public async void Hide()
11181165
{
1166+
lastHistoryIndex = 1;
11191167
// Trick for no delay
11201168
MainWindowOpacity = 0;
11211169
lastContextMenuResult = new Result();

0 commit comments

Comments
 (0)