mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-15 03:59:15 +08:00
updated top most record
This commit is contained in:
parent
406cc71f96
commit
c90dd0e818
@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Wox.Infrastructure.Storage
|
namespace Wox.Infrastructure.Storage
|
||||||
{
|
{
|
||||||
class WoxJsonStorage<T> : JsonStrorage<T> where T : new()
|
public class WoxJsonStorage<T> : JsonStrorage<T> where T : new()
|
||||||
{
|
{
|
||||||
public WoxJsonStorage()
|
public WoxJsonStorage()
|
||||||
{
|
{
|
||||||
|
@ -108,7 +108,7 @@ namespace Wox.Plugin
|
|||||||
public object ContextData { get; set; }
|
public object ContextData { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Plugin ID that generate this result
|
/// Plugin ID that generated this result
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string PluginID { get; internal set; }
|
public string PluginID { get; internal set; }
|
||||||
}
|
}
|
||||||
|
@ -1,47 +1,52 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using Wox.Infrastructure.Storage;
|
using Wox.Infrastructure.Storage;
|
||||||
using Wox.Plugin;
|
using Wox.Plugin;
|
||||||
|
|
||||||
namespace Wox.Storage
|
namespace Wox.Storage
|
||||||
{
|
{
|
||||||
|
// todo this class is not thread safe.... but used from multiple threads.
|
||||||
public class TopMostRecord
|
public class TopMostRecord
|
||||||
{
|
{
|
||||||
public Dictionary<string, Record> records = new Dictionary<string, Record>();
|
[JsonProperty]
|
||||||
|
private Dictionary<string, Record> records = new Dictionary<string, Record>();
|
||||||
|
|
||||||
internal bool IsTopMost(Result result)
|
internal bool IsTopMost(Result result)
|
||||||
{
|
{
|
||||||
|
if (records.Count == 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// since this dictionary should be very small (or empty) going over it should be pretty fast.
|
||||||
return records.Any(o => o.Value.Title == result.Title
|
return records.Any(o => o.Value.Title == result.Title
|
||||||
&& o.Value.SubTitle == result.SubTitle
|
&& o.Value.SubTitle == result.SubTitle
|
||||||
&& o.Value.PluginID == result.PluginID
|
&& o.Value.PluginID == result.PluginID
|
||||||
&& o.Key == result.OriginQuery.RawQuery);
|
&& o.Key == result.OriginQuery.RawQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void Remove(Result result)
|
internal void Remove(Result result)
|
||||||
{
|
{
|
||||||
if (records.ContainsKey(result.OriginQuery.RawQuery))
|
records.Remove(result.OriginQuery.RawQuery);
|
||||||
{
|
|
||||||
records.Remove(result.OriginQuery.RawQuery);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void AddOrUpdate(Result result)
|
internal void AddOrUpdate(Result result)
|
||||||
{
|
{
|
||||||
if (records.ContainsKey(result.OriginQuery.RawQuery))
|
var record = new Record
|
||||||
{
|
{
|
||||||
records[result.OriginQuery.RawQuery].Title = result.Title;
|
PluginID = result.PluginID,
|
||||||
records[result.OriginQuery.RawQuery].SubTitle = result.SubTitle;
|
Title = result.Title,
|
||||||
records[result.OriginQuery.RawQuery].PluginID = result.PluginID;
|
SubTitle = result.SubTitle
|
||||||
}
|
};
|
||||||
else
|
records[result.OriginQuery.RawQuery] = record;
|
||||||
{
|
|
||||||
records.Add(result.OriginQuery.RawQuery, new Record
|
}
|
||||||
{
|
|
||||||
PluginID = result.PluginID,
|
public void Load(Dictionary<string, Record> dictionary)
|
||||||
Title = result.Title,
|
{
|
||||||
SubTitle = result.SubTitle
|
records = dictionary;
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user