From 3dfccea5229dc9943cca16760ce9b5ed011860c7 Mon Sep 17 00:00:00 2001 From: AT <14300910+theClueless@users.noreply.github.com> Date: Sat, 14 Dec 2019 00:07:27 +0200 Subject: [PATCH] Revert "results and query update fixes" This reverts commit ced0faf9164a11012b5f3276d3acf3416986589c. --- Wox.Infrastructure/Image/ImageLoader.cs | 2 +- Wox/MainWindow.xaml | 2 +- Wox/ViewModel/MainViewModel.cs | 77 +++++++++++-------------- Wox/ViewModel/ResultsViewModel.cs | 6 +- 4 files changed, 37 insertions(+), 50 deletions(-) diff --git a/Wox.Infrastructure/Image/ImageLoader.cs b/Wox.Infrastructure/Image/ImageLoader.cs index 184f78cad3..3498e4f3b2 100644 --- a/Wox.Infrastructure/Image/ImageLoader.cs +++ b/Wox.Infrastructure/Image/ImageLoader.cs @@ -133,7 +133,7 @@ namespace Wox.Infrastructure.Image } 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]; ImageCache[path] = image; diff --git a/Wox/MainWindow.xaml b/Wox/MainWindow.xaml index cc50e76dce..7dfe8cd1e9 100644 --- a/Wox/MainWindow.xaml +++ b/Wox/MainWindow.xaml @@ -56,7 +56,7 @@ - { // 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) { diff --git a/Wox/ViewModel/ResultsViewModel.cs b/Wox/ViewModel/ResultsViewModel.cs index 45eb4bec2c..e36ddc94d3 100644 --- a/Wox/ViewModel/ResultsViewModel.cs +++ b/Wox/ViewModel/ResultsViewModel.cs @@ -248,10 +248,6 @@ namespace Wox.ViewModel } } - /// - /// Update the results collection with new results, try to keep identical results - /// - /// public void Update(List 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)