From c950a689d5b29c92f51743c03ff27d4d5fab156c Mon Sep 17 00:00:00 2001 From: DB p Date: Thu, 16 May 2024 01:11:27 +0900 Subject: [PATCH 1/7] - Convert Garulf's Query Cycle feature - Add Reset CycleIndex when close window --- .../UserSettings/Settings.cs | 6 ++ Flow.Launcher/MainWindow.xaml | 8 +++ Flow.Launcher/SettingWindow.xaml | 20 ++++++ Flow.Launcher/ViewModel/MainViewModel.cs | 68 ++++++++++++++++++- 4 files changed, 101 insertions(+), 1 deletion(-) diff --git a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs index 7bb8fe2009c..3d443349310 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs @@ -31,6 +31,8 @@ public class Settings : BaseModel, IHotkeySettings public string SelectPrevPageHotkey { get; set; } = $"PageDown"; public string OpenContextMenuHotkey { get; set; } = $"Ctrl+O"; public string SettingWindowHotkey { get; set; } = $"Ctrl+I"; + public string CycleHistoryUpHotkey { get; set; } = $"{KeyConstant.Alt} + Up"; + public string CycleHistoryDownHotkey { get; set; } = $"{KeyConstant.Alt} + Down"; public string Language { @@ -340,6 +342,10 @@ public List RegisteredHotkeys list.Add(new(SelectNextPageHotkey, "SelectNextPageHotkey", () => SelectNextPageHotkey = "")); if(!string.IsNullOrEmpty(SelectPrevPageHotkey)) list.Add(new(SelectPrevPageHotkey, "SelectPrevPageHotkey", () => SelectPrevPageHotkey = "")); + if (!string.IsNullOrEmpty(CycleHistoryUpHotkey)) + list.Add(new(CycleHistoryUpHotkey, "CycleHistoryUpHotkey", () => CycleHistoryUpHotkey = "")); + if (!string.IsNullOrEmpty(CycleHistoryDownHotkey)) + list.Add(new(CycleHistoryDownHotkey, "CycleHistoryDownHotkey", () => CycleHistoryDownHotkey = "")); foreach (var customPluginHotkey in CustomPluginHotkeys) { diff --git a/Flow.Launcher/MainWindow.xaml b/Flow.Launcher/MainWindow.xaml index 2e6e973a720..da5ec63bfdf 100644 --- a/Flow.Launcher/MainWindow.xaml +++ b/Flow.Launcher/MainWindow.xaml @@ -197,6 +197,14 @@ Key="{Binding SelectPrevPageHotkey, Converter={StaticResource StringToKeyBindingConverter}, ConverterParameter='key'}" Command="{Binding SelectPrevPageCommand}" Modifiers="{Binding SelectPrevPageHotkey, Converter={StaticResource StringToKeyBindingConverter}, ConverterParameter='modifiers'}" /> + + diff --git a/Flow.Launcher/SettingWindow.xaml b/Flow.Launcher/SettingWindow.xaml index 119268d6bd9..4a563bc450f 100644 --- a/Flow.Launcher/SettingWindow.xaml +++ b/Flow.Launcher/SettingWindow.xaml @@ -2810,6 +2810,26 @@ Type="Inside"> + + + + + + _userSelectedRecordStorage; private readonly FlowLauncherJsonStorage _topMostRecordStorage; private readonly History _history; + private int lasthistoryindex = 1; private readonly UserSelectedRecord _userSelectedRecord; private readonly TopMostRecord _topMostRecord; @@ -83,6 +84,12 @@ public MainViewModel(Settings settings) case nameof(Settings.AutoCompleteHotkey): OnPropertyChanged(nameof(AutoCompleteHotkey)); break; + case nameof(Settings.CycleHistoryUpHotkey): + OnPropertyChanged(nameof(CycleHistoryUpHotkey)); + break; + case nameof(Settings.CycleHistoryDownHotkey): + OnPropertyChanged(nameof(CycleHistoryDownHotkey)); + break; case nameof(Settings.AutoCompleteHotkey2): OnPropertyChanged(nameof(AutoCompleteHotkey2)); break; @@ -256,6 +263,49 @@ public void ReQuery(bool reselect) } } + [RelayCommand] + public void ReverseHistory() + { + if (_history.Items.Count > 0) + { + ChangeQueryText(_history.Items[_history.Items.Count - lasthistoryindex].Query.ToString()); + if (lasthistoryindex < _history.Items.Count) + { + lasthistoryindex++; + } + } + } + + [RelayCommand] + public void ForwardHistory() + { + if (_history.Items.Count > 0) + { + ChangeQueryText(_history.Items[_history.Items.Count - lasthistoryindex].Query.ToString()); + if (lasthistoryindex > 1) + { + lasthistoryindex--; + } + } + } + + [RelayCommand] + public void ReverseHistoryOnEmptyQuery() + { + var results = SelectedResults; + if (_history.Items.Count > 0 + && _queryText == String.Empty + && !HistorySelected() + && !ContextMenuSelected()) + { + ReverseHistory(); + } + else + { + SelectedResults.SelectPrevResult(); + } + } + [RelayCommand] private void LoadContextMenu() { @@ -394,7 +444,20 @@ private void SelectNextPage() [RelayCommand] private void SelectPrevItem() { - SelectedResults.SelectPrevResult(); + var results = SelectedResults; + if (_history.Items.Count > 0 + && _queryText == String.Empty + && !HistorySelected() + && !ContextMenuSelected()) + { + lasthistoryindex = 1; + ReverseHistory(); + } + else + { + SelectedResults.SelectPrevResult(); + } + } [RelayCommand] @@ -690,6 +753,8 @@ public string VerifyOrSetDefaultHotkey(string hotkey, string defaultHotkey) public string SelectPrevPageHotkey => VerifyOrSetDefaultHotkey(Settings.SelectPrevPageHotkey, ""); public string OpenContextMenuHotkey => VerifyOrSetDefaultHotkey(Settings.OpenContextMenuHotkey, "Ctrl+O"); public string SettingWindowHotkey => VerifyOrSetDefaultHotkey(Settings.SettingWindowHotkey, "Ctrl+I"); + public string CycleHistoryUpHotkey => VerifyOrSetDefaultHotkey(Settings.CycleHistoryUpHotkey, "Alt+Up"); + public string CycleHistoryDownHotkey => VerifyOrSetDefaultHotkey(Settings.CycleHistoryDownHotkey, "Alt+Down"); public string Image => Constant.QueryTextBoxIconImagePath; @@ -1116,6 +1181,7 @@ public void Show() public async void Hide() { + lasthistoryindex = 1; // Trick for no delay MainWindowOpacity = 0; lastContextMenuResult = new Result(); From 572e889c3449d604c7ad833cd8409f4bfb9da8ce Mon Sep 17 00:00:00 2001 From: DB p Date: Thu, 16 May 2024 01:44:00 +0900 Subject: [PATCH 2/7] Delete unused code --- Flow.Launcher/ViewModel/MainViewModel.cs | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index ac5b980e08b..2e52f92c1cf 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -289,23 +289,6 @@ public void ForwardHistory() } } - [RelayCommand] - public void ReverseHistoryOnEmptyQuery() - { - var results = SelectedResults; - if (_history.Items.Count > 0 - && _queryText == String.Empty - && !HistorySelected() - && !ContextMenuSelected()) - { - ReverseHistory(); - } - else - { - SelectedResults.SelectPrevResult(); - } - } - [RelayCommand] private void LoadContextMenu() { From aa82d358d1e8642dee2ab93746e983401f10b48a Mon Sep 17 00:00:00 2001 From: DB p Date: Thu, 16 May 2024 15:16:52 +0900 Subject: [PATCH 3/7] Add Strings --- Flow.Launcher/Languages/en.xaml | 2 ++ Flow.Launcher/SettingWindow.xaml | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Flow.Launcher/Languages/en.xaml b/Flow.Launcher/Languages/en.xaml index fd24f825ecc..9ab05555c1e 100644 --- a/Flow.Launcher/Languages/en.xaml +++ b/Flow.Launcher/Languages/en.xaml @@ -188,6 +188,8 @@ Select Previous Item Next Page Previous Page + Cycle Previous Query + Cycle Next Query Open Context Menu Open Setting Window Copy File Path diff --git a/Flow.Launcher/SettingWindow.xaml b/Flow.Launcher/SettingWindow.xaml index 4a563bc450f..a8de26af7c9 100644 --- a/Flow.Launcher/SettingWindow.xaml +++ b/Flow.Launcher/SettingWindow.xaml @@ -2811,8 +2811,8 @@ Date: Sun, 19 May 2024 22:47:14 +0800 Subject: [PATCH 4/7] Extract fixed hotkeys --- .../UserSettings/Settings.cs | 77 ++++++++++--------- 1 file changed, 42 insertions(+), 35 deletions(-) diff --git a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs index 3d443349310..61a9da40050 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs @@ -282,42 +282,9 @@ public List RegisteredHotkeys { get { - var list = new List - { - new("Up", "HotkeyLeftRightDesc"), - new("Down", "HotkeyLeftRightDesc"), - new("Left", "HotkeyUpDownDesc"), - new("Right", "HotkeyUpDownDesc"), - new("Escape", "HotkeyESCDesc"), - new("F5", "ReloadPluginHotkey"), - new("Alt+Home", "HotkeySelectFirstResult"), - new("Alt+End", "HotkeySelectLastResult"), - new("Ctrl+R", "HotkeyRequery"), - new("Ctrl+H", "ToggleHistoryHotkey"), - new("Ctrl+OemCloseBrackets", "QuickWidthHotkey"), - new("Ctrl+OemOpenBrackets", "QuickWidthHotkey"), - new("Ctrl+OemPlus", "QuickHeightHotkey"), - new("Ctrl+OemMinus", "QuickHeightHotkey"), - new("Ctrl+Shift+Enter", "HotkeyCtrlShiftEnterDesc"), - new("Shift+Enter", "OpenContextMenuHotkey"), - new("Enter", "HotkeyRunDesc"), - new("Ctrl+Enter", "OpenContainFolderHotkey"), - new("Alt+Enter", "HotkeyOpenResult"), - new("Ctrl+F12", "ToggleGameModeHotkey"), - new("Ctrl+Shift+C", "CopyFilePathHotkey"), - - new($"{OpenResultModifiers}+D1", "HotkeyOpenResultN", 1), - new($"{OpenResultModifiers}+D2", "HotkeyOpenResultN", 2), - new($"{OpenResultModifiers}+D3", "HotkeyOpenResultN", 3), - new($"{OpenResultModifiers}+D4", "HotkeyOpenResultN", 4), - new($"{OpenResultModifiers}+D5", "HotkeyOpenResultN", 5), - new($"{OpenResultModifiers}+D6", "HotkeyOpenResultN", 6), - new($"{OpenResultModifiers}+D7", "HotkeyOpenResultN", 7), - new($"{OpenResultModifiers}+D8", "HotkeyOpenResultN", 8), - new($"{OpenResultModifiers}+D9", "HotkeyOpenResultN", 9), - new($"{OpenResultModifiers}+D0", "HotkeyOpenResultN", 10) - }; + var list = FixedHotkeys(); + // Customizeable hotkeys if(!string.IsNullOrEmpty(Hotkey)) list.Add(new(Hotkey, "flowlauncherHotkey", () => Hotkey = "")); if(!string.IsNullOrEmpty(PreviewHotkey)) @@ -347,6 +314,7 @@ public List RegisteredHotkeys if (!string.IsNullOrEmpty(CycleHistoryDownHotkey)) list.Add(new(CycleHistoryDownHotkey, "CycleHistoryDownHotkey", () => CycleHistoryDownHotkey = "")); + // Custom Query Hotkeys foreach (var customPluginHotkey in CustomPluginHotkeys) { if (!string.IsNullOrEmpty(customPluginHotkey.Hotkey)) @@ -356,6 +324,45 @@ public List RegisteredHotkeys return list; } } + + private List FixedHotkeys() + { + return new List + { + new("Up", "HotkeyLeftRightDesc"), + new("Down", "HotkeyLeftRightDesc"), + new("Left", "HotkeyUpDownDesc"), + new("Right", "HotkeyUpDownDesc"), + new("Escape", "HotkeyESCDesc"), + new("F5", "ReloadPluginHotkey"), + new("Alt+Home", "HotkeySelectFirstResult"), + new("Alt+End", "HotkeySelectLastResult"), + new("Ctrl+R", "HotkeyRequery"), + new("Ctrl+H", "ToggleHistoryHotkey"), + new("Ctrl+OemCloseBrackets", "QuickWidthHotkey"), + new("Ctrl+OemOpenBrackets", "QuickWidthHotkey"), + new("Ctrl+OemPlus", "QuickHeightHotkey"), + new("Ctrl+OemMinus", "QuickHeightHotkey"), + new("Ctrl+Shift+Enter", "HotkeyCtrlShiftEnterDesc"), + new("Shift+Enter", "OpenContextMenuHotkey"), + new("Enter", "HotkeyRunDesc"), + new("Ctrl+Enter", "OpenContainFolderHotkey"), + new("Alt+Enter", "HotkeyOpenResult"), + new("Ctrl+F12", "ToggleGameModeHotkey"), + new("Ctrl+Shift+C", "CopyFilePathHotkey"), + + new($"{OpenResultModifiers}+D1", "HotkeyOpenResultN", 1), + new($"{OpenResultModifiers}+D2", "HotkeyOpenResultN", 2), + new($"{OpenResultModifiers}+D3", "HotkeyOpenResultN", 3), + new($"{OpenResultModifiers}+D4", "HotkeyOpenResultN", 4), + new($"{OpenResultModifiers}+D5", "HotkeyOpenResultN", 5), + new($"{OpenResultModifiers}+D6", "HotkeyOpenResultN", 6), + new($"{OpenResultModifiers}+D7", "HotkeyOpenResultN", 7), + new($"{OpenResultModifiers}+D8", "HotkeyOpenResultN", 8), + new($"{OpenResultModifiers}+D9", "HotkeyOpenResultN", 9), + new($"{OpenResultModifiers}+D0", "HotkeyOpenResultN", 10) + }; + } } public enum LastQueryMode From 7924dcca0d83e69cb70a402881cf1cc8110ce120 Mon Sep 17 00:00:00 2001 From: VictoriousRaptor <10308169+VictoriousRaptor@users.noreply.github.com> Date: Sun, 19 May 2024 23:16:56 +0800 Subject: [PATCH 5/7] Rename to camel case --- Flow.Launcher/ViewModel/MainViewModel.cs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 2e52f92c1cf..a134dbfa502 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -42,7 +42,7 @@ public partial class MainViewModel : BaseModel, ISavable private readonly FlowLauncherJsonStorage _userSelectedRecordStorage; private readonly FlowLauncherJsonStorage _topMostRecordStorage; private readonly History _history; - private int lasthistoryindex = 1; + private int lastHistoryIndex = 1; private readonly UserSelectedRecord _userSelectedRecord; private readonly TopMostRecord _topMostRecord; @@ -268,10 +268,10 @@ public void ReverseHistory() { if (_history.Items.Count > 0) { - ChangeQueryText(_history.Items[_history.Items.Count - lasthistoryindex].Query.ToString()); - if (lasthistoryindex < _history.Items.Count) + ChangeQueryText(_history.Items[_history.Items.Count - lastHistoryIndex].Query.ToString()); + if (lastHistoryIndex < _history.Items.Count) { - lasthistoryindex++; + lastHistoryIndex++; } } } @@ -281,10 +281,10 @@ public void ForwardHistory() { if (_history.Items.Count > 0) { - ChangeQueryText(_history.Items[_history.Items.Count - lasthistoryindex].Query.ToString()); - if (lasthistoryindex > 1) + ChangeQueryText(_history.Items[_history.Items.Count - lastHistoryIndex].Query.ToString()); + if (lastHistoryIndex > 1) { - lasthistoryindex--; + lastHistoryIndex--; } } } @@ -379,6 +379,7 @@ private async Task OpenResultAsync(string index) { _userSelectedRecord.Add(result); _history.Add(result.OriginQuery.RawQuery); + } if (hideWindow) @@ -427,13 +428,12 @@ private void SelectNextPage() [RelayCommand] private void SelectPrevItem() { - var results = SelectedResults; if (_history.Items.Count > 0 && _queryText == String.Empty && !HistorySelected() && !ContextMenuSelected()) { - lasthistoryindex = 1; + lastHistoryIndex = 1; ReverseHistory(); } else @@ -1164,7 +1164,7 @@ public void Show() public async void Hide() { - lasthistoryindex = 1; + lastHistoryIndex = 1; // Trick for no delay MainWindowOpacity = 0; lastContextMenuResult = new Result(); From 9ac92e293980ab1936eabba44f50c564e801fca3 Mon Sep 17 00:00:00 2001 From: VictoriousRaptor <10308169+VictoriousRaptor@users.noreply.github.com> Date: Sun, 19 May 2024 23:17:57 +0800 Subject: [PATCH 6/7] Reset lastHistoryIndex when opening result --- Flow.Launcher/ViewModel/MainViewModel.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index a134dbfa502..fbd35ed5b43 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -379,7 +379,7 @@ private async Task OpenResultAsync(string index) { _userSelectedRecord.Add(result); _history.Add(result.OriginQuery.RawQuery); - + lastHistoryIndex = 1; } if (hideWindow) From 3d6d79b6e4695959d428b328bea9a9dd2e164600 Mon Sep 17 00:00:00 2001 From: VictoriousRaptor <10308169+VictoriousRaptor@users.noreply.github.com> Date: Sun, 19 May 2024 23:27:24 +0800 Subject: [PATCH 7/7] Simplify conditions --- Flow.Launcher/ViewModel/MainViewModel.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index fbd35ed5b43..01dc67b9844 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -429,9 +429,8 @@ private void SelectNextPage() private void SelectPrevItem() { if (_history.Items.Count > 0 - && _queryText == String.Empty - && !HistorySelected() - && !ContextMenuSelected()) + && QueryText == string.Empty + && SelectedIsFromQueryResults()) { lastHistoryIndex = 1; ReverseHistory();