diff --git a/Wox/MainWindow.xaml.cs b/Wox/MainWindow.xaml.cs index 71204acde8..d842aa2fdb 100644 --- a/Wox/MainWindow.xaml.cs +++ b/Wox/MainWindow.xaml.cs @@ -163,7 +163,7 @@ namespace Wox o.PluginID = plugin.ID; o.OriginQuery = query; }); - UpdateResultView(results); + UpdateResultView(results, plugin, query); } public void ShowContextMenu(PluginMetadata plugin, List results) @@ -177,7 +177,7 @@ namespace Wox o.ContextMenu = null; }); pnlContextMenu.Clear(); - pnlContextMenu.AddResults(results); + pnlContextMenu.AddResults(results, plugin.ID); pnlContextMenu.Visibility = Visibility.Visible; pnlResult.Visibility = Visibility.Collapsed; } @@ -419,11 +419,12 @@ namespace Wox private void QueryContextMenu() { + var contextMenuId = "Context Menu Id"; pnlContextMenu.Clear(); var query = tbQuery.Text.ToLower(); if (string.IsNullOrEmpty(query)) { - pnlContextMenu.AddResults(CurrentContextMenus); + pnlContextMenu.AddResults(CurrentContextMenus, contextMenuId); } else { @@ -436,7 +437,7 @@ namespace Wox filterResults.Add(contextMenu); } } - pnlContextMenu.AddResults(filterResults); + pnlContextMenu.AddResults(filterResults, contextMenuId); } } @@ -445,15 +446,14 @@ namespace Wox if (_ignoreTextChange) { _ignoreTextChange = false; return; } string query = tbQuery.Text.Trim(); + toolTip.IsOpen = false; + if (IsInContextMenuMode) + { + QueryContextMenu(); + return; + } if (!string.IsNullOrEmpty(query)) { - toolTip.IsOpen = false; - if (IsInContextMenuMode) - { - QueryContextMenu(); - return; - } - Query(query); Dispatcher.DelayInvoke("ShowProgressbar", () => { @@ -738,6 +738,11 @@ namespace Wox { if (history != null) { + var historyMetadata = new PluginMetadata + { + ID = "Query history", + Name = "Query history" + }; ChangeQueryText(history.Query, true); var executeQueryHistoryTitle = GetTranslation("executeQuery"); var lastExecuteTime = GetTranslation("lastExecuteTime"); @@ -753,7 +758,7 @@ namespace Wox return false; } } - }); + }, historyMetadata); } } @@ -834,33 +839,28 @@ namespace Wox } } - private void UpdateResultView(List list) + private void UpdateResultView(List list, PluginMetadata metadata, Query originQuery) { _queryHasReturn = true; progressBar.Dispatcher.Invoke(new Action(StopProgress)); - if (list == null || list.Count == 0) return; - if (list.Count > 0) + list.ForEach(o => { - list.ForEach(o => - { - o.Score += UserSelectedRecordStorage.Instance.GetSelectedCount(o) * 5; - }); - List l = list.Where(o => o.OriginQuery != null && o.OriginQuery.RawQuery == _lastQuery.RawQuery).ToList(); - UpdateResultViewInternal(l); + o.Score += UserSelectedRecordStorage.Instance.GetSelectedCount(o) * 5; + }); + if (originQuery.RawQuery == _lastQuery.RawQuery) + { + UpdateResultViewInternal(list, metadata); } } - private void UpdateResultViewInternal(List list) + private void UpdateResultViewInternal(List list, PluginMetadata metadata) { - if (list != null && list.Count > 0) + Dispatcher.Invoke(new Action(() => { - Dispatcher.Invoke(new Action(() => - { - Stopwatch.Normal($"UI update cost for {list[0].PluginDirectory.Split('\\').Last()}", - () =>{pnlResult.AddResults(list);}); - })); - } + Stopwatch.Normal($"UI update cost for {metadata.Name}", + () => { pnlResult.AddResults(list, metadata.ID); }); + })); } private Result GetTopMostContextMenu(Result result) @@ -908,7 +908,7 @@ namespace Wox textBeforeEnterContextMenuMode = tbQuery.Text; ChangeQueryText(""); pnlContextMenu.Clear(); - pnlContextMenu.AddResults(results); + pnlContextMenu.AddResults(results, result.PluginID); CurrentContextMenus = results; pnlContextMenu.Visibility = Visibility.Visible; pnlResult.Visibility = Visibility.Collapsed; diff --git a/Wox/ResultPanel.xaml.cs b/Wox/ResultPanel.xaml.cs index f3e0148fd7..66f9a9fea9 100644 --- a/Wox/ResultPanel.xaml.cs +++ b/Wox/ResultPanel.xaml.cs @@ -55,56 +55,51 @@ namespace Wox } } - public void AddResults(List newResults) + public void AddResults(List newResults, string resultId) { - if (newResults != null && newResults.Count > 0) + var oldResults = _results.Where(r => r.PluginID == resultId).ToList(); + // intersection of A (old results) and B (new newResults) + var intersection = oldResults.Intersect(newResults).ToList(); + lock (_resultsUpdateLock) { - lock (_resultsUpdateLock) + // remove result of relative complement of B in A + foreach (var result in oldResults.Except(intersection)) { - var pluginId = newResults[0].PluginID; - var oldResults = _results.Where(r => r.PluginID == pluginId).ToList(); - // intersection of A (old results) and B (new newResults) - var intersection = oldResults.Intersect(newResults).ToList(); + _results.Remove(result); + } - // remove result of relative complement of B in A - foreach (var result in oldResults.Except(intersection)) + // update scores + foreach (var result in newResults) + { + if (IsTopMostResult(result)) { - _results.Remove(result); + result.Score = int.MaxValue; } + } - // update scores - foreach (var result in newResults) - { - if (IsTopMostResult(result)) - { - result.Score = int.MaxValue; - } - } - - // update index for result in intersection of A and B - foreach (var result in intersection) - { - int oldIndex = _results.IndexOf(result); - int oldScore = _results[oldIndex].Score; - if (result.Score != oldScore) - { - int newIndex = InsertIndexOf(result.Score); - if (newIndex != oldIndex) - { - _results.Move(oldIndex, newIndex); - } - } - } - - // insert result in relative complement of A in B - foreach (var result in newResults.Except(intersection)) + // update index for result in intersection of A and B + foreach (var result in intersection) + { + int oldIndex = _results.IndexOf(result); + int oldScore = _results[oldIndex].Score; + if (result.Score != oldScore) { int newIndex = InsertIndexOf(result.Score); - _results.Insert(newIndex, result); + if (newIndex != oldIndex) + { + _results.Move(oldIndex, newIndex); + } } - lbResults.Margin = lbResults.Items.Count > 0 ? new Thickness { Top = 8 } : new Thickness { Top = 0 }; - SelectFirst(); } + + // insert result in relative complement of A in B + foreach (var result in newResults.Except(intersection)) + { + int newIndex = InsertIndexOf(result.Score); + _results.Insert(newIndex, result); + } + lbResults.Margin = lbResults.Items.Count > 0 ? new Thickness { Top = 8 } : new Thickness { Top = 0 }; + SelectFirst(); } } diff --git a/Wox/SettingWindow.xaml.cs b/Wox/SettingWindow.xaml.cs index 09e269d56c..5b57bb8d85 100644 --- a/Wox/SettingWindow.xaml.cs +++ b/Wox/SettingWindow.xaml.cs @@ -429,7 +429,7 @@ namespace Wox IcoPath = "Images/app.png", PluginDirectory = Path.GetDirectoryName(Application.ExecutablePath) } - }); + }, "test id"); foreach (string theme in ThemeManager.Theme.LoadAvailableThemes()) {