diff --git a/Plugins/Wox.Plugin.CMD/CMD.cs b/Plugins/Wox.Plugin.CMD/CMD.cs index b120c4f280..cd522d56af 100644 --- a/Plugins/Wox.Plugin.CMD/CMD.cs +++ b/Plugins/Wox.Plugin.CMD/CMD.cs @@ -9,11 +9,12 @@ using WindowsInput; using WindowsInput.Native; using Wox.Infrastructure; using Wox.Infrastructure.Hotkey; +using Wox.Plugin.Features; using Control = System.Windows.Controls.Control; namespace Wox.Plugin.CMD { - public class CMD : IPlugin, ISettingProvider, IPluginI18n, IInstantSearch + public class CMD : IPlugin, ISettingProvider, IPluginI18n, IInstantSearch,IExclusiveSearch { private PluginInitContext context; private bool WinRStroked; @@ -217,5 +218,10 @@ namespace Wox.Plugin.CMD if (query.StartsWith(">")) return true; return false; } + + public bool IsExclusiveSearch(Query query) + { + return query.Search.StartsWith(">"); + } } } \ No newline at end of file diff --git a/Wox.Core/Plugin/PluginManager.cs b/Wox.Core/Plugin/PluginManager.cs index af31c7a70e..9cf930c783 100644 --- a/Wox.Core/Plugin/PluginManager.cs +++ b/Wox.Core/Plugin/PluginManager.cs @@ -12,6 +12,7 @@ using Wox.Infrastructure; using Wox.Infrastructure.Http; using Wox.Infrastructure.Logger; using Wox.Plugin; +using Wox.Plugin.Features; namespace Wox.Core.Plugin { @@ -23,7 +24,7 @@ namespace Wox.Core.Plugin public const string ActionKeywordWildcardSign = "*"; private static List pluginMetadatas; private static List> instantSearches; - + private static List> exclusiveSearchPlugins; public static String DebuggerMode { get; private set; } public static IPublicAPI API { get; private set; } @@ -116,6 +117,7 @@ namespace Wox.Core.Plugin { if (!string.IsNullOrEmpty(query.RawQuery.Trim())) { + query.Search = IsUserPluginQuery(query) ? query.RawQuery.Substring(query.RawQuery.IndexOf(' ') + 1) : query.RawQuery; QueryDispatcher.QueryDispatcher.Dispatch(query); } } @@ -238,5 +240,51 @@ namespace Wox.Core.Plugin { return AllPlugins.FirstOrDefault(o => o.Metadata.ID == id); } + + internal static List> LoadExclusiveSearchPlugins() + { + if (exclusiveSearchPlugins != null) return exclusiveSearchPlugins; + + exclusiveSearchPlugins = new List>(); + List CSharpPluginMetadatas = pluginMetadatas.Where(o => o.Language.ToUpper() == AllowedLanguage.CSharp.ToUpper()).ToList(); + + foreach (PluginMetadata metadata in CSharpPluginMetadatas) + { + try + { + Assembly asm = Assembly.Load(AssemblyName.GetAssemblyName(metadata.ExecuteFilePath)); + List types = asm.GetTypes().Where(o => o.IsClass && !o.IsAbstract && o.GetInterfaces().Contains(typeof(IExclusiveSearch))).ToList(); + if (types.Count == 0) + { + continue; + } + + foreach (Type type in types) + { + exclusiveSearchPlugins.Add(new KeyValuePair(AllPlugins.First(o => o.Metadata.ID == metadata.ID), + Activator.CreateInstance(type) as IExclusiveSearch)); + } + } + catch (System.Exception e) + { + Log.Error(string.Format("Couldn't load plugin {0}: {1}", metadata.Name, e.Message)); +#if (DEBUG) + { + throw; + } +#endif + } + } + + return exclusiveSearchPlugins; + } + + internal static PluginPair GetExclusiveSearchPlugin(Query query) + { + KeyValuePair plugin = LoadExclusiveSearchPlugins().FirstOrDefault(o => o.Value.IsExclusiveSearch((query))); + if (plugin.Key != null) return plugin.Key; + + return null; + } } } diff --git a/Wox.Core/Plugin/QueryDispatcher/QueryDispatcher.cs b/Wox.Core/Plugin/QueryDispatcher/QueryDispatcher.cs index e5f5b76bf4..3b4a4af556 100644 --- a/Wox.Core/Plugin/QueryDispatcher/QueryDispatcher.cs +++ b/Wox.Core/Plugin/QueryDispatcher/QueryDispatcher.cs @@ -1,4 +1,7 @@  +using System.Threading; +using Wox.Plugin; + namespace Wox.Core.Plugin.QueryDispatcher { internal static class QueryDispatcher @@ -8,14 +11,22 @@ namespace Wox.Core.Plugin.QueryDispatcher public static void Dispatch(Wox.Plugin.Query query) { + PluginPair exclusiveSearchPlugin = PluginManager.GetExclusiveSearchPlugin(query); + if (exclusiveSearchPlugin != null) + { + ThreadPool.QueueUserWorkItem(state => + { + PluginManager.ExecutePluginQuery(exclusiveSearchPlugin, query); + }); + return; + } + if (PluginManager.IsUserPluginQuery(query)) { - query.Search = query.RawQuery.Substring(query.RawQuery.IndexOf(' ') + 1); UserPluginDispatcher.Dispatch(query); } else { - query.Search = query.RawQuery; SystemPluginDispatcher.Dispatch(query); } } diff --git a/Wox.Plugin/Features/IExclusiveSearch.cs b/Wox.Plugin/Features/IExclusiveSearch.cs new file mode 100644 index 0000000000..0339b5094a --- /dev/null +++ b/Wox.Plugin/Features/IExclusiveSearch.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Wox.Plugin.Features +{ + public interface IExclusiveSearch + { + bool IsExclusiveSearch(Query query); + } +} diff --git a/Wox.Plugin/IInstantSearch.cs b/Wox.Plugin/IInstantSearch.cs index 0799f45f4b..553c6573b4 100644 --- a/Wox.Plugin/IInstantSearch.cs +++ b/Wox.Plugin/IInstantSearch.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using Wox.Plugin.Features; namespace Wox.Plugin { diff --git a/Wox.Plugin/Wox.Plugin.csproj b/Wox.Plugin/Wox.Plugin.csproj index 424272a200..665f70ff37 100644 --- a/Wox.Plugin/Wox.Plugin.csproj +++ b/Wox.Plugin/Wox.Plugin.csproj @@ -46,6 +46,7 @@ +