mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-14 11:39:16 +08:00
results and query update fixes
This commit is contained in:
parent
be77bf94aa
commit
ced0faf916
@ -133,7 +133,7 @@ namespace Wox.Infrastructure.Image
|
|||||||
}
|
}
|
||||||
catch (System.Exception e)
|
catch (System.Exception e)
|
||||||
{
|
{
|
||||||
Log.Exception($"|ImageLoader.Load|Failed to get thumbnail for {path}", e);
|
// Log.Exception($"|ImageLoader.Load|Failed to get thumbnail for {path}", e);
|
||||||
|
|
||||||
image = ImageCache[Constant.ErrorIcon];
|
image = ImageCache[Constant.ErrorIcon];
|
||||||
ImageCache[path] = image;
|
ImageCache[path] = image;
|
||||||
|
@ -56,7 +56,7 @@
|
|||||||
<Border Style="{DynamicResource WindowBorderStyle}" MouseDown="OnMouseDown" >
|
<Border Style="{DynamicResource WindowBorderStyle}" MouseDown="OnMouseDown" >
|
||||||
<StackPanel Orientation="Vertical">
|
<StackPanel Orientation="Vertical">
|
||||||
<TextBox Style="{DynamicResource QueryBoxStyle}"
|
<TextBox Style="{DynamicResource QueryBoxStyle}"
|
||||||
Text="{Binding QueryText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
Text="{Binding QueryText, Mode=TwoWay, Delay=100, UpdateSourceTrigger=PropertyChanged}"
|
||||||
PreviewDragOver="OnPreviewDragOver"
|
PreviewDragOver="OnPreviewDragOver"
|
||||||
TextChanged="OnTextChanged"
|
TextChanged="OnTextChanged"
|
||||||
AllowDrop="True"
|
AllowDrop="True"
|
||||||
|
@ -13,7 +13,6 @@ using Wox.Core.Resource;
|
|||||||
using Wox.Helper;
|
using Wox.Helper;
|
||||||
using Wox.Infrastructure;
|
using Wox.Infrastructure;
|
||||||
using Wox.Infrastructure.Hotkey;
|
using Wox.Infrastructure.Hotkey;
|
||||||
using Wox.Infrastructure.Image;
|
|
||||||
using Wox.Infrastructure.Storage;
|
using Wox.Infrastructure.Storage;
|
||||||
using Wox.Infrastructure.UserSettings;
|
using Wox.Infrastructure.UserSettings;
|
||||||
using Wox.Plugin;
|
using Wox.Plugin;
|
||||||
@ -25,7 +24,7 @@ namespace Wox.ViewModel
|
|||||||
{
|
{
|
||||||
#region Private Fields
|
#region Private Fields
|
||||||
|
|
||||||
private bool _queryHasReturn;
|
private bool _isQueryRunning;
|
||||||
private Query _lastQuery;
|
private Query _lastQuery;
|
||||||
private string _queryTextBeforeLeaveResults;
|
private string _queryTextBeforeLeaveResults;
|
||||||
|
|
||||||
@ -371,15 +370,61 @@ namespace Wox.ViewModel
|
|||||||
if (!string.IsNullOrEmpty(QueryText))
|
if (!string.IsNullOrEmpty(QueryText))
|
||||||
{
|
{
|
||||||
_updateSource?.Cancel();
|
_updateSource?.Cancel();
|
||||||
_updateSource = new CancellationTokenSource();
|
var currentUpdateSource = new CancellationTokenSource();
|
||||||
var updateToken = _updateSource.Token;
|
_updateSource = currentUpdateSource;
|
||||||
|
var currentCancellationToken = _updateSource.Token;
|
||||||
|
|
||||||
ProgressBarVisibility = Visibility.Hidden;
|
ProgressBarVisibility = Visibility.Hidden;
|
||||||
_queryHasReturn = false;
|
_isQueryRunning = true;
|
||||||
var query = PluginManager.QueryInit(QueryText.Trim());
|
var query = PluginManager.QueryInit(QueryText.Trim());
|
||||||
if (query != null)
|
if (query != null)
|
||||||
{
|
{
|
||||||
// handle the exclusiveness of plugin using action keyword
|
// handle the exclusiveness of plugin using action keyword
|
||||||
|
RemoveOldQueryResults(query);
|
||||||
|
|
||||||
|
_lastQuery = query;
|
||||||
|
Task.Delay(200, currentCancellationToken).ContinueWith(_ =>
|
||||||
|
{ // start the progress bar if query takes more than 200 ms and this is the current running query and it didn't finish yet
|
||||||
|
if (currentUpdateSource == _updateSource && _isQueryRunning)
|
||||||
|
{
|
||||||
|
ProgressBarVisibility = Visibility.Visible;
|
||||||
|
}
|
||||||
|
}, currentCancellationToken);
|
||||||
|
|
||||||
|
var plugins = PluginManager.ValidPluginsForQuery(query);
|
||||||
|
Task.Run(() =>
|
||||||
|
{
|
||||||
|
// so looping will stop once it was cancelled
|
||||||
|
var parallelOptions = new ParallelOptions {CancellationToken = currentCancellationToken};
|
||||||
|
Parallel.ForEach(plugins, parallelOptions, plugin =>
|
||||||
|
{
|
||||||
|
var config = _settings.PluginSettings.Plugins[plugin.Metadata.ID];
|
||||||
|
if (!config.Disabled)
|
||||||
|
{
|
||||||
|
var results = PluginManager.QueryForPlugin(plugin, query);
|
||||||
|
UpdateResultView(results, plugin.Metadata, query);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// this should happen once after all queries are done so progress bar should continue
|
||||||
|
// until the end of all querying
|
||||||
|
_isQueryRunning = false;
|
||||||
|
if (currentUpdateSource == _updateSource)
|
||||||
|
{ // update to hidden if this is still the current query
|
||||||
|
ProgressBarVisibility = Visibility.Hidden;
|
||||||
|
}
|
||||||
|
}, currentCancellationToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Results.Clear();
|
||||||
|
Results.Visbility = Visibility.Collapsed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RemoveOldQueryResults(Query query)
|
||||||
|
{
|
||||||
string lastKeyword = _lastQuery.ActionKeyword;
|
string lastKeyword = _lastQuery.ActionKeyword;
|
||||||
string keyword = query.ActionKeyword;
|
string keyword = query.ActionKeyword;
|
||||||
if (string.IsNullOrEmpty(lastKeyword))
|
if (string.IsNullOrEmpty(lastKeyword))
|
||||||
@ -400,42 +445,6 @@ namespace Wox.ViewModel
|
|||||||
Results.RemoveResultsExcept(PluginManager.NonGlobalPlugins[keyword].Metadata);
|
Results.RemoveResultsExcept(PluginManager.NonGlobalPlugins[keyword].Metadata);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_lastQuery = query;
|
|
||||||
Task.Delay(200, updateToken).ContinueWith(_ =>
|
|
||||||
{
|
|
||||||
if (query.RawQuery == _lastQuery.RawQuery && !_queryHasReturn)
|
|
||||||
{
|
|
||||||
ProgressBarVisibility = Visibility.Visible;
|
|
||||||
}
|
|
||||||
}, updateToken);
|
|
||||||
|
|
||||||
var plugins = PluginManager.ValidPluginsForQuery(query);
|
|
||||||
Task.Run(() =>
|
|
||||||
{
|
|
||||||
var parallelOptions = new ParallelOptions {CancellationToken = updateToken}; // so looping will stop once it was cancelled
|
|
||||||
Parallel.ForEach(plugins, parallelOptions, plugin =>
|
|
||||||
{
|
|
||||||
var config = _settings.PluginSettings.Plugins[plugin.Metadata.ID];
|
|
||||||
if (!config.Disabled)
|
|
||||||
{
|
|
||||||
var results = PluginManager.QueryForPlugin(plugin, query);
|
|
||||||
UpdateResultView(results, plugin.Metadata, query);
|
|
||||||
}
|
|
||||||
});// TODO add cancel code.
|
|
||||||
|
|
||||||
// this should happen once after all queries are done so progress bar should continue
|
|
||||||
// until the end of all querying
|
|
||||||
_queryHasReturn = true;
|
|
||||||
ProgressBarVisibility = Visibility.Hidden;
|
|
||||||
}, updateToken);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Results.Clear();
|
|
||||||
Results.Visbility = Visibility.Collapsed;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -248,6 +248,10 @@ namespace Wox.ViewModel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Update the results collection with new results, try to keep identical results
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="newItems"></param>
|
||||||
public void Update(List<ResultViewModel> newItems)
|
public void Update(List<ResultViewModel> newItems)
|
||||||
{
|
{
|
||||||
int newCount = newItems.Count;
|
int newCount = newItems.Count;
|
||||||
@ -259,7 +263,7 @@ namespace Wox.ViewModel
|
|||||||
ResultViewModel oldResult = this[i];
|
ResultViewModel oldResult = this[i];
|
||||||
ResultViewModel newResult = newItems[i];
|
ResultViewModel newResult = newItems[i];
|
||||||
if (!oldResult.Equals(newResult))
|
if (!oldResult.Equals(newResult))
|
||||||
{
|
{ // result is not the same update it in the current index
|
||||||
this[i] = newResult;
|
this[i] = newResult;
|
||||||
}
|
}
|
||||||
else if (oldResult.Result.Score != newResult.Result.Score)
|
else if (oldResult.Result.Score != newResult.Result.Score)
|
||||||
|
Loading…
Reference in New Issue
Block a user