PowerToys/Wox.Plugin.SystemPlugins/ControlPanel/ControlPanel.cs

120 lines
3.9 KiB
C#
Raw Normal View History

2014-07-17 23:14:58 +08:00
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;
namespace Wox.Plugin.SystemPlugins.ControlPanel
{
public class ControlPanel : BaseSystemPlugin
{
#region Properties
private PluginInitContext context;
public override string Description
{
get
{
return "Search within the Control Panel.";
}
}
public override string ID
{
get { return "209621585B9B4D81813913C507C058C6"; }
}
public override string Name { get { return "Control Panel"; } }
public override string IcoPath { get { return @"Images\ControlPanel.png"; } }
private List<ControlPanelItem> controlPanelItems;
private string iconFolder;
private string fileType;
2014-07-17 23:14:58 +08:00
#endregion Properties
protected override void InitInternal(PluginInitContext context)
{
this.context = context;
controlPanelItems = WindowsControlPanelItems.List.Create(48);
iconFolder = @"Images\ControlPanelIcons\";
fileType = ".bmp";
2014-07-17 23:14:58 +08:00
foreach (ControlPanelItem item in controlPanelItems)
{
if (!File.Exists(iconFolder + item.ApplicationName + fileType))
2014-07-17 23:14:58 +08:00
{
item.Icon.ToBitmap().Save(iconFolder + item.ApplicationName + fileType);
2014-07-17 23:14:58 +08:00
}
}
}
protected override List<Result> QueryInternal(Query query)
{
2014-07-17 23:36:19 +08:00
if (query.RawQuery.EndsWith(" ") || query.RawQuery.Length <= 1) return new List<Result>();
string myQuery = query.RawQuery.Trim();
2014-07-17 23:14:58 +08:00
List<Result> results = new List<Result>();
2014-07-17 23:47:58 +08:00
List<Result> filteredResults = new List<Result>();
2014-07-17 23:14:58 +08:00
foreach (var item in controlPanelItems)
{
if (item.LocalizedString.IndexOf(myQuery, StringComparison.OrdinalIgnoreCase) >= 0)
2014-07-17 23:14:58 +08:00
{
results.Insert(0, new Result()
2014-07-17 23:14:58 +08:00
{
Title = item.LocalizedString,
SubTitle = item.InfoTip,
IcoPath = "Images\\ControlPanelIcons\\" + item.ApplicationName + fileType,
Action = e =>
2014-07-17 23:14:58 +08:00
{
try
{
Process.Start(item.ExecutablePath);
}
catch (Exception)
2014-07-17 23:14:58 +08:00
{
//Silently Fail for now..
2014-07-17 23:14:58 +08:00
}
return true;
}
});
}
else if (item.InfoTip.IndexOf(myQuery, StringComparison.OrdinalIgnoreCase) >= 0)
{
results.Add(new Result()
2014-07-17 23:43:29 +08:00
{
Title = item.LocalizedString,
SubTitle = item.InfoTip,
IcoPath = "Images\\ControlPanelIcons\\" + item.ApplicationName + fileType,
Action = e =>
2014-07-17 23:43:29 +08:00
{
try
{
Process.Start(item.ExecutablePath);
}
catch (Exception)
2014-07-17 23:14:58 +08:00
{
//Silently Fail for now..
2014-07-17 23:14:58 +08:00
}
return true;
}
});
2014-07-17 23:14:58 +08:00
}
}
2014-07-17 23:47:58 +08:00
for (int i = 0; i < 2 && i < results.Count; i++)
{
filteredResults.Add(results[i]);
}
return filteredResults;
2014-07-17 23:14:58 +08:00
}
}
}