diff --git a/Wox/Images/topmost.png b/Wox/Images/topmost.png new file mode 100644 index 0000000000..50b68e6e20 Binary files /dev/null and b/Wox/Images/topmost.png differ diff --git a/Wox/MainWindow.xaml.cs b/Wox/MainWindow.xaml.cs index ac5469e334..3c710ccfd5 100644 --- a/Wox/MainWindow.xaml.cs +++ b/Wox/MainWindow.xaml.cs @@ -5,6 +5,7 @@ using System.Diagnostics; using System.Drawing; using System.Linq; using System.Net; +using System.Reflection; using System.Threading; using System.Windows; using System.Windows.Controls; @@ -35,6 +36,7 @@ using MessageBox = System.Windows.MessageBox; using ToolTip = System.Windows.Controls.ToolTip; using Wox.Infrastructure.Logger; using IDataObject = System.Windows.IDataObject; +using System.IO; namespace Wox { @@ -754,6 +756,11 @@ namespace Wox list.ForEach(o => { o.Score += UserSelectedRecordStorage.Instance.GetSelectedCount(o) * 5; + if (o.ContextMenu == null) + { + o.ContextMenu = new List(); + } + HanleTopMost(o); }); List l = list.Where(o => o.OriginQuery != null && o.OriginQuery.RawQuery == lastQuery).ToList(); Dispatcher.Invoke(new Action(() => @@ -763,6 +770,36 @@ namespace Wox } } + private void HanleTopMost(Result result) + { + if (TopMostRecordStorage.Instance.IsTopMost(result)) + { + result.ContextMenu.Add(new Result("Remove top most in this query", "Images\\topmost.png") + { + PluginDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), + Action = _ => + { + TopMostRecordStorage.Instance.Remove(result); + ShowMsg("Succeed", "", ""); + return false; + } + }); + } + else + { + result.ContextMenu.Add(new Result("Set as top most in this query", "Images\\topmost.png") + { + PluginDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), + Action = _ => + { + TopMostRecordStorage.Instance.Add(result); + ShowMsg("Succeed", "", ""); + return false; + } + }); + } + } + private void ShowContextMenuFromResult(Result result) { if (result.ContextMenu != null && result.ContextMenu.Count > 0) diff --git a/Wox/ResultPanel.xaml.cs b/Wox/ResultPanel.xaml.cs index 2a1d217175..341c08e127 100644 --- a/Wox/ResultPanel.xaml.cs +++ b/Wox/ResultPanel.xaml.cs @@ -8,6 +8,7 @@ using System.Windows.Input; using System.Windows.Media; using Wox.Helper; using Wox.Plugin; +using Wox.Storage; using UserControl = System.Windows.Controls.UserControl; namespace Wox @@ -34,7 +35,6 @@ namespace Wox public void AddResults(List results) { - if (Dirty) { Dirty = false; @@ -42,13 +42,30 @@ namespace Wox } foreach (var result in results) { - int position = GetInsertLocation(result.Score); + int position = 0; + if (IsTopMostResult(result)) + { + result.Score = int.MaxValue; + } + else + { + if (result.Score >= int.MaxValue) + { + result.Score = int.MaxValue - 1; + } + position = GetInsertLocation(result.Score); + } lbResults.Items.Insert(position, result); } lbResults.Margin = lbResults.Items.Count > 0 ? new Thickness { Top = 8 } : new Thickness { Top = 0 }; SelectFirst(); } + private bool IsTopMostResult(Result result) + { + return TopMostRecordStorage.Instance.IsTopMost(result); + } + private int GetInsertLocation(int currentScore) { int location = lbResults.Items.Count; diff --git a/Wox/Storage/TopMostRecordStorage.cs b/Wox/Storage/TopMostRecordStorage.cs new file mode 100644 index 0000000000..87e8feb86b --- /dev/null +++ b/Wox/Storage/TopMostRecordStorage.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Text; +using Wox.Infrastructure.Storage; + +namespace Wox.Storage +{ + public class TopMostRecordStorage : JsonStrorage + { + public Dictionary records = new Dictionary(); + + protected override string ConfigFolder + { + get { return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Config"); } + } + + protected override string ConfigName + { + get { return "TopMostRecords"; } + } + + internal bool IsTopMost(Plugin.Result result) + { + return records.Any(o => o.Value.Title == result.Title + && o.Value.SubTitle == result.SubTitle + && o.Value.PluginID == result.PluginID); + } + + internal void Remove(Plugin.Result result) + { + if (records.ContainsKey(result.OriginQuery.RawQuery)) + { + records.Remove(result.OriginQuery.RawQuery); + Save(); + } + } + + internal void Add(Plugin.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 + { + records.Add(result.OriginQuery.RawQuery, new TopMostRecord() + { + PluginID = result.PluginID, + Title = result.Title, + SubTitle = result.SubTitle, + }); + } + + Save(); + } + } + + + public class TopMostRecord + { + public string Title { get; set; } + public string SubTitle { get; set; } + public string PluginID { get; set; } + } +} diff --git a/Wox/Wox.csproj b/Wox/Wox.csproj index 5102805cd0..c290bdc4a2 100644 --- a/Wox/Wox.csproj +++ b/Wox/Wox.csproj @@ -115,6 +115,7 @@ + WoxUpdate.xaml @@ -179,6 +180,9 @@ PreserveNewest + + PreserveNewest + Designer MSBuild:Compile