mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 11:46:30 +02:00
Add IExclusiveSearch interface [WIP]
This commit is contained in:
@@ -9,11 +9,12 @@ using WindowsInput;
|
|||||||
using WindowsInput.Native;
|
using WindowsInput.Native;
|
||||||
using Wox.Infrastructure;
|
using Wox.Infrastructure;
|
||||||
using Wox.Infrastructure.Hotkey;
|
using Wox.Infrastructure.Hotkey;
|
||||||
|
using Wox.Plugin.Features;
|
||||||
using Control = System.Windows.Controls.Control;
|
using Control = System.Windows.Controls.Control;
|
||||||
|
|
||||||
namespace Wox.Plugin.CMD
|
namespace Wox.Plugin.CMD
|
||||||
{
|
{
|
||||||
public class CMD : IPlugin, ISettingProvider, IPluginI18n, IInstantSearch
|
public class CMD : IPlugin, ISettingProvider, IPluginI18n, IInstantSearch,IExclusiveSearch
|
||||||
{
|
{
|
||||||
private PluginInitContext context;
|
private PluginInitContext context;
|
||||||
private bool WinRStroked;
|
private bool WinRStroked;
|
||||||
@@ -217,5 +218,10 @@ namespace Wox.Plugin.CMD
|
|||||||
if (query.StartsWith(">")) return true;
|
if (query.StartsWith(">")) return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsExclusiveSearch(Query query)
|
||||||
|
{
|
||||||
|
return query.Search.StartsWith(">");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -12,6 +12,7 @@ using Wox.Infrastructure;
|
|||||||
using Wox.Infrastructure.Http;
|
using Wox.Infrastructure.Http;
|
||||||
using Wox.Infrastructure.Logger;
|
using Wox.Infrastructure.Logger;
|
||||||
using Wox.Plugin;
|
using Wox.Plugin;
|
||||||
|
using Wox.Plugin.Features;
|
||||||
|
|
||||||
namespace Wox.Core.Plugin
|
namespace Wox.Core.Plugin
|
||||||
{
|
{
|
||||||
@@ -23,7 +24,7 @@ namespace Wox.Core.Plugin
|
|||||||
public const string ActionKeywordWildcardSign = "*";
|
public const string ActionKeywordWildcardSign = "*";
|
||||||
private static List<PluginMetadata> pluginMetadatas;
|
private static List<PluginMetadata> pluginMetadatas;
|
||||||
private static List<KeyValuePair<PluginMetadata, IInstantSearch>> instantSearches;
|
private static List<KeyValuePair<PluginMetadata, IInstantSearch>> instantSearches;
|
||||||
|
private static List<KeyValuePair<PluginPair,IExclusiveSearch>> exclusiveSearchPlugins;
|
||||||
|
|
||||||
public static String DebuggerMode { get; private set; }
|
public static String DebuggerMode { get; private set; }
|
||||||
public static IPublicAPI API { get; private set; }
|
public static IPublicAPI API { get; private set; }
|
||||||
@@ -116,6 +117,7 @@ namespace Wox.Core.Plugin
|
|||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(query.RawQuery.Trim()))
|
if (!string.IsNullOrEmpty(query.RawQuery.Trim()))
|
||||||
{
|
{
|
||||||
|
query.Search = IsUserPluginQuery(query) ? query.RawQuery.Substring(query.RawQuery.IndexOf(' ') + 1) : query.RawQuery;
|
||||||
QueryDispatcher.QueryDispatcher.Dispatch(query);
|
QueryDispatcher.QueryDispatcher.Dispatch(query);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -238,5 +240,51 @@ namespace Wox.Core.Plugin
|
|||||||
{
|
{
|
||||||
return AllPlugins.FirstOrDefault(o => o.Metadata.ID == id);
|
return AllPlugins.FirstOrDefault(o => o.Metadata.ID == id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static List<KeyValuePair<PluginPair, IExclusiveSearch>> LoadExclusiveSearchPlugins()
|
||||||
|
{
|
||||||
|
if (exclusiveSearchPlugins != null) return exclusiveSearchPlugins;
|
||||||
|
|
||||||
|
exclusiveSearchPlugins = new List<KeyValuePair<PluginPair, IExclusiveSearch>>();
|
||||||
|
List<PluginMetadata> 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<Type> 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<PluginPair, IExclusiveSearch>(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<PluginPair, IExclusiveSearch> plugin = LoadExclusiveSearchPlugins().FirstOrDefault(o => o.Value.IsExclusiveSearch((query)));
|
||||||
|
if (plugin.Key != null) return plugin.Key;
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
|
|
||||||
|
using System.Threading;
|
||||||
|
using Wox.Plugin;
|
||||||
|
|
||||||
namespace Wox.Core.Plugin.QueryDispatcher
|
namespace Wox.Core.Plugin.QueryDispatcher
|
||||||
{
|
{
|
||||||
internal static class QueryDispatcher
|
internal static class QueryDispatcher
|
||||||
@@ -8,14 +11,22 @@ namespace Wox.Core.Plugin.QueryDispatcher
|
|||||||
|
|
||||||
public static void Dispatch(Wox.Plugin.Query query)
|
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))
|
if (PluginManager.IsUserPluginQuery(query))
|
||||||
{
|
{
|
||||||
query.Search = query.RawQuery.Substring(query.RawQuery.IndexOf(' ') + 1);
|
|
||||||
UserPluginDispatcher.Dispatch(query);
|
UserPluginDispatcher.Dispatch(query);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
query.Search = query.RawQuery;
|
|
||||||
SystemPluginDispatcher.Dispatch(query);
|
SystemPluginDispatcher.Dispatch(query);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
12
Wox.Plugin/Features/IExclusiveSearch.cs
Normal file
12
Wox.Plugin/Features/IExclusiveSearch.cs
Normal file
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using Wox.Plugin.Features;
|
||||||
|
|
||||||
namespace Wox.Plugin
|
namespace Wox.Plugin
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -46,6 +46,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="AllowedLanguage.cs" />
|
<Compile Include="AllowedLanguage.cs" />
|
||||||
<Compile Include="EventHandler.cs" />
|
<Compile Include="EventHandler.cs" />
|
||||||
|
<Compile Include="Features\IExclusiveSearch.cs" />
|
||||||
<Compile Include="IInstantSearch.cs" />
|
<Compile Include="IInstantSearch.cs" />
|
||||||
<Compile Include="IHttpProxy.cs" />
|
<Compile Include="IHttpProxy.cs" />
|
||||||
<Compile Include="IPluginI18n.cs" />
|
<Compile Include="IPluginI18n.cs" />
|
||||||
|
|||||||
Reference in New Issue
Block a user