diff --git a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs index 8ecd6dc4b76..ee7f20852b3 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs @@ -15,6 +15,7 @@ public class Settings : BaseModel private string language = "en"; public string Hotkey { get; set; } = $"{KeyConstant.Alt} + {KeyConstant.Space}"; public string OpenResultModifiers { get; set; } = KeyConstant.Alt; + public string CycleHistoryModifiers { get; set; } = KeyConstant.Alt; public string ColorScheme { get; set; } = "System"; public bool ShowOpenResultHotkey { get; set; } = true; public double WindowSize { get; set; } = 580; diff --git a/Flow.Launcher/Languages/en.xaml b/Flow.Launcher/Languages/en.xaml index ec355a0ac11..c8baec9c49b 100644 --- a/Flow.Launcher/Languages/en.xaml +++ b/Flow.Launcher/Languages/en.xaml @@ -110,6 +110,8 @@ Select a modifier key to open selected result via keyboard. Show Hotkey Show result selection hotkey with results. + Cycle History Modifiers + You can switch to the previously entered query using up, down + modifier. Custom Query Hotkey Query Delete diff --git a/Flow.Launcher/MainWindow.xaml b/Flow.Launcher/MainWindow.xaml index 5d26433b511..36af6a9f392 100644 --- a/Flow.Launcher/MainWindow.xaml +++ b/Flow.Launcher/MainWindow.xaml @@ -84,10 +84,16 @@ Modifiers="Ctrl" /> + + + - @@ -2097,6 +2096,7 @@ Style="{DynamicResource SideControlCheckBox}" /> + diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 2395f8de273..aa59d31d873 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -27,6 +27,7 @@ public class MainViewModel : BaseModel, ISavable #region Private Fields private const string DefaultOpenResultModifiers = "Alt"; + private const string DefaultCycleHistoryModifiers = "Alt"; private bool _isQueryRunning; private Query _lastQuery; @@ -37,6 +38,7 @@ public class MainViewModel : BaseModel, ISavable private readonly FlowLauncherJsonStorage _topMostRecordStorage; internal readonly Settings _settings; private readonly History _history; + private int lasthistoryindex = 1; private readonly UserSelectedRecord _userSelectedRecord; private readonly TopMostRecord _topMostRecord; @@ -84,6 +86,7 @@ public MainViewModel(Settings settings) RegisterResultsUpdatedEvent(); SetOpenResultModifiers(); + SetCycleHistoryModifiers(); } private void RegisterViewUpdate() @@ -187,6 +190,50 @@ private void InitializeKeyCommands() SelectFirstResultCommand = new RelayCommand(_ => SelectedResults.SelectFirstResult()); + ReverseHistory = new RelayCommand(_ => { + + if (_history.Items.Count > 0) + { + ChangeQueryText(_history.Items[_history.Items.Count - lasthistoryindex].Query.ToString()); + + if (lasthistoryindex < _history.Items.Count) + { + lasthistoryindex++; + } + } + }); + + ForwardHistory = new RelayCommand(_ => { + + if (_history.Items.Count > 0) + { + ChangeQueryText(_history.Items[_history.Items.Count - lasthistoryindex].Query.ToString()); + + if (lasthistoryindex > 1) + { + lasthistoryindex--; + } + } + + }); + + ReverseHistoryOnEmptyQuery = new RelayCommand(_ => { + var results = SelectedResults; + + if (_history.Items.Count > 0 + && _queryText == String.Empty + && !HistorySelected() + && !ContextMenuSelected()) + { + ReverseHistory.Execute(null); + } + else + { + SelectPrevItemCommand.Execute(null); + } + + }); + StartHelpCommand = new RelayCommand(_ => { PluginManager.API.OpenUrl("https://github.com/Flow-Launcher/Flow.Launcher/wiki/Flow-Launcher/"); @@ -424,8 +471,12 @@ private ResultsViewModel SelectedResults public ICommand ReloadPluginDataCommand { get; set; } public ICommand ClearQueryCommand { get; private set; } public ICommand AutocompleteQueryCommand { get; set; } + public ICommand ReverseHistory { get; set; } + public ICommand ForwardHistory { get; set; } + public ICommand ReverseHistoryOnEmptyQuery { get; set; } public string OpenResultCommandModifiers { get; private set; } + public string CycleHistoryModifiers { get; private set; } public string Image => Constant.QueryTextBoxIconImagePath; @@ -543,6 +594,7 @@ private async void QueryResults() { Results.Clear(); Results.Visbility = Visibility.Collapsed; + lasthistoryindex = 1; PluginIconPath = null; SearchIconVisibility = Visibility.Visible; return; @@ -753,6 +805,11 @@ private void SetOpenResultModifiers() OpenResultCommandModifiers = _settings.OpenResultModifiers ?? DefaultOpenResultModifiers; } + private void SetCycleHistoryModifiers() + { + CycleHistoryModifiers = _settings.CycleHistoryModifiers ?? DefaultCycleHistoryModifiers; + } + public void ToggleFlowLauncher() { if (!MainWindowVisibilityStatus) @@ -798,7 +855,7 @@ public async void Hide() default: throw new ArgumentException($"wrong LastQueryMode: <{_settings.LastQueryMode}>"); } - + lasthistoryindex = 1; MainWindowVisibilityStatus = false; MainWindowVisibility = Visibility.Collapsed; } diff --git a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs index 2fc6934d58a..e7929923c5d 100644 --- a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs +++ b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs @@ -166,6 +166,7 @@ public List QuerySearchPrecisionStrings } public List OpenResultModifiersList => new List { KeyConstant.Alt, KeyConstant.Ctrl, $"{KeyConstant.Ctrl}+{KeyConstant.Alt}" }; + public List CycleHistoryModifiersList => new List { KeyConstant.Alt, KeyConstant.Ctrl, $"{KeyConstant.Ctrl}+{KeyConstant.Alt}" }; private Internationalization _translater => InternationalizationManager.Instance; public List Languages => _translater.LoadAvailableLanguages(); public IEnumerable MaxResultsRange => Enumerable.Range(2, 16);