mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 04:07:40 +02:00
Remove all plugin results on query change (#5796)
This commit is contained in:
committed by
GitHub
parent
7d8931696d
commit
b2006f2466
@@ -31,7 +31,7 @@ namespace PowerLauncher.ViewModel
|
|||||||
{
|
{
|
||||||
#region Private Fields
|
#region Private Fields
|
||||||
|
|
||||||
private Query _lastQuery;
|
private Query _currentQuery;
|
||||||
private static Query _emptyQuery = new Query();
|
private static Query _emptyQuery = new Query();
|
||||||
private static bool _disposed;
|
private static bool _disposed;
|
||||||
private string _queryTextBeforeLeaveResults;
|
private string _queryTextBeforeLeaveResults;
|
||||||
@@ -65,7 +65,7 @@ namespace PowerLauncher.ViewModel
|
|||||||
_hotkeyManager = new HotkeyManager();
|
_hotkeyManager = new HotkeyManager();
|
||||||
_saved = false;
|
_saved = false;
|
||||||
_queryTextBeforeLeaveResults = "";
|
_queryTextBeforeLeaveResults = "";
|
||||||
_lastQuery = _emptyQuery;
|
_currentQuery = _emptyQuery;
|
||||||
_disposed = false;
|
_disposed = false;
|
||||||
|
|
||||||
_settings = settings ?? throw new ArgumentNullException(nameof(settings));
|
_settings = settings ?? throw new ArgumentNullException(nameof(settings));
|
||||||
@@ -118,7 +118,7 @@ namespace PowerLauncher.ViewModel
|
|||||||
Task.Run(() =>
|
Task.Run(() =>
|
||||||
{
|
{
|
||||||
PluginManager.UpdatePluginMetadata(e.Results, pair.Metadata, e.Query);
|
PluginManager.UpdatePluginMetadata(e.Results, pair.Metadata, e.Query);
|
||||||
UpdateResultView(e.Results, pair.Metadata, e.Query, _updateToken);
|
UpdateResultView(e.Results, e.Query, _updateToken);
|
||||||
}, _updateToken);
|
}, _updateToken);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -413,7 +413,6 @@ namespace PowerLauncher.ViewModel
|
|||||||
|
|
||||||
private void QueryHistory()
|
private void QueryHistory()
|
||||||
{
|
{
|
||||||
const string id = "Query History ID";
|
|
||||||
#pragma warning disable CA1308 // Normalize strings to uppercase
|
#pragma warning disable CA1308 // Normalize strings to uppercase
|
||||||
var query = QueryText.ToLower(CultureInfo.InvariantCulture).Trim();
|
var query = QueryText.ToLower(CultureInfo.InvariantCulture).Trim();
|
||||||
#pragma warning restore CA1308 // Normalize strings to uppercase
|
#pragma warning restore CA1308 // Normalize strings to uppercase
|
||||||
@@ -447,11 +446,11 @@ namespace PowerLauncher.ViewModel
|
|||||||
r => StringMatcher.FuzzySearch(query, r.Title).IsSearchPrecisionScoreMet() ||
|
r => StringMatcher.FuzzySearch(query, r.Title).IsSearchPrecisionScoreMet() ||
|
||||||
StringMatcher.FuzzySearch(query, r.SubTitle).IsSearchPrecisionScoreMet()
|
StringMatcher.FuzzySearch(query, r.SubTitle).IsSearchPrecisionScoreMet()
|
||||||
).ToList();
|
).ToList();
|
||||||
History.AddResults(filtered, id, _updateToken);
|
History.AddResults(filtered, _updateToken);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
History.AddResults(results, id, _updateToken);
|
History.AddResults(results, _updateToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -470,7 +469,7 @@ namespace PowerLauncher.ViewModel
|
|||||||
var query = QueryBuilder.Build(QueryText.Trim(), PluginManager.NonGlobalPlugins);
|
var query = QueryBuilder.Build(QueryText.Trim(), PluginManager.NonGlobalPlugins);
|
||||||
if (query != null)
|
if (query != null)
|
||||||
{
|
{
|
||||||
_lastQuery = query;
|
_currentQuery = query;
|
||||||
Task.Run(() =>
|
Task.Run(() =>
|
||||||
{
|
{
|
||||||
Thread.Sleep(20);
|
Thread.Sleep(20);
|
||||||
@@ -493,21 +492,24 @@ namespace PowerLauncher.ViewModel
|
|||||||
|
|
||||||
lock (_addResultsLock)
|
lock (_addResultsLock)
|
||||||
{
|
{
|
||||||
RemoveOldQueryResults(query);
|
if (query.RawQuery == _currentQuery.RawQuery)
|
||||||
foreach (var p in resultPluginPair)
|
|
||||||
{
|
{
|
||||||
UpdateResultView(p.Item1, p.Item2, query, currentCancellationToken);
|
Results.Clear();
|
||||||
currentCancellationToken.ThrowIfCancellationRequested();
|
foreach (var p in resultPluginPair)
|
||||||
}
|
{
|
||||||
|
UpdateResultView(p.Item1, query, currentCancellationToken);
|
||||||
|
currentCancellationToken.ThrowIfCancellationRequested();
|
||||||
|
}
|
||||||
|
|
||||||
currentCancellationToken.ThrowIfCancellationRequested();
|
currentCancellationToken.ThrowIfCancellationRequested();
|
||||||
Results.Results.Sort();
|
Results.Results.Sort();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
currentCancellationToken.ThrowIfCancellationRequested();
|
currentCancellationToken.ThrowIfCancellationRequested();
|
||||||
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
|
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
|
||||||
{
|
{
|
||||||
if (query.RawQuery == _lastQuery.RawQuery)
|
if (query.RawQuery == _currentQuery.RawQuery)
|
||||||
{
|
{
|
||||||
Results.Results.NotifyChanges();
|
Results.Results.NotifyChanges();
|
||||||
}
|
}
|
||||||
@@ -542,37 +544,13 @@ namespace PowerLauncher.ViewModel
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
_updateSource?.Cancel();
|
_updateSource?.Cancel();
|
||||||
_lastQuery = _emptyQuery;
|
_currentQuery = _emptyQuery;
|
||||||
Results.SelectedItem = null;
|
Results.SelectedItem = null;
|
||||||
Results.Visibility = Visibility.Hidden;
|
Results.Visibility = Visibility.Hidden;
|
||||||
Results.Clear();
|
Results.Clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RemoveOldQueryResults(Query query)
|
|
||||||
{
|
|
||||||
string lastKeyword = _lastQuery.ActionKeyword;
|
|
||||||
string keyword = query.ActionKeyword;
|
|
||||||
if (string.IsNullOrEmpty(lastKeyword))
|
|
||||||
{
|
|
||||||
if (!string.IsNullOrEmpty(keyword))
|
|
||||||
{
|
|
||||||
Results.RemoveResultsExcept(PluginManager.NonGlobalPlugins[keyword].Metadata);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(keyword))
|
|
||||||
{
|
|
||||||
Results.RemoveResultsFor(PluginManager.NonGlobalPlugins[lastKeyword].Metadata);
|
|
||||||
}
|
|
||||||
else if (lastKeyword != keyword)
|
|
||||||
{
|
|
||||||
Results.RemoveResultsExcept(PluginManager.NonGlobalPlugins[keyword].Metadata);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool SelectedIsFromQueryResults()
|
private bool SelectedIsFromQueryResults()
|
||||||
{
|
{
|
||||||
var selected = SelectedResults == Results;
|
var selected = SelectedResults == Results;
|
||||||
@@ -714,18 +692,13 @@ namespace PowerLauncher.ViewModel
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// To avoid deadlock, this method should not called from main thread
|
/// To avoid deadlock, this method should not called from main thread
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void UpdateResultView(List<Result> list, PluginMetadata metadata, Query originQuery, CancellationToken ct)
|
public void UpdateResultView(List<Result> list, Query originQuery, CancellationToken ct)
|
||||||
{
|
{
|
||||||
if (list == null)
|
if (list == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(list));
|
throw new ArgumentNullException(nameof(list));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (metadata == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(metadata));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (originQuery == null)
|
if (originQuery == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(originQuery));
|
throw new ArgumentNullException(nameof(originQuery));
|
||||||
@@ -743,10 +716,10 @@ namespace PowerLauncher.ViewModel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (originQuery.RawQuery == _lastQuery.RawQuery)
|
if (originQuery.RawQuery == _currentQuery.RawQuery)
|
||||||
{
|
{
|
||||||
ct.ThrowIfCancellationRequested();
|
ct.ThrowIfCancellationRequested();
|
||||||
Results.AddResults(list, metadata.ID, ct);
|
Results.AddResults(list, ct);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -759,7 +732,7 @@ namespace PowerLauncher.ViewModel
|
|||||||
Title = "hello"
|
Title = "hello"
|
||||||
};
|
};
|
||||||
list.Add(r);
|
list.Add(r);
|
||||||
Results.AddResults(list, "0", _updateToken);
|
Results.AddResults(list, _updateToken);
|
||||||
Results.Clear();
|
Results.Clear();
|
||||||
MainWindowVisibility = System.Windows.Visibility.Collapsed;
|
MainWindowVisibility = System.Windows.Visibility.Collapsed;
|
||||||
|
|
||||||
|
|||||||
@@ -222,7 +222,7 @@ namespace PowerLauncher.ViewModel
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Add new results to ResultCollection
|
/// Add new results to ResultCollection
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void AddResults(List<Result> newRawResults, string resultId, CancellationToken ct)
|
public void AddResults(List<Result> newRawResults, CancellationToken ct)
|
||||||
{
|
{
|
||||||
if (newRawResults == null)
|
if (newRawResults == null)
|
||||||
{
|
{
|
||||||
@@ -236,7 +236,6 @@ namespace PowerLauncher.ViewModel
|
|||||||
ct.ThrowIfCancellationRequested();
|
ct.ThrowIfCancellationRequested();
|
||||||
}
|
}
|
||||||
|
|
||||||
Results.RemoveAll(r => r.Result.PluginID == resultId);
|
|
||||||
Results.AddRange(newResults);
|
Results.AddRange(newResults);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
Reference in New Issue
Block a user