PowerToys/WinAlfred/PluginLoader/Plugins.cs

49 lines
1.5 KiB
C#
Raw Normal View History

2014-01-03 18:16:05 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
2014-01-03 23:52:36 +08:00
using System.Threading;
2014-01-03 18:16:05 +08:00
using WinAlfred.Plugin;
namespace WinAlfred.PluginLoader
{
public static class Plugins
{
private static List<PluginPair> plugins = new List<PluginPair>();
2014-01-03 23:52:36 +08:00
public static void Init(MainWindow window)
2014-01-03 18:16:05 +08:00
{
plugins.Clear();
plugins.AddRange(new PythonPluginLoader().LoadPlugin());
plugins.AddRange(new CSharpPluginLoader().LoadPlugin());
2014-01-03 23:52:36 +08:00
foreach (IPlugin plugin in plugins.Select(pluginPair => pluginPair.Plugin))
{
IPlugin plugin1 = plugin;
2014-01-09 22:16:19 +08:00
//ThreadPool.QueueUserWorkItem(o =>);
plugin1.Init(new PluginInitContext()
2014-01-03 23:52:36 +08:00
{
Plugins = plugins,
2014-01-05 17:56:02 +08:00
ChangeQuery = s => window.ChangeQuery(s),
CloseApp = window.CloseApp,
2014-01-07 23:27:05 +08:00
HideApp = window.HideApp,
2014-01-05 17:56:02 +08:00
ShowApp = window.ShowApp,
2014-01-07 23:27:05 +08:00
ShowMsg = (title, subTitle, iconPath) => window.ShowMsg(title, subTitle, iconPath)
2014-01-09 22:16:19 +08:00
});
2014-01-03 23:52:36 +08:00
}
2014-01-03 18:16:05 +08:00
}
public static List<PluginPair> AllPlugins
{
get { return plugins; }
}
2014-01-07 23:27:05 +08:00
public static bool HitThirdpartyKeyword(Query query)
{
if (string.IsNullOrEmpty(query.ActionName)) return false;
return plugins.Any(o => o.Metadata.PluginType == PluginType.ThirdParty && o.Metadata.ActionKeyword == query.ActionName);
}
2014-01-03 18:16:05 +08:00
}
}