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. diff --git a/Flow.Launcher/Storage/TopMostRecord.cs b/Flow.Launcher/Storage/TopMostRecord.cs index cbd0b88fc7e..a2af6fe92d8 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)) { @@ -24,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, @@ -37,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 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 55bc8d1b3f8..5c3251bfc7e 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; @@ -398,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; } @@ -986,19 +988,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)); - } + results = PluginManager.GetContextMenusForPlugin(selected); + results.Add(ContextMenuTopMost(selected)); + results.Add(ContextMenuPluginInfo(selected.PluginID)); if (!string.IsNullOrEmpty(query)) { @@ -1273,6 +1266,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 +1284,8 @@ private Result ContextMenuTopMost(Result result) { _topMostRecord.AddOrUpdate(result); App.API.ShowMsg(InternationalizationManager.Instance.GetTranslation("success")); + App.API.BackToQueryResults(); + App.API.ReQuery(); return false; } }; @@ -1377,8 +1374,6 @@ public async void Hide() lastHistoryIndex = 1; // Trick for no delay MainWindowOpacity = 0; - lastContextMenuResult = new Result(); - lastContextMenuResults = new List(); if (ExternalPreviewVisible) CloseExternalPreview(); 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",