From 02e22e5781c7337955d63763e2c87265cbeb7c85 Mon Sep 17 00:00:00 2001 From: qianlifeng Date: Thu, 5 Feb 2015 23:29:41 +0800 Subject: [PATCH] Add top most function. --- Wox/Images/topmost.png | Bin 0 -> 4304 bytes Wox/MainWindow.xaml.cs | 37 +++++++++++++++ Wox/ResultPanel.xaml.cs | 21 ++++++++- Wox/Storage/TopMostRecordStorage.cs | 70 ++++++++++++++++++++++++++++ Wox/Wox.csproj | 4 ++ 5 files changed, 130 insertions(+), 2 deletions(-) create mode 100644 Wox/Images/topmost.png create mode 100644 Wox/Storage/TopMostRecordStorage.cs diff --git a/Wox/Images/topmost.png b/Wox/Images/topmost.png new file mode 100644 index 0000000000000000000000000000000000000000..50b68e6e2076c2b9f85fa562ff5340b9901c34a5 GIT binary patch literal 4304 zcmV;>5HIhEP)KLZ*U+IBfRsybQWXdwQbLP>6pAqfylh#{fb6;Z(vMMVS~$e@S=j*ftg6;Uhf59&ghTmgWD0l;*T zI709Y^p6lP1rIRMx#05C~cW=H_Aw*bJ-5DT&Z2n+x)QHX^p z00esgV8|mQcmRZ%02D^@S3L16t`O%c004NIvOKvYIYoh62rY33S640`D9%Y2D-rV&neh&#Q1i z007~1e$oCcFS8neI|hJl{-P!B1ZZ9hpmq0)X0i`JwE&>$+E?>%_LC6RbVIkUx0b+_+BaR3cnT7Zv!AJxW zizFb)h!jyGOOZ85F;a?DAXP{m@;!0_IfqH8(HlgRxt7s3}k3K`kFu>>-2Q$QMFfPW!La{h336o>X zu_CMttHv6zR;&ZNiS=X8v3CR#fknUxHUxJ0uoBa_M6WNWeqIg~6QE69c9o#eyhGvpiOA@W-aonk<7r1(?fC{oI5N*U!4 zfg=2N-7=cNnjjOr{yriy6mMFgG#l znCF=fnQv8CDz++o6_Lscl}eQ+l^ZHARH>?_s@|##Rr6KLRFA1%Q+=*RRWnoLsR`7U zt5vFIcfW3@?wFpwUVxrVZ>QdQz32KIeJ}k~{cZZE^+ya? z2D1z#2HOnI7(B%_ac?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iwjs;8!=`hPt$JzxBwRKtv80RX7NM!Ctz=O^o%b+ly58X`v5Gx@srlPS*AHO zHtsNV{&|o9Jxac0y(8eFJeB1)S-pM+f80Bf~w<$Kp+Q@^*y zLH-L5SSM&3ibP$ANJp1;P!x#8tSr6%%hK9%H|C)g=|bBnNwQwc#DUkEsNZhW_CObObVLuFTBI!=M1nXqGbh>e yz2YbxrNBT;K-DK { 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