Add top most function.

This commit is contained in:
qianlifeng 2015-02-05 23:29:41 +08:00
parent ad11ca0a87
commit 02e22e5781
5 changed files with 130 additions and 2 deletions

BIN
Wox/Images/topmost.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

@ -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<Result>();
}
HanleTopMost(o);
});
List<Result> 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)

View File

@ -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<Result> 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;

View File

@ -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<TopMostRecordStorage>
{
public Dictionary<string, TopMostRecord> records = new Dictionary<string, TopMostRecord>();
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; }
}
}

View File

@ -115,6 +115,7 @@
<Compile Include="Converters\StringEmptyConverter.cs" />
<Compile Include="Converters\StringNullOrEmptyToVisibilityConverter.cs" />
<Compile Include="ImageLoader\ImageCacheStroage.cs" />
<Compile Include="Storage\TopMostRecordStorage.cs" />
<Compile Include="Storage\UserSelectedRecordStorage.cs" />
<Compile Include="WoxUpdate.xaml.cs">
<DependentUpon>WoxUpdate.xaml</DependentUpon>
@ -179,6 +180,9 @@
<Resource Include="Images\update.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
<None Include="Images\topmost.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<Content Include="Languages\en.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>