mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Merge pull request #3203 from Jack251970/context_menu_back_to_query
Improve context menu item action response & Fix origin query null exception
This commit is contained in:
commit
735cc14821
6 changed files with 35 additions and 36 deletions
|
|
@ -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 @@ namespace Flow.Launcher.Plugin
|
|||
{
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raw query, this includes action keyword if it has
|
||||
/// We didn't recommend use this property directly. You should always use Search property.
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ namespace Flow.Launcher.Storage
|
|||
|
||||
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 @@ namespace Flow.Launcher.Storage
|
|||
|
||||
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,
|
||||
|
|
@ -38,11 +54,6 @@ namespace Flow.Launcher.Storage
|
|||
};
|
||||
records.AddOrUpdate(result.OriginQuery.RawQuery, record, (key, oldValue) => record);
|
||||
}
|
||||
|
||||
public void Load(Dictionary<string, Record> dictionary)
|
||||
{
|
||||
records = new ConcurrentDictionary<string, Record>(dictionary);
|
||||
}
|
||||
}
|
||||
|
||||
public class Record
|
||||
|
|
|
|||
|
|
@ -57,6 +57,8 @@ namespace Flow.Launcher.Storage
|
|||
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -34,8 +34,6 @@ namespace Flow.Launcher.ViewModel
|
|||
|
||||
private bool _isQueryRunning;
|
||||
private Query _lastQuery;
|
||||
private Result lastContextMenuResult = new Result();
|
||||
private List<Result> lastContextMenuResults = new List<Result>();
|
||||
private string _queryTextBeforeLeaveResults;
|
||||
|
||||
private readonly FlowLauncherJsonStorage<History> _historyItemsStorage;
|
||||
|
|
@ -398,11 +396,15 @@ namespace Flow.Launcher.ViewModel
|
|||
})
|
||||
.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 @@ namespace Flow.Launcher.ViewModel
|
|||
if (selected != null) // SelectedItem returns null if selection is empty.
|
||||
{
|
||||
List<Result> 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 @@ namespace Flow.Launcher.ViewModel
|
|||
{
|
||||
_topMostRecord.Remove(result);
|
||||
App.API.ShowMsg(InternationalizationManager.Instance.GetTranslation("success"));
|
||||
App.API.BackToQueryResults();
|
||||
App.API.ReQuery();
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
|
@ -1289,6 +1284,8 @@ namespace Flow.Launcher.ViewModel
|
|||
{
|
||||
_topMostRecord.AddOrUpdate(result);
|
||||
App.API.ShowMsg(InternationalizationManager.Instance.GetTranslation("success"));
|
||||
App.API.BackToQueryResults();
|
||||
App.API.ReQuery();
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
|
@ -1377,8 +1374,6 @@ namespace Flow.Launcher.ViewModel
|
|||
lastHistoryIndex = 1;
|
||||
// Trick for no delay
|
||||
MainWindowOpacity = 0;
|
||||
lastContextMenuResult = new Result();
|
||||
lastContextMenuResults = new List<Result>();
|
||||
|
||||
if (ExternalPreviewVisible)
|
||||
CloseExternalPreview();
|
||||
|
|
|
|||
|
|
@ -242,6 +242,7 @@ namespace Flow.Launcher.Plugin.Explorer
|
|||
var name = "Plugin: Folder";
|
||||
var message = $"File not found: {e.Message}";
|
||||
Context.API.ShowMsgError(name, message);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -264,6 +264,8 @@ namespace Flow.Launcher.Plugin.Program
|
|||
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",
|
||||
|
|
|
|||
Loading…
Reference in a new issue