Fix query history for the new result panel

This commit is contained in:
bao-qian 2015-11-08 02:50:33 +00:00
parent d946e18fa2
commit e3cdfe27d1
3 changed files with 15 additions and 13 deletions

View File

@ -473,6 +473,7 @@ namespace Wox
private void ResetQueryHistoryIndex() private void ResetQueryHistoryIndex()
{ {
pnlResult.RemoveResultsFor(QueryHistoryStorage.MetaData);
QueryHistoryStorage.Instance.Reset(); QueryHistoryStorage.Instance.Reset();
} }
private void Query(string text) private void Query(string text)
@ -487,18 +488,18 @@ namespace Wox
{ {
if (!string.IsNullOrEmpty(keyword)) if (!string.IsNullOrEmpty(keyword))
{ {
pnlResult.RemoveResultsExcept(PluginManager.NonGlobalPlugins[keyword]); pnlResult.RemoveResultsExcept(PluginManager.NonGlobalPlugins[keyword].Metadata);
} }
} }
else else
{ {
if (string.IsNullOrEmpty(keyword)) if (string.IsNullOrEmpty(keyword))
{ {
pnlResult.RemoveResultsFor(PluginManager.NonGlobalPlugins[lastKeyword]); pnlResult.RemoveResultsFor(PluginManager.NonGlobalPlugins[lastKeyword].Metadata);
} }
else if (lastKeyword != keyword) else if (lastKeyword != keyword)
{ {
pnlResult.RemoveResultsExcept(PluginManager.NonGlobalPlugins[keyword]); pnlResult.RemoveResultsExcept(PluginManager.NonGlobalPlugins[keyword].Metadata);
} }
} }
_lastQuery = query; _lastQuery = query;
@ -738,14 +739,11 @@ namespace Wox
{ {
if (history != null) if (history != null)
{ {
var historyMetadata = new PluginMetadata var historyMetadata = QueryHistoryStorage.MetaData;
{
ID = "Query history",
Name = "Query history"
};
ChangeQueryText(history.Query, true); ChangeQueryText(history.Query, true);
var executeQueryHistoryTitle = GetTranslation("executeQuery"); var executeQueryHistoryTitle = GetTranslation("executeQuery");
var lastExecuteTime = GetTranslation("lastExecuteTime"); var lastExecuteTime = GetTranslation("lastExecuteTime");
pnlResult.RemoveResultsExcept(historyMetadata);
UpdateResultViewInternal(new List<Result>() UpdateResultViewInternal(new List<Result>()
{ {
new Result(){ new Result(){

View File

@ -40,19 +40,19 @@ namespace Wox
public int MaxResultsToShow { get { return UserSettingStorage.Instance.MaxResultsToShow * 50; } } public int MaxResultsToShow { get { return UserSettingStorage.Instance.MaxResultsToShow * 50; } }
internal void RemoveResultsFor(PluginPair plugin) internal void RemoveResultsFor(PluginMetadata metadata)
{ {
lock (_resultsUpdateLock) 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) lock (_resultsUpdateLock)
{ {
_results.RemoveAll(r => r.PluginID != plugin.Metadata.ID); _results.RemoveAll(r => r.PluginID != metadata.ID);
} }
} }

View File

@ -5,6 +5,7 @@ using System.Linq;
using System.Reflection; using System.Reflection;
using Newtonsoft.Json; using Newtonsoft.Json;
using Wox.Infrastructure.Storage; using Wox.Infrastructure.Storage;
using Wox.Plugin;
namespace Wox.Storage namespace Wox.Storage
{ {
@ -16,6 +17,9 @@ namespace Wox.Storage
private int MaxHistory = 300; private int MaxHistory = 300;
private int cursor = 0; private int cursor = 0;
public static PluginMetadata MetaData { get; } = new PluginMetadata
{ ID = "Query history", Name = "Query history" };
protected override string ConfigFolder protected override string ConfigFolder
{ {
get { return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Config"); } get { return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Config"); }
@ -77,7 +81,7 @@ namespace Wox.Storage
return History.OrderByDescending(o => o.ExecutedDateTime).ToList(); return History.OrderByDescending(o => o.ExecutedDateTime).ToList();
} }
} }
public class HistoryItem public class HistoryItem
{ {
public string Query { get; set; } public string Query { get; set; }