From 178710dabc11302921efe57c7ea6b0c7d39c3af7 Mon Sep 17 00:00:00 2001 From: bao-qian Date: Thu, 5 Nov 2015 22:47:28 +0000 Subject: [PATCH] Fix PluginIndicator for multiple action keywords 1. Fixup, part of #352 2. Refactoring --- .../PluginIndicator.cs | 57 +++++++------------ Wox.Core/Plugin/PluginConfig.cs | 2 +- Wox.Core/Plugin/PluginManager.cs | 19 ++----- Wox.Plugin/Query.cs | 2 +- 4 files changed, 27 insertions(+), 53 deletions(-) diff --git a/Plugins/Wox.Plugin.PluginIndicator/PluginIndicator.cs b/Plugins/Wox.Plugin.PluginIndicator/PluginIndicator.cs index d0ad7b9a6f..f7b2bd0314 100644 --- a/Plugins/Wox.Plugin.PluginIndicator/PluginIndicator.cs +++ b/Plugins/Wox.Plugin.PluginIndicator/PluginIndicator.cs @@ -7,47 +7,32 @@ using Wox.Core.UserSettings; namespace Wox.Plugin.PluginIndicator { - public class PluginIndicator : IPlugin,IPluginI18n + public class PluginIndicator : IPlugin, IPluginI18n { - private List allPlugins = new List(); private PluginInitContext context; public List Query(Query query) { - List results = new List(); - if (allPlugins.Count == 0) - { - allPlugins = context.API.GetAllPlugins().Where(o => !PluginManager.IsGlobalPlugin(o.Metadata)).ToList(); - } - - foreach (PluginMetadata metadata in allPlugins.Select(o => o.Metadata)) - { - if (metadata.ActionKeyword.StartsWith(query.Search)) - { - PluginMetadata metadataCopy = metadata; - var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == metadataCopy.ID); - if (customizedPluginConfig != null && customizedPluginConfig.Disabled) - { - continue; - } - - Result result = new Result - { - Title = metadata.ActionKeyword, - SubTitle = string.Format("Activate {0} plugin", metadata.Name), - Score = 100, - IcoPath = metadata.FullIcoPath, - Action = (c) => - { - context.API.ChangeQuery(metadataCopy.ActionKeyword + " "); - return false; - }, - }; - results.Add(result); - } - } - - return results; + var results = from plugin in PluginManager.NonGlobalPlugins + select plugin.Metadata into metadata + from keyword in metadata.ActionKeywords + where keyword.StartsWith(query.Terms[0]) + let customizedPluginConfig = + UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == metadata.ID) + where customizedPluginConfig == null || !customizedPluginConfig.Disabled + select new Result + { + Title = keyword, + SubTitle = $"Activate {metadata.Name} plugin", + Score = 100, + IcoPath = metadata.FullIcoPath, + Action = (c) => + { + context.API.ChangeQuery($"{keyword}{Plugin.Query.TermSeperater}"); + return false; + }, + }; + return results.ToList(); } public void Init(PluginInitContext context) diff --git a/Wox.Core/Plugin/PluginConfig.cs b/Wox.Core/Plugin/PluginConfig.cs index 128d192495..a2f34fd79d 100644 --- a/Wox.Core/Plugin/PluginConfig.cs +++ b/Wox.Core/Plugin/PluginConfig.cs @@ -119,7 +119,7 @@ namespace Wox.Core.Plugin if (customizedPluginConfig?.ActionKeywords?.Length > 0) { metadata.ActionKeywords = customizedPluginConfig.ActionKeywords; - metadata.ActionKeyword = customizedPluginConfig.ActionKeywords[0]; //todo reenable + metadata.ActionKeyword = customizedPluginConfig.ActionKeywords[0]; } return metadata; diff --git a/Wox.Core/Plugin/PluginManager.cs b/Wox.Core/Plugin/PluginManager.cs index 749a91f30e..ab237af395 100644 --- a/Wox.Core/Plugin/PluginManager.cs +++ b/Wox.Core/Plugin/PluginManager.cs @@ -29,8 +29,8 @@ namespace Wox.Core.Plugin public static IEnumerable AllPlugins { get; private set; } - private static List GlobalPlugins { get; set; } - private static List NonGlobalPlugins { get; set; } + public static IEnumerable GlobalPlugins { get; private set; } + public static IEnumerable NonGlobalPlugins { get; private set; } private static IEnumerable InstantQueryPlugins { get; set; } public static IPublicAPI API { private set; get; } @@ -104,19 +104,8 @@ namespace Wox.Core.Plugin { InstantQueryPlugins = GetPluginsForInterface(); contextMenuPlugins = GetPluginsForInterface(); - GlobalPlugins = new List(); - NonGlobalPlugins = new List(); - foreach (var plugin in AllPlugins) - { - if (IsGlobalPlugin(plugin.Metadata)) - { - GlobalPlugins.Add(plugin); - } - else - { - NonGlobalPlugins.Add(plugin); - } - } + GlobalPlugins = AllPlugins.Where(p => IsGlobalPlugin(p.Metadata)); + NonGlobalPlugins = AllPlugins.Where(p => !IsGlobalPlugin(p.Metadata)); }); } diff --git a/Wox.Plugin/Query.cs b/Wox.Plugin/Query.cs index f5c4145ebf..400ae741f1 100644 --- a/Wox.Plugin/Query.cs +++ b/Wox.Plugin/Query.cs @@ -23,7 +23,7 @@ namespace Wox.Plugin /// /// The raw query splited into a string array. /// - internal string[] Terms { private get; set; } + public string[] Terms { get; set; } /// /// Query can be splited into multiple terms by whitespace