2015-01-03 15:20:34 +08:00
|
|
|
|
using System.Collections.Generic;
|
2014-01-06 19:03:20 +08:00
|
|
|
|
using System.Linq;
|
2015-01-04 23:08:26 +08:00
|
|
|
|
using Wox.Core.Plugin;
|
2015-01-05 22:41:17 +08:00
|
|
|
|
using Wox.Core.UserSettings;
|
2014-01-06 19:03:20 +08:00
|
|
|
|
|
2015-01-03 15:20:34 +08:00
|
|
|
|
namespace Wox.Plugin.PluginIndicator
|
2014-01-06 19:03:20 +08:00
|
|
|
|
{
|
2015-01-03 15:20:34 +08:00
|
|
|
|
public class PluginIndicator : IPlugin
|
2014-01-06 19:03:20 +08:00
|
|
|
|
{
|
|
|
|
|
private List<PluginPair> allPlugins = new List<PluginPair>();
|
2014-07-05 23:10:34 +08:00
|
|
|
|
private PluginInitContext context;
|
2014-01-06 19:03:20 +08:00
|
|
|
|
|
2015-01-03 15:20:34 +08:00
|
|
|
|
public List<Result> Query(Query query)
|
2014-01-06 19:03:20 +08:00
|
|
|
|
{
|
|
|
|
|
List<Result> results = new List<Result>();
|
2015-01-03 15:20:34 +08:00
|
|
|
|
if (allPlugins.Count == 0)
|
|
|
|
|
{
|
2015-01-26 17:46:55 +08:00
|
|
|
|
allPlugins = context.API.GetAllPlugins().Where(o => !PluginManager.IsSystemPlugin(o.Metadata)).ToList();
|
2015-01-03 15:20:34 +08:00
|
|
|
|
}
|
2014-01-06 19:03:20 +08:00
|
|
|
|
|
2014-01-29 22:44:57 +08:00
|
|
|
|
foreach (PluginMetadata metadata in allPlugins.Select(o => o.Metadata))
|
2014-01-06 19:03:20 +08:00
|
|
|
|
{
|
2015-01-26 17:46:55 +08:00
|
|
|
|
if (metadata.ActionKeyword.StartsWith(query.Search))
|
2014-01-06 19:03:20 +08:00
|
|
|
|
{
|
|
|
|
|
PluginMetadata metadataCopy = metadata;
|
2014-07-01 22:19:46 +08:00
|
|
|
|
var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == metadataCopy.ID);
|
|
|
|
|
if (customizedPluginConfig != null && customizedPluginConfig.Disabled)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-06 19:03:20 +08:00
|
|
|
|
Result result = new Result
|
|
|
|
|
{
|
|
|
|
|
Title = metadata.ActionKeyword,
|
2014-01-29 22:44:57 +08:00
|
|
|
|
SubTitle = string.Format("Activate {0} plugin", metadata.Name),
|
2014-07-18 20:00:55 +08:00
|
|
|
|
Score = 100,
|
2014-12-09 23:42:20 +08:00
|
|
|
|
IcoPath = metadata.FullIcoPath,
|
2014-02-28 23:21:01 +08:00
|
|
|
|
Action = (c) =>
|
|
|
|
|
{
|
2014-07-21 19:48:17 +08:00
|
|
|
|
context.API.ChangeQuery(metadataCopy.ActionKeyword + " ");
|
2014-02-28 23:21:01 +08:00
|
|
|
|
return false;
|
|
|
|
|
},
|
2014-01-06 19:03:20 +08:00
|
|
|
|
};
|
2014-01-29 22:44:57 +08:00
|
|
|
|
results.Add(result);
|
2014-01-06 19:03:20 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-01-29 22:44:57 +08:00
|
|
|
|
|
2015-01-26 22:50:38 +08:00
|
|
|
|
//results.AddRange(UserSettingStorage.Instance.WebSearches.Where(o => o.ActionWord.StartsWith(query.Search) && o.Enabled).Select(n => new Result()
|
|
|
|
|
//{
|
|
|
|
|
// Title = n.ActionWord,
|
|
|
|
|
// SubTitle = string.Format("Activate {0} web search", n.ActionWord),
|
|
|
|
|
// Score = 100,
|
|
|
|
|
// IcoPath = "Images/work.png",
|
|
|
|
|
// Action = (c) =>
|
|
|
|
|
// {
|
|
|
|
|
// context.API.ChangeQuery(n.ActionWord + " ");
|
|
|
|
|
// return false;
|
|
|
|
|
// }
|
|
|
|
|
//}));
|
2014-01-29 22:44:57 +08:00
|
|
|
|
|
2014-01-06 19:03:20 +08:00
|
|
|
|
return results;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-03 15:20:34 +08:00
|
|
|
|
public void Init(PluginInitContext context)
|
2014-01-06 19:03:20 +08:00
|
|
|
|
{
|
2014-07-05 23:10:34 +08:00
|
|
|
|
this.context = context;
|
2014-01-06 19:03:20 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|