Skip to content

Commit

Permalink
Merge pull request microsoft#86 from theClueless/smallFixes
Browse files Browse the repository at this point in the history
Smallfixes
  • Loading branch information
jjw24 authored Dec 8, 2019
2 parents b47e7f0 + a2d6858 commit 982cac3
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 35 deletions.
4 changes: 2 additions & 2 deletions Wox.Infrastructure/Storage/WoxJsonStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Wox.Infrastructure.Storage
{
class WoxJsonStorage<T> : JsonStrorage<T> where T : new()
public class WoxJsonStorage<T> : JsonStrorage<T> where T : new()
{
public WoxJsonStorage()
{
Expand All @@ -18,4 +18,4 @@ public WoxJsonStorage()
FilePath = Path.Combine(directoryPath, $"{filename}{FileSuffix}");
}
}
}
}
2 changes: 1 addition & 1 deletion Wox.Plugin/Result.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public Result() { }
public object ContextData { get; set; }

/// <summary>
/// Plugin ID that generate this result
/// Plugin ID that generated this result
/// </summary>
public string PluginID { get; internal set; }
}
Expand Down
49 changes: 26 additions & 23 deletions Wox/Storage/TopMostRecord.cs
Original file line number Diff line number Diff line change
@@ -1,47 +1,50 @@
using System.Collections.Generic;
using System.Linq;
using Wox.Infrastructure.Storage;
using Newtonsoft.Json;
using Wox.Plugin;

namespace Wox.Storage
{
// todo this class is not thread safe.... but used from multiple threads.
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)
{
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
&& o.Value.SubTitle == result.SubTitle
&& o.Value.PluginID == result.PluginID
&& o.Key == result.OriginQuery.RawQuery);
&& o.Value.SubTitle == result.SubTitle
&& o.Value.PluginID == result.PluginID
&& o.Key == result.OriginQuery.RawQuery);
}

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)
{
if (records.ContainsKey(result.OriginQuery.RawQuery))
{
records[result.OriginQuery.RawQuery].Title = result.Title;
records[result.OriginQuery.RawQuery].SubTitle = result.SubTitle;
records[result.OriginQuery.RawQuery].PluginID = result.PluginID;
}
else
var record = new Record
{
records.Add(result.OriginQuery.RawQuery, new Record
{
PluginID = result.PluginID,
Title = result.Title,
SubTitle = result.SubTitle
});
}
PluginID = result.PluginID,
Title = result.Title,
SubTitle = result.SubTitle
};
records[result.OriginQuery.RawQuery] = record;

}

public void Load(Dictionary<string, Record> dictionary)
{
records = dictionary;
}
}

Expand Down
12 changes: 7 additions & 5 deletions Wox/Storage/UserSelectedRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,23 @@ public class UserSelectedRecord

public void Add(Result result)
{
if (records.ContainsKey(result.ToString()))
var key = result.ToString();
if (records.TryGetValue(key, out int value))
{
records[result.ToString()] += 1;
records[key] = value + 1;
}
else
{
records.Add(result.ToString(), 1);
records.Add(key, 1);

}
}

public int GetSelectedCount(Result result)
{
if (records.ContainsKey(result.ToString()))
if (records.TryGetValue(result.ToString(), out int value))
{
return records[result.ToString()];
return value;
}
return 0;
}
Expand Down
8 changes: 5 additions & 3 deletions Wox/ViewModel/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,11 @@ private void QueryResults()
UpdateResultView(results, plugin.Metadata, query);
}
});

// this should happen once after all queries are done so progress bar should continue
// until the end of all querying
_queryHasReturn = true;
ProgressBarVisibility = Visibility.Hidden;
}, _updateToken);
}
}
Expand Down Expand Up @@ -627,9 +632,6 @@ public void Save()
/// </summary>
public void UpdateResultView(List<Result> list, PluginMetadata metadata, Query originQuery)
{
_queryHasReturn = true;
ProgressBarVisibility = Visibility.Hidden;

foreach (var result in list)
{
if (_topMostRecord.IsTopMost(result))
Expand Down
1 change: 0 additions & 1 deletion Wox/ViewModel/ResultsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ private List<ResultViewModel> NewResults(List<Result> newRawResults, string resu
// Find the same results in A (old results) and B (new newResults)
var sameResults = oldResults
.Where(t1 => newResults.Any(x => x.Result.Equals(t1.Result)))
.Select(t1 => t1)
.ToList();

// remove result of relative complement of B in A
Expand Down

0 comments on commit 982cac3

Please sign in to comment.