From e3cdfe27d18a82ab5195f3e5b11344f27afa59f1 Mon Sep 17 00:00:00 2001 From: bao-qian Date: Sun, 8 Nov 2015 02:50:33 +0000 Subject: [PATCH] Fix query history for the new result panel --- Wox/MainWindow.xaml.cs | 14 ++++++-------- Wox/ResultPanel.xaml.cs | 8 ++++---- Wox/Storage/QueryHistoryStorage.cs | 6 +++++- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/Wox/MainWindow.xaml.cs b/Wox/MainWindow.xaml.cs index d842aa2fdb..97cb97d162 100644 --- a/Wox/MainWindow.xaml.cs +++ b/Wox/MainWindow.xaml.cs @@ -473,6 +473,7 @@ namespace Wox private void ResetQueryHistoryIndex() { + pnlResult.RemoveResultsFor(QueryHistoryStorage.MetaData); QueryHistoryStorage.Instance.Reset(); } private void Query(string text) @@ -487,18 +488,18 @@ namespace Wox { if (!string.IsNullOrEmpty(keyword)) { - pnlResult.RemoveResultsExcept(PluginManager.NonGlobalPlugins[keyword]); + pnlResult.RemoveResultsExcept(PluginManager.NonGlobalPlugins[keyword].Metadata); } } else { if (string.IsNullOrEmpty(keyword)) { - pnlResult.RemoveResultsFor(PluginManager.NonGlobalPlugins[lastKeyword]); + pnlResult.RemoveResultsFor(PluginManager.NonGlobalPlugins[lastKeyword].Metadata); } else if (lastKeyword != keyword) { - pnlResult.RemoveResultsExcept(PluginManager.NonGlobalPlugins[keyword]); + pnlResult.RemoveResultsExcept(PluginManager.NonGlobalPlugins[keyword].Metadata); } } _lastQuery = query; @@ -738,14 +739,11 @@ namespace Wox { if (history != null) { - var historyMetadata = new PluginMetadata - { - ID = "Query history", - Name = "Query history" - }; + var historyMetadata = QueryHistoryStorage.MetaData; ChangeQueryText(history.Query, true); var executeQueryHistoryTitle = GetTranslation("executeQuery"); var lastExecuteTime = GetTranslation("lastExecuteTime"); + pnlResult.RemoveResultsExcept(historyMetadata); UpdateResultViewInternal(new List() { new Result(){ diff --git a/Wox/ResultPanel.xaml.cs b/Wox/ResultPanel.xaml.cs index 24d5385c3b..121ee9b852 100644 --- a/Wox/ResultPanel.xaml.cs +++ b/Wox/ResultPanel.xaml.cs @@ -40,19 +40,19 @@ namespace Wox public int MaxResultsToShow { get { return UserSettingStorage.Instance.MaxResultsToShow * 50; } } - internal void RemoveResultsFor(PluginPair plugin) + internal void RemoveResultsFor(PluginMetadata metadata) { lock (_resultsUpdateLock) { - _results.RemoveAll(r => r.PluginID == plugin.Metadata.ID); + _results.RemoveAll(r => r.PluginID == metadata.ID); } } - internal void RemoveResultsExcept(PluginPair plugin) + internal void RemoveResultsExcept(PluginMetadata metadata) { lock (_resultsUpdateLock) { - _results.RemoveAll(r => r.PluginID != plugin.Metadata.ID); + _results.RemoveAll(r => r.PluginID != metadata.ID); } } diff --git a/Wox/Storage/QueryHistoryStorage.cs b/Wox/Storage/QueryHistoryStorage.cs index d39ebaad14..81ccc353ae 100644 --- a/Wox/Storage/QueryHistoryStorage.cs +++ b/Wox/Storage/QueryHistoryStorage.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Reflection; using Newtonsoft.Json; using Wox.Infrastructure.Storage; +using Wox.Plugin; namespace Wox.Storage { @@ -16,6 +17,9 @@ namespace Wox.Storage private int MaxHistory = 300; private int cursor = 0; + public static PluginMetadata MetaData { get; } = new PluginMetadata + { ID = "Query history", Name = "Query history" }; + protected override string ConfigFolder { get { return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Config"); } @@ -77,7 +81,7 @@ namespace Wox.Storage return History.OrderByDescending(o => o.ExecutedDateTime).ToList(); } } - + public class HistoryItem { public string Query { get; set; }