Revert "results and query update fixes"

This reverts commit ced0faf916.
This commit is contained in:
AT
2019-12-14 00:07:27 +02:00
parent ced0faf916
commit 3dfccea522
4 changed files with 37 additions and 50 deletions

View File

@@ -13,6 +13,7 @@ using Wox.Core.Resource;
using Wox.Helper;
using Wox.Infrastructure;
using Wox.Infrastructure.Hotkey;
using Wox.Infrastructure.Image;
using Wox.Infrastructure.Storage;
using Wox.Infrastructure.UserSettings;
using Wox.Plugin;
@@ -24,7 +25,7 @@ namespace Wox.ViewModel
{
#region Private Fields
private bool _isQueryRunning;
private bool _queryHasReturn;
private Query _lastQuery;
private string _queryTextBeforeLeaveResults;
@@ -370,32 +371,49 @@ namespace Wox.ViewModel
if (!string.IsNullOrEmpty(QueryText))
{
_updateSource?.Cancel();
var currentUpdateSource = new CancellationTokenSource();
_updateSource = currentUpdateSource;
var currentCancellationToken = _updateSource.Token;
_updateSource = new CancellationTokenSource();
var updateToken = _updateSource.Token;
ProgressBarVisibility = Visibility.Hidden;
_isQueryRunning = true;
_queryHasReturn = false;
var query = PluginManager.QueryInit(QueryText.Trim());
if (query != null)
{
// handle the exclusiveness of plugin using action keyword
RemoveOldQueryResults(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);
}
}
_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)
Task.Delay(200, updateToken).ContinueWith(_ =>
{
if (query.RawQuery == _lastQuery.RawQuery && !_queryHasReturn)
{
ProgressBarVisibility = Visibility.Visible;
}
}, currentCancellationToken);
}, updateToken);
var plugins = PluginManager.ValidPluginsForQuery(query);
Task.Run(() =>
{
// so looping will stop once it was cancelled
var parallelOptions = new ParallelOptions {CancellationToken = currentCancellationToken};
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];
@@ -404,16 +422,13 @@ namespace Wox.ViewModel
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
_isQueryRunning = false;
if (currentUpdateSource == _updateSource)
{ // update to hidden if this is still the current query
ProgressBarVisibility = Visibility.Hidden;
}
}, currentCancellationToken);
_queryHasReturn = true;
ProgressBarVisibility = Visibility.Hidden;
}, updateToken);
}
}
else
@@ -423,30 +438,6 @@ namespace Wox.ViewModel
}
}
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 Result ContextMenuTopMost(Result result)
{

View File

@@ -248,10 +248,6 @@ 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)
{
int newCount = newItems.Count;
@@ -263,7 +259,7 @@ namespace Wox.ViewModel
ResultViewModel oldResult = this[i];
ResultViewModel newResult = newItems[i];
if (!oldResult.Equals(newResult))
{ // result is not the same update it in the current index
{
this[i] = newResult;
}
else if (oldResult.Result.Score != newResult.Result.Score)