Fix issues in ControlPanel plugin.

This commit is contained in:
qianlifeng
2014-07-18 14:09:52 +08:00
parent 3cfa4f9cb7
commit 7be02731ee
4 changed files with 315 additions and 37 deletions

View File

@@ -1,12 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Wox.Infrastructure;
using Wox.Infrastructure.Storage.UserSettings;
using WindowsControlPanelItems;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Wox.Infrastructure;
namespace Wox.Plugin.SystemPlugins.ControlPanel
{
@@ -42,10 +39,16 @@ namespace Wox.Plugin.SystemPlugins.ControlPanel
protected override void InitInternal(PluginInitContext context)
{
this.context = context;
controlPanelItems = WindowsControlPanelItems.List.Create(48);
controlPanelItems = ControlPanelList.Create(48);
iconFolder = @"Images\ControlPanelIcons\";
fileType = ".bmp";
if (!Directory.Exists(iconFolder))
{
Directory.CreateDirectory(iconFolder);
}
foreach (ControlPanelItem item in controlPanelItems)
{
if (!File.Exists(iconFolder + item.ApplicationName + fileType))
@@ -61,37 +64,17 @@ namespace Wox.Plugin.SystemPlugins.ControlPanel
string myQuery = query.RawQuery.Trim();
List<Result> results = new List<Result>();
List<Result> filteredResults = new List<Result>();
foreach (var item in controlPanelItems)
{
if (item.LocalizedString.IndexOf(myQuery, StringComparison.OrdinalIgnoreCase) >= 0)
{
results.Insert(0, new Result()
{
Title = item.LocalizedString,
SubTitle = item.InfoTip,
IcoPath = "Images\\ControlPanelIcons\\" + item.ApplicationName + fileType,
Action = e =>
{
try
{
Process.Start(item.ExecutablePath);
}
catch (Exception)
{
//Silently Fail for now..
}
return true;
}
});
}
else if (item.InfoTip.IndexOf(myQuery, StringComparison.OrdinalIgnoreCase) >= 0)
var fuzzyMather = FuzzyMatcher.Create(myQuery);
if (MatchProgram(item, fuzzyMather))
{
results.Add(new Result()
{
Title = item.LocalizedString,
SubTitle = item.InfoTip,
Score = item.Score,
IcoPath = "Images\\ControlPanelIcons\\" + item.ApplicationName + fileType,
Action = e =>
{
@@ -108,12 +91,18 @@ namespace Wox.Plugin.SystemPlugins.ControlPanel
});
}
}
for (int i = 0; i < 2 && i < results.Count; i++)
{
filteredResults.Add(results[i]);
}
return filteredResults;
return results.OrderByDescending(o => o.Score).Take(5).ToList();
}
private bool MatchProgram(ControlPanelItem item, FuzzyMatcher matcher)
{
if (item.LocalizedString != null && (item.Score = matcher.Evaluate(item.LocalizedString).Score) > 0) return true;
if (item.InfoTip != null && (item.Score = matcher.Evaluate(item.InfoTip).Score) > 0) return true;
if (item.LocalizedString != null && (item.Score = matcher.Evaluate(item.LocalizedString.Unidecode()).Score) > 0) return true;
return false;
}
}
}