From 1562c88ea71a0f56033553016682a51bc019d590 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Sun, 26 Jan 2025 20:07:40 +0800 Subject: [PATCH 1/5] Improve context menu item action response --- Flow.Launcher/ViewModel/MainViewModel.cs | 4 ++++ Plugins/Flow.Launcher.Plugin.Explorer/ContextMenu.cs | 1 + Plugins/Flow.Launcher.Plugin.Program/Main.cs | 2 ++ 3 files changed, 7 insertions(+) diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 55bc8d1b3f8..b12e97e0b3b 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -1273,6 +1273,8 @@ private Result ContextMenuTopMost(Result result) { _topMostRecord.Remove(result); App.API.ShowMsg(InternationalizationManager.Instance.GetTranslation("success")); + App.API.BackToQueryResults(); + App.API.ReQuery(); return false; } }; @@ -1289,6 +1291,8 @@ private Result ContextMenuTopMost(Result result) { _topMostRecord.AddOrUpdate(result); App.API.ShowMsg(InternationalizationManager.Instance.GetTranslation("success")); + App.API.BackToQueryResults(); + App.API.ReQuery(); return false; } }; diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/ContextMenu.cs b/Plugins/Flow.Launcher.Plugin.Explorer/ContextMenu.cs index feccc74c8e1..3f3b7cb5846 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/ContextMenu.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/ContextMenu.cs @@ -242,6 +242,7 @@ public List LoadContextMenus(Result selectedResult) var name = "Plugin: Folder"; var message = $"File not found: {e.Message}"; Context.API.ShowMsgError(name, message); + return false; } return true; diff --git a/Plugins/Flow.Launcher.Plugin.Program/Main.cs b/Plugins/Flow.Launcher.Plugin.Program/Main.cs index 00b97e11435..6ba7047f23e 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Program/Main.cs @@ -264,6 +264,8 @@ public List LoadContextMenus(Result selectedResult) Context.API.GetTranslation("flowlauncher_plugin_program_disable_dlgtitle_success"), Context.API.GetTranslation( "flowlauncher_plugin_program_disable_dlgtitle_success_message")); + Context.API.BackToQueryResults(); + Context.API.ReQuery(); return false; }, IcoPath = "Images/disable.png", From ae5186dacfad5fd354867b1ec254edaa913e0a52 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Sun, 26 Jan 2025 20:21:30 +0800 Subject: [PATCH 2/5] Remove context menu cache --- Flow.Launcher/ViewModel/MainViewModel.cs | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index b12e97e0b3b..2d232ebdd01 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -34,8 +34,6 @@ public partial class MainViewModel : BaseModel, ISavable private bool _isQueryRunning; private Query _lastQuery; - private Result lastContextMenuResult = new Result(); - private List lastContextMenuResults = new List(); private string _queryTextBeforeLeaveResults; private readonly FlowLauncherJsonStorage _historyItemsStorage; @@ -986,19 +984,10 @@ private void QueryContextMenu() if (selected != null) // SelectedItem returns null if selection is empty. { List results; - if (selected == lastContextMenuResult) - { - results = lastContextMenuResults; - } - else - { + results = PluginManager.GetContextMenusForPlugin(selected); - lastContextMenuResults = results; - lastContextMenuResult = selected; results.Add(ContextMenuTopMost(selected)); results.Add(ContextMenuPluginInfo(selected.PluginID)); - } - if (!string.IsNullOrEmpty(query)) { @@ -1381,8 +1370,6 @@ public async void Hide() lastHistoryIndex = 1; // Trick for no delay MainWindowOpacity = 0; - lastContextMenuResult = new Result(); - lastContextMenuResults = new List(); if (ExternalPreviewVisible) CloseExternalPreview(); From 00de8611e1996d724c48672b5712c4db8f071b63 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Sun, 26 Jan 2025 20:37:41 +0800 Subject: [PATCH 3/5] Remove useless obsolete constructor --- Flow.Launcher.Plugin/Query.cs | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/Flow.Launcher.Plugin/Query.cs b/Flow.Launcher.Plugin/Query.cs index b41675a1aa4..e182491c2f0 100644 --- a/Flow.Launcher.Plugin/Query.cs +++ b/Flow.Launcher.Plugin/Query.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; namespace Flow.Launcher.Plugin { @@ -9,15 +6,6 @@ public class Query { public Query() { } - [Obsolete("Use the default Query constructor.")] - public Query(string rawQuery, string search, string[] terms, string[] searchTerms, string actionKeyword = "") - { - Search = search; - RawQuery = rawQuery; - SearchTerms = searchTerms; - ActionKeyword = actionKeyword; - } - /// /// Raw query, this includes action keyword if it has /// We didn't recommend use this property directly. You should always use Search property. From 95c8475c436b687822ddee2b342da5e4945225b3 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Sun, 26 Jan 2025 20:45:58 +0800 Subject: [PATCH 4/5] Fix null exception when result is from context menu & Add documents --- Flow.Launcher/Storage/TopMostRecord.cs | 2 ++ Flow.Launcher/Storage/UserSelectedRecord.cs | 2 ++ Flow.Launcher/ViewModel/MainViewModel.cs | 14 +++++++++----- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Flow.Launcher/Storage/TopMostRecord.cs b/Flow.Launcher/Storage/TopMostRecord.cs index cbd0b88fc7e..e76c5749344 100644 --- a/Flow.Launcher/Storage/TopMostRecord.cs +++ b/Flow.Launcher/Storage/TopMostRecord.cs @@ -12,6 +12,8 @@ public class TopMostRecord internal bool IsTopMost(Result result) { + // origin query is null when user select the context menu item directly of one item from query list + // in this case, we do not need to check if the result is top most if (records.IsEmpty || result.OriginQuery == null || !records.TryGetValue(result.OriginQuery.RawQuery, out var value)) { diff --git a/Flow.Launcher/Storage/UserSelectedRecord.cs b/Flow.Launcher/Storage/UserSelectedRecord.cs index d6405005dba..4f62d2b08a9 100644 --- a/Flow.Launcher/Storage/UserSelectedRecord.cs +++ b/Flow.Launcher/Storage/UserSelectedRecord.cs @@ -51,6 +51,8 @@ private static int GenerateResultHashCode(Result result) private static int GenerateQueryAndResultHashCode(Query query, Result result) { + // query is null when user select the context menu item directly of one item from query list + // so we only need to consider the result if (query == null) { return GenerateResultHashCode(result); diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 2d232ebdd01..5c3251bfc7e 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -396,11 +396,15 @@ private async Task OpenResultAsync(string index) }) .ConfigureAwait(false); - if (SelectedIsFromQueryResults()) { _userSelectedRecord.Add(result); - _history.Add(result.OriginQuery.RawQuery); + // origin query is null when user select the context menu item directly of one item from query list + // so we don't want to add it to history + if (result.OriginQuery != null) + { + _history.Add(result.OriginQuery.RawQuery); + } lastHistoryIndex = 1; } @@ -985,9 +989,9 @@ private void QueryContextMenu() { List results; - results = PluginManager.GetContextMenusForPlugin(selected); - results.Add(ContextMenuTopMost(selected)); - results.Add(ContextMenuPluginInfo(selected.PluginID)); + results = PluginManager.GetContextMenusForPlugin(selected); + results.Add(ContextMenuTopMost(selected)); + results.Add(ContextMenuPluginInfo(selected.PluginID)); if (!string.IsNullOrEmpty(query)) { From 80f54ba0de3b55c6ef1cac360078dddd9a1e07a4 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Sun, 26 Jan 2025 20:51:12 +0800 Subject: [PATCH 5/5] Fix more possible origin query null exception & Remove useless load function --- Flow.Launcher/Storage/TopMostRecord.cs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/Flow.Launcher/Storage/TopMostRecord.cs b/Flow.Launcher/Storage/TopMostRecord.cs index e76c5749344..a2af6fe92d8 100644 --- a/Flow.Launcher/Storage/TopMostRecord.cs +++ b/Flow.Launcher/Storage/TopMostRecord.cs @@ -26,11 +26,25 @@ internal bool IsTopMost(Result result) internal void Remove(Result result) { + // origin query is null when user select the context menu item directly of one item from query list + // in this case, we do not need to remove the record + if (result.OriginQuery == null) + { + return; + } + records.Remove(result.OriginQuery.RawQuery, out _); } internal void AddOrUpdate(Result result) { + // origin query is null when user select the context menu item directly of one item from query list + // in this case, we do not need to add or update the record + if (result.OriginQuery == null) + { + return; + } + var record = new Record { PluginID = result.PluginID, @@ -39,11 +53,6 @@ internal void AddOrUpdate(Result result) }; records.AddOrUpdate(result.OriginQuery.RawQuery, record, (key, oldValue) => record); } - - public void Load(Dictionary dictionary) - { - records = new ConcurrentDictionary(dictionary); - } } public class Record