From e722927d9e0e1e2dd72359cc11cc80b7a54dc24b Mon Sep 17 00:00:00 2001 From: AminSallah <124622454+AminSallah@users.noreply.github.com> Date: Sun, 25 Feb 2024 04:05:54 +0200 Subject: [PATCH 1/4] ReQuery method overloading, reselect flag. --- Flow.Launcher/ViewModel/MainViewModel.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index ab93e08e2..6e53879f8 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -33,6 +33,7 @@ namespace Flow.Launcher.ViewModel #region Private Fields private bool _isQueryRunning; + private bool _reselect = true; private Query _lastQuery; private Result lastContextMenuResult = new Result(); private List lastContextMenuResults = new List(); @@ -216,6 +217,15 @@ namespace Flow.Launcher.ViewModel } } + public void ReQuery(bool reselect) + { + if (SelectedIsFromQueryResults()) + { + _reselect = reselect; + QueryResults(isReQuery: true); + } + } + [RelayCommand] private void LoadContextMenu() { @@ -1151,7 +1161,8 @@ namespace Flow.Launcher.ViewModel } } - Results.AddResults(resultsForUpdates, token); + Results.AddResults(resultsForUpdates, token, _reselect); + _reselect = true; } #endregion From 1d6c4cee2e703510ad60e0d011d55d4d0170dc4a Mon Sep 17 00:00:00 2001 From: AminSallah <124622454+AminSallah@users.noreply.github.com> Date: Sun, 25 Feb 2024 04:11:30 +0200 Subject: [PATCH 2/4] AddResults & UpdateResults new param "reselect" --- Flow.Launcher/ViewModel/ResultsViewModel.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Flow.Launcher/ViewModel/ResultsViewModel.cs b/Flow.Launcher/ViewModel/ResultsViewModel.cs index bb07ce085..d02dc9bd5 100644 --- a/Flow.Launcher/ViewModel/ResultsViewModel.cs +++ b/Flow.Launcher/ViewModel/ResultsViewModel.cs @@ -147,23 +147,23 @@ namespace Flow.Launcher.ViewModel /// /// To avoid deadlock, this method should not called from main thread /// - public void AddResults(IEnumerable resultsForUpdates, CancellationToken token) + public void AddResults(IEnumerable resultsForUpdates, CancellationToken token, bool reselect = true) { var newResults = NewResults(resultsForUpdates); if (token.IsCancellationRequested) return; - UpdateResults(newResults, token); + UpdateResults(newResults, token, reselect); } - private void UpdateResults(List newResults, CancellationToken token = default) + private void UpdateResults(List newResults, CancellationToken token = default, bool reselect = true) { lock (_collectionLock) { // update UI in one run, so it can avoid UI flickering Results.Update(newResults, token); - if (Results.Any()) + if (reselect && Results.Any()) SelectedItem = Results[0]; } From ae84dae66dd98a7c894684d51b0fb98304242715 Mon Sep 17 00:00:00 2001 From: AminSallah <124622454+AminSallah@users.noreply.github.com> Date: Sun, 25 Feb 2024 04:13:09 +0200 Subject: [PATCH 3/4] ReQuery new param "reselect" --- Flow.Launcher/PublicAPIInstance.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs index 5efc2324e..b49bf39d3 100644 --- a/Flow.Launcher/PublicAPIInstance.cs +++ b/Flow.Launcher/PublicAPIInstance.cs @@ -315,7 +315,7 @@ namespace Flow.Launcher public void RegisterGlobalKeyboardCallback(Func callback) => _globalKeyboardHandlers.Add(callback); public void RemoveGlobalKeyboardCallback(Func callback) => _globalKeyboardHandlers.Remove(callback); - public void ReQuery() => _mainVM.ReQuery(); + public void ReQuery(bool reselect = true) => _mainVM.ReQuery(reselect); #endregion From c8a2f10620e46265b879077244ccc452a7dfcff4 Mon Sep 17 00:00:00 2001 From: AminSallah <124622454+AminSallah@users.noreply.github.com> Date: Sun, 25 Feb 2024 04:29:14 +0200 Subject: [PATCH 4/4] Introduce param "reselect" to ReQuery instance --- Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs b/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs index 78f1e0afa..c95a8ce7b 100644 --- a/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs +++ b/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs @@ -293,9 +293,10 @@ namespace Flow.Launcher.Plugin public bool IsGameModeOn(); /// - /// Reload Query + /// Reloads the query. + /// This method should run /// - /// - public void ReQuery(); + /// Choose the first result after reload if true; keep the last selected result if false. Default is true. + public void ReQuery(bool reselect = true); } }