From 1d3f1fd7d0414887f1d2fb1c1ccf4871b721f268 Mon Sep 17 00:00:00 2001 From: qianlifeng Date: Wed, 4 Feb 2015 23:16:41 +0800 Subject: [PATCH] Improve instant search ue --- Plugins/Wox.Plugin.CMD/CMD.cs | 6 + .../ControlPanelList.cs | 2 - Plugins/Wox.Plugin.Folder/FolderPlugin.cs | 40 ++- .../FolderPluginSettings.xaml.cs | 12 +- Plugins/Wox.Plugin.Folder/Images/copy.png | Bin 0 -> 898 bytes .../Wox.Plugin.Folder.csproj | 241 ++++++++------- .../Wox.Plugin.Program/FileChangeWatcher.cs | 3 +- Plugins/Wox.Plugin.Program/Programs.cs | 7 +- .../Wox.Plugin.Program.csproj | 292 +++++++++--------- Wox.Core/Plugin/PluginManager.cs | 41 ++- .../QueryDispatcher/BaseQueryDispatcher.cs | 39 +++ .../SystemPluginQueryDispatcher.cs | 30 +- .../UserPluginQueryDispatcher.cs | 33 +- Wox.Core/Wox.Core.csproj | 1 + Wox.Infrastructure/DebugHelper.cs | 16 + Wox.Infrastructure/Logger/NLog.xsd | 2 +- Wox.Infrastructure/Timeit.cs | 2 +- Wox.Infrastructure/Wox.Infrastructure.csproj | 1 + Wox.Plugin/IPublicAPI.cs | 10 +- Wox.Plugin/Query.cs | 2 + Wox.Plugin/Result.cs | 5 + Wox/ImageLoader/ImageLoader.cs | 50 +-- Wox/MainWindow.xaml.cs | 35 ++- 23 files changed, 503 insertions(+), 367 deletions(-) create mode 100644 Plugins/Wox.Plugin.Folder/Images/copy.png create mode 100644 Wox.Core/Plugin/QueryDispatcher/BaseQueryDispatcher.cs create mode 100644 Wox.Infrastructure/DebugHelper.cs diff --git a/Plugins/Wox.Plugin.CMD/CMD.cs b/Plugins/Wox.Plugin.CMD/CMD.cs index bb0a212726..16e3777f78 100644 --- a/Plugins/Wox.Plugin.CMD/CMD.cs +++ b/Plugins/Wox.Plugin.CMD/CMD.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; @@ -20,6 +21,9 @@ namespace Wox.Plugin.CMD public List Query(Query query) { + Stopwatch stopwatch = new Stopwatch(); + stopwatch.Start(); + List results = new List(); List pushedResults = new List(); if (query.Search == ">") @@ -76,6 +80,8 @@ namespace Wox.Plugin.CMD catch (Exception) { } } + stopwatch.Stop(); + DebugHelper.WriteLine("CMD:" + stopwatch.ElapsedMilliseconds + "ms"); return results; } diff --git a/Plugins/Wox.Plugin.ControlPanel/ControlPanelList.cs b/Plugins/Wox.Plugin.ControlPanel/ControlPanelList.cs index 724688e4e1..68f11a52c8 100644 --- a/Plugins/Wox.Plugin.ControlPanel/ControlPanelList.cs +++ b/Plugins/Wox.Plugin.ControlPanel/ControlPanelList.cs @@ -326,8 +326,6 @@ namespace Wox.Plugin.ControlPanel private static bool EnumRes(IntPtr hModule, IntPtr lpszType, IntPtr lpszName, IntPtr lParam) { - //Debug.WriteLine("Type: " + GET_RESOURCE_NAME(lpszType)); - //Debug.WriteLine("Name: " + GET_RESOURCE_NAME(lpszName)); defaultIconPtr = lpszName; return false; } diff --git a/Plugins/Wox.Plugin.Folder/FolderPlugin.cs b/Plugins/Wox.Plugin.Folder/FolderPlugin.cs index da5525ffc9..7e7c641021 100644 --- a/Plugins/Wox.Plugin.Folder/FolderPlugin.cs +++ b/Plugins/Wox.Plugin.Folder/FolderPlugin.cs @@ -9,14 +9,14 @@ using Control = System.Windows.Controls.Control; namespace Wox.Plugin.Folder { - public class FolderPlugin : IPlugin, ISettingProvider,IPluginI18n + public class FolderPlugin : IPlugin, ISettingProvider, IPluginI18n { private static List driverNames; private PluginInitContext context; public Control CreateSettingPanel() { - return new FileSystemSettings(context); + return new FileSystemSettings(context.API); } public void Init(PluginInitContext context) @@ -32,11 +32,38 @@ namespace Wox.Plugin.Folder } } - void API_ResultItemDropEvent(Result result, IDataObject dropObject,DragEventArgs e) + void API_ResultItemDropEvent(Result result, IDataObject dropObject, DragEventArgs e) { + if (dropObject.GetDataPresent(DataFormats.FileDrop)) + { + HanldeFilesDrop(result, dropObject); + } e.Handled = true; } + private void HanldeFilesDrop(Result targetResult, IDataObject dropObject) + { + List files = ((string[])dropObject.GetData(DataFormats.FileDrop, false)).ToList(); + context.API.ShowContextMenu(context.CurrentPluginMetadata, GetContextMenusForFileDrop(targetResult, files)); + } + + private static List GetContextMenusForFileDrop(Result targetResult, List files) + { + List contextMenus = new List(); + string folderPath = ((FolderLink) targetResult.ContextData).Path; + contextMenus.Add(new Result() + { + Title = "Copy to this folder", + IcoPath = "Images/copy.png", + Action = _ => + { + MessageBox.Show("Copy"); + return true; + } + }); + return contextMenus; + } + private void ApiBackKeyDownEvent(WoxKeyDownEventArgs e) { string query = e.Query; @@ -84,7 +111,8 @@ namespace Wox.Plugin.Folder } context.API.ChangeQuery(item.Path); return false; - } + }, + ContextData = item }).ToList(); if (driverNames != null && !driverNames.Any(input.StartsWith)) @@ -98,9 +126,7 @@ namespace Wox.Plugin.Folder results.AddRange(QueryInternal_Directory_Exists(input)); return results; - } - - private void InitialDriverList() + } private void InitialDriverList() { if (driverNames == null) { diff --git a/Plugins/Wox.Plugin.Folder/FolderPluginSettings.xaml.cs b/Plugins/Wox.Plugin.Folder/FolderPluginSettings.xaml.cs index 64845005ea..0b0c655a73 100644 --- a/Plugins/Wox.Plugin.Folder/FolderPluginSettings.xaml.cs +++ b/Plugins/Wox.Plugin.Folder/FolderPluginSettings.xaml.cs @@ -13,11 +13,11 @@ namespace Wox.Plugin.Folder /// public partial class FileSystemSettings : UserControl { - PluginInitContext context; + private IPublicAPI woxAPI; - public FileSystemSettings(PluginInitContext context) + public FileSystemSettings(IPublicAPI woxAPI) { - this.context = context; + this.woxAPI = woxAPI; InitializeComponent(); lbxFolders.ItemsSource = FolderStorage.Instance.FolderLinks; } @@ -27,7 +27,7 @@ namespace Wox.Plugin.Folder var selectedFolder = lbxFolders.SelectedItem as FolderLink; if (selectedFolder != null) { - string msg = string.Format(context.API.GetTranslation("wox_plugin_folder_delete_folder_link"), selectedFolder.Path); + string msg = string.Format(woxAPI.GetTranslation("wox_plugin_folder_delete_folder_link"), selectedFolder.Path); if (MessageBox.Show(msg, string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.Yes) { @@ -37,7 +37,7 @@ namespace Wox.Plugin.Folder } else { - string warning = context.API.GetTranslation("wox_plugin_folder_select_folder_link_warning"); + string warning = woxAPI.GetTranslation("wox_plugin_folder_select_folder_link_warning"); MessageBox.Show(warning); } } @@ -61,7 +61,7 @@ namespace Wox.Plugin.Folder } else { - string warning = context.API.GetTranslation("wox_plugin_folder_select_folder_link_warning"); + string warning = woxAPI.GetTranslation("wox_plugin_folder_select_folder_link_warning"); MessageBox.Show(warning); } } diff --git a/Plugins/Wox.Plugin.Folder/Images/copy.png b/Plugins/Wox.Plugin.Folder/Images/copy.png new file mode 100644 index 0000000000000000000000000000000000000000..91f0647e736f23063e1011c1fd9bf49b783adfc7 GIT binary patch literal 898 zcmV-|1AY97P)yr?kapuiD3{9{ z^YimBr>3TU0jELMlCsA348xFNQYaK;KA)E}Gc#W@nM^Mb4=SK~i69GkMO9Ve@i>~M z^=Gr$xlAT=n}8y!L?S>@6ck0Fudk0(D%F?GX6JwoLJ$#&0Dwdyfu?Dui0SF+H$XdZ zEy%i&3219;LkNMUY4rE^)6>&4s_Xh&0*Z*)4H||aM@B{*CoL>2kW421KGT+BvFO>Q ztS;2z=V8fYlEJ}2KT~Zf7K;cW28M@+-|y_~jLy!^e#fKLMpi;@BoYZ)T3UR$R6_`8 zZEdAesrYiKh7b^o#gJ0^a;b(8AcR0s6kjgoxruY1zMAp%K-;w^9zUxVAq1VBo%Hth z0*vXp&cwvTD_|ceU!3PT11}!+m{&cp+OiOWj*bqxySwS?>KfB^{T&XO@MWX*Ae~NA zC=@t4I^yu~klo!~N~IF1R0>=&(J%rOMIoI|pBt-GDjXafaD04BsZ<&RUITxCqv|~k z(*t%0Ay8EnRaMF5asVn&#E$@L?XRr-4sVwp+1lEIv;CfX{RypvtQiV}i)P{UEi5zv z^>U|LG;|Mm!Bv1YZOgxXD zdf_TSh=w@0bH!DFqA0GDom?smo($abbf2w&y}dmqCnqVFFP-E8Ff=p-IJ;CB1o|8p zA0JnN8=RfPTw-~7c`4ZTyi=>soJ!~f*am(ESv(B<+UO}Be&UHjfZq&wA_|uZ^g&jO zS}qj@z65M;ZnC(z=;%^W;+`L8+HrBIIIeV)Pt<8 literal 0 HcmV?d00001 diff --git a/Plugins/Wox.Plugin.Folder/Wox.Plugin.Folder.csproj b/Plugins/Wox.Plugin.Folder/Wox.Plugin.Folder.csproj index 5551d5c2af..162c2a12bf 100644 --- a/Plugins/Wox.Plugin.Folder/Wox.Plugin.Folder.csproj +++ b/Plugins/Wox.Plugin.Folder/Wox.Plugin.Folder.csproj @@ -1,120 +1,123 @@ - - - - - Debug - AnyCPU - {787B8AA6-CA93-4C84-96FE-DF31110AD1C4} - Library - Properties - Wox.Plugin.Folder - Wox.Plugin.Folder - v3.5 - 512 - ..\..\ - true - - - - true - full - false - ..\..\Output\Debug\Plugins\Wox.Plugin.Folder\ - DEBUG;TRACE - prompt - 4 - false - - - pdbonly - true - ..\..\Output\Release\Plugins\Wox.Plugin.Folder\ - TRACE - prompt - 4 - false - - - - ..\..\packages\Newtonsoft.Json.6.0.8\lib\net35\Newtonsoft.Json.dll - True - - - - - - - - - - - - - - - - - - FolderPluginSettings.xaml - - - - - - - - PreserveNewest - - - - - MSBuild:Compile - Designer - - - MSBuild:Compile - Designer - PreserveNewest - - - MSBuild:Compile - Designer - PreserveNewest - - - MSBuild:Compile - Designer - PreserveNewest - - - - - {4fd29318-a8ab-4d8f-aa47-60bc241b8da3} - Wox.Infrastructure - - - {8451ecdd-2ea4-4966-bb0a-7bbc40138e80} - Wox.Plugin - - - - - PreserveNewest - - - - - - - 这台计算机上缺少此项目引用的 NuGet 程序包。启用“NuGet 程序包还原”可下载这些程序包。有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。 - - - - + + + + + Debug + AnyCPU + {787B8AA6-CA93-4C84-96FE-DF31110AD1C4} + Library + Properties + Wox.Plugin.Folder + Wox.Plugin.Folder + v3.5 + 512 + ..\..\ + true + + + + true + full + false + ..\..\Output\Debug\Plugins\Wox.Plugin.Folder\ + DEBUG;TRACE + prompt + 4 + false + + + pdbonly + true + ..\..\Output\Release\Plugins\Wox.Plugin.Folder\ + TRACE + prompt + 4 + false + + + + ..\..\packages\Newtonsoft.Json.6.0.8\lib\net35\Newtonsoft.Json.dll + True + + + + + + + + + + + + + + + + + + FolderPluginSettings.xaml + + + + + + + + PreserveNewest + + + + + MSBuild:Compile + Designer + + + PreserveNewest + + + MSBuild:Compile + Designer + PreserveNewest + + + MSBuild:Compile + Designer + PreserveNewest + + + MSBuild:Compile + Designer + PreserveNewest + + + + + {4fd29318-a8ab-4d8f-aa47-60bc241b8da3} + Wox.Infrastructure + + + {8451ecdd-2ea4-4966-bb0a-7bbc40138e80} + Wox.Plugin + + + + + PreserveNewest + + + + + + + 这台计算机上缺少此项目引用的 NuGet 程序包。启用“NuGet 程序包还原”可下载这些程序包。有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。 + + + + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Program/FileChangeWatcher.cs b/Plugins/Wox.Plugin.Program/FileChangeWatcher.cs index 303970fd38..c6f6ec5469 100644 --- a/Plugins/Wox.Plugin.Program/FileChangeWatcher.cs +++ b/Plugins/Wox.Plugin.Program/FileChangeWatcher.cs @@ -2,6 +2,7 @@ using System.Diagnostics; using System.IO; using System.Threading; +using Wox.Infrastructure; namespace Wox.Plugin.Program { @@ -15,7 +16,7 @@ namespace Wox.Plugin.Program if (watchedPath.Contains(path)) return; if (!Directory.Exists(path)) { - Debug.WriteLine(string.Format("FileChangeWatcher: {0} doesn't exist", path),"WoxDebug"); + DebugHelper.WriteLine(string.Format("FileChangeWatcher: {0} doesn't exist", path)); return; } diff --git a/Plugins/Wox.Plugin.Program/Programs.cs b/Plugins/Wox.Plugin.Program/Programs.cs index ded1fea3e3..4d888bd5b6 100644 --- a/Plugins/Wox.Plugin.Program/Programs.cs +++ b/Plugins/Wox.Plugin.Program/Programs.cs @@ -108,16 +108,17 @@ namespace Wox.Plugin.Program { programs = ProgramCacheStorage.Instance.Programs; } - Debug.WriteLine(string.Format("Preload {0} programs from cache", programs.Count), "Wox"); + DebugHelper.WriteLine(string.Format("Preload {0} programs from cache", programs.Count)); using (new Timeit("Program Index")) { IndexPrograms(); } } - void API_ResultItemDropEvent(Result result, IDataObject dropObject, DragEventArgs args) + void API_ResultItemDropEvent(Result result, IDataObject dropObject, DragEventArgs e) { - args.Handled = true; + + e.Handled = true; } public static void IndexPrograms() diff --git a/Plugins/Wox.Plugin.Program/Wox.Plugin.Program.csproj b/Plugins/Wox.Plugin.Program/Wox.Plugin.Program.csproj index 1fa4ddf8cf..0f357736f1 100644 --- a/Plugins/Wox.Plugin.Program/Wox.Plugin.Program.csproj +++ b/Plugins/Wox.Plugin.Program/Wox.Plugin.Program.csproj @@ -1,153 +1,153 @@ - - - - - Debug - AnyCPU - {FDB3555B-58EF-4AE6-B5F1-904719637AB4} - Library - Properties - Wox.Plugin.Program - Wox.Plugin.Program - v3.5 - 512 - ..\..\ - true - - - - true - full - false - ..\..\Output\Debug\Plugins\Wox.Plugin.Program\ - DEBUG;TRACE - prompt - 4 - false - - - pdbonly - true - ..\..\Output\Release\Plugins\Wox.Plugin.Program\ - TRACE - prompt - 4 - false - - - - False - ..\..\packages\Newtonsoft.Json.6.0.8\lib\net35\Newtonsoft.Json.dll - - - - - - - - - - - - - - - - - - - - - ProgramSetting.xaml - - - - - - - - - ProgramSuffixes.xaml - - - - - - - - PreserveNewest - - - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - MSBuild:Compile - Designer - PreserveNewest - - - - - MSBuild:Compile - Designer - PreserveNewest - - - MSBuild:Compile - Designer - PreserveNewest - - - MSBuild:Compile - Designer - - - MSBuild:Compile - Designer - - - - - {4fd29318-a8ab-4d8f-aa47-60bc241b8da3} - Wox.Infrastructure - - - {8451ecdd-2ea4-4966-bb0a-7bbc40138e80} - Wox.Plugin - - - - - {F935DC20-1CF0-11D0-ADB9-00C04FD58A0B} - 1 - 0 - 0 - tlbimp - False - True - - - - - - - 这台计算机上缺少此项目引用的 NuGet 程序包。启用“NuGet 程序包还原”可下载这些程序包。有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。 - - - + + + + + Debug + AnyCPU + {FDB3555B-58EF-4AE6-B5F1-904719637AB4} + Library + Properties + Wox.Plugin.Program + Wox.Plugin.Program + v3.5 + 512 + ..\..\ + true + + + + true + full + false + ..\..\Output\Debug\Plugins\Wox.Plugin.Program\ + DEBUG;TRACE + prompt + 4 + false + + + pdbonly + true + ..\..\Output\Release\Plugins\Wox.Plugin.Program\ + TRACE + prompt + 4 + false + + + + False + ..\..\packages\Newtonsoft.Json.6.0.8\lib\net35\Newtonsoft.Json.dll + + + + + + + + + + + + + + + + + + + + + ProgramSetting.xaml + + + + + + + + + ProgramSuffixes.xaml + + + + + + + + PreserveNewest + + + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + MSBuild:Compile + Designer + PreserveNewest + + + + + MSBuild:Compile + Designer + PreserveNewest + + + MSBuild:Compile + Designer + PreserveNewest + + + MSBuild:Compile + Designer + + + MSBuild:Compile + Designer + + + + + {4fd29318-a8ab-4d8f-aa47-60bc241b8da3} + Wox.Infrastructure + + + {8451ecdd-2ea4-4966-bb0a-7bbc40138e80} + Wox.Plugin + + + + + {F935DC20-1CF0-11D0-ADB9-00C04FD58A0B} + 1 + 0 + 0 + tlbimp + False + True + + + + + + + 这台计算机上缺少此项目引用的 NuGet 程序包。启用“NuGet 程序包还原”可下载这些程序包。有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。 + + + + --> \ No newline at end of file diff --git a/Wox.Core/Plugin/PluginManager.cs b/Wox.Core/Plugin/PluginManager.cs index c9d15ec0b9..fabc450f2a 100644 --- a/Wox.Core/Plugin/PluginManager.cs +++ b/Wox.Core/Plugin/PluginManager.cs @@ -21,7 +21,7 @@ namespace Wox.Core.Plugin { public const string ActionKeywordWildcardSign = "*"; private static List pluginMetadatas; - private static List instantSearches = new List(); + private static List> instantSearches; public static String DebuggerMode { get; private set; } @@ -98,7 +98,10 @@ namespace Wox.Core.Plugin }); } - LoadInstantSearches(); + ThreadPool.QueueUserWorkItem(o => + { + LoadInstantSearches(); + }); } public static void InstallPlugin(string path) @@ -146,12 +149,38 @@ namespace Wox.Core.Plugin public static bool IsInstantSearch(string query) { - return LoadInstantSearches().Any(o => o.IsInstantSearch(query)); + return LoadInstantSearches().Any(o => o.Value.IsInstantSearch(query)); } - private static List LoadInstantSearches() + public static bool IsInstantSearchPlugin(PluginMetadata pluginMetadata) { - if (instantSearches.Count > 0) return instantSearches; + //todo:to improve performance, any instant search plugin that takes long than 200ms will not consider a instant plugin anymore + return pluginMetadata.Language.ToUpper() == AllowedLanguage.CSharp && + LoadInstantSearches().Any(o => o.Key.ID == pluginMetadata.ID); + } + + internal static void ExecutePluginQuery(PluginPair pair, Query query) + { + try + { + List results = pair.Plugin.Query(query) ?? new List(); + results.ForEach(o => + { + o.PluginID = pair.Metadata.ID; + }); + API.PushResults(query, pair.Metadata, results); + } + catch (System.Exception e) + { + throw new WoxPluginException(pair.Metadata.Name, e); + } + } + + private static List> LoadInstantSearches() + { + if (instantSearches != null) return instantSearches; + + instantSearches = new List>(); List CSharpPluginMetadatas = pluginMetadatas.Where(o => o.Language.ToUpper() == AllowedLanguage.CSharp.ToUpper()).ToList(); foreach (PluginMetadata metadata in CSharpPluginMetadatas) @@ -167,7 +196,7 @@ namespace Wox.Core.Plugin foreach (Type type in types) { - instantSearches.Add(Activator.CreateInstance(type) as IInstantSearch); + instantSearches.Add(new KeyValuePair(metadata,Activator.CreateInstance(type) as IInstantSearch)); } } catch (System.Exception e) diff --git a/Wox.Core/Plugin/QueryDispatcher/BaseQueryDispatcher.cs b/Wox.Core/Plugin/QueryDispatcher/BaseQueryDispatcher.cs new file mode 100644 index 0000000000..6c5c562c8c --- /dev/null +++ b/Wox.Core/Plugin/QueryDispatcher/BaseQueryDispatcher.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading; +using Wox.Infrastructure; +using Wox.Plugin; + +namespace Wox.Core.Plugin.QueryDispatcher +{ + public abstract class BaseQueryDispatcher : IQueryDispatcher + { + protected abstract List GetPlugins(Query query); + + public void Dispatch(Query query) + { + foreach (PluginPair pair in GetPlugins(query)) + { + PluginPair localPair = pair; + if (query.IsIntantQuery && PluginManager.IsInstantSearchPlugin(pair.Metadata)) + { + DebugHelper.WriteLine(string.Format("Plugin {0} is executing instant search.", pair.Metadata.Name)); + using (new Timeit(" => instant search took: ")) + { + PluginManager.ExecutePluginQuery(localPair, query); + } + } + else + { + ThreadPool.QueueUserWorkItem(state => + { + PluginManager.ExecutePluginQuery(localPair, query); + }); + } + } + } + } +} diff --git a/Wox.Core/Plugin/QueryDispatcher/SystemPluginQueryDispatcher.cs b/Wox.Core/Plugin/QueryDispatcher/SystemPluginQueryDispatcher.cs index 5cda7d3e34..9a9948df01 100644 --- a/Wox.Core/Plugin/QueryDispatcher/SystemPluginQueryDispatcher.cs +++ b/Wox.Core/Plugin/QueryDispatcher/SystemPluginQueryDispatcher.cs @@ -8,34 +8,14 @@ using Wox.Plugin; namespace Wox.Core.Plugin.QueryDispatcher { - public class SystemPluginQueryDispatcher : IQueryDispatcher + public class SystemPluginQueryDispatcher : BaseQueryDispatcher { - private IEnumerable allSytemPlugins = PluginManager.AllPlugins.Where(o => PluginManager.IsSystemPlugin(o.Metadata)); + private readonly List allSytemPlugins = + PluginManager.AllPlugins.Where(o => PluginManager.IsSystemPlugin(o.Metadata)).ToList(); - public void Dispatch(Query query) + protected override List GetPlugins(Query query) { - var queryPlugins = allSytemPlugins; - foreach (PluginPair pair in queryPlugins) - { - PluginPair pair1 = pair; - ThreadPool.QueueUserWorkItem(state => - { - try - { - List results = pair1.Plugin.Query(query); - results.ForEach(o => - { - o.PluginID = pair1.Metadata.ID; - }); - - PluginManager.API.PushResults(query, pair1.Metadata, results); - } - catch (System.Exception e) - { - throw new WoxPluginException(pair1.Metadata.Name,e); - } - }); - } + return allSytemPlugins; } } } \ No newline at end of file diff --git a/Wox.Core/Plugin/QueryDispatcher/UserPluginQueryDispatcher.cs b/Wox.Core/Plugin/QueryDispatcher/UserPluginQueryDispatcher.cs index c50344296e..d3cebb88d0 100644 --- a/Wox.Core/Plugin/QueryDispatcher/UserPluginQueryDispatcher.cs +++ b/Wox.Core/Plugin/QueryDispatcher/UserPluginQueryDispatcher.cs @@ -9,38 +9,29 @@ using Wox.Plugin; namespace Wox.Core.Plugin.QueryDispatcher { - public class UserPluginQueryDispatcher : IQueryDispatcher + public class UserPluginQueryDispatcher : BaseQueryDispatcher { - public void Dispatch(Query query) + protected override List GetPlugins(Query query) { + List plugins = new List(); + //only first plugin that matches action keyword will get executed PluginPair userPlugin = PluginManager.AllPlugins.FirstOrDefault(o => o.Metadata.ActionKeyword == query.GetActionKeyword()); - if (userPlugin != null && !string.IsNullOrEmpty(userPlugin.Metadata.ActionKeyword)) + if (userPlugin != null) { - var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == userPlugin.Metadata.ID); + var customizedPluginConfig = UserSettingStorage.Instance. + CustomizedPluginConfigs.FirstOrDefault(o => o.ID == userPlugin.Metadata.ID); if (customizedPluginConfig != null && customizedPluginConfig.Disabled) { //need to stop the loading animation PluginManager.API.StopLoadingBar(); - return; } - - ThreadPool.QueueUserWorkItem(t => + else { - try - { - List results = userPlugin.Plugin.Query(query) ?? new List(); - results.ForEach(o => - { - o.PluginID = userPlugin.Metadata.ID; - }); - PluginManager.API.PushResults(query, userPlugin.Metadata, results); - } - catch (System.Exception e) - { - throw new WoxPluginException(userPlugin.Metadata.Name, e); - } - }); + plugins.Add(userPlugin); + } } + + return plugins; } } } diff --git a/Wox.Core/Wox.Core.csproj b/Wox.Core/Wox.Core.csproj index 84940b3039..92c63ae13c 100644 --- a/Wox.Core/Wox.Core.csproj +++ b/Wox.Core/Wox.Core.csproj @@ -69,6 +69,7 @@ + diff --git a/Wox.Infrastructure/DebugHelper.cs b/Wox.Infrastructure/DebugHelper.cs new file mode 100644 index 0000000000..5d5e111423 --- /dev/null +++ b/Wox.Infrastructure/DebugHelper.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; + +namespace Wox.Infrastructure +{ + public static class DebugHelper + { + public static void WriteLine(string msg) + { + Debug.WriteLine(msg); + } + } +} diff --git a/Wox.Infrastructure/Logger/NLog.xsd b/Wox.Infrastructure/Logger/NLog.xsd index 481702860b..edf2b7087a 100644 --- a/Wox.Infrastructure/Logger/NLog.xsd +++ b/Wox.Infrastructure/Logger/NLog.xsd @@ -855,7 +855,7 @@ - + diff --git a/Wox.Infrastructure/Timeit.cs b/Wox.Infrastructure/Timeit.cs index a29ea53ed8..14dd1f62c0 100644 --- a/Wox.Infrastructure/Timeit.cs +++ b/Wox.Infrastructure/Timeit.cs @@ -20,7 +20,7 @@ namespace Wox.Infrastructure public void Dispose() { stopwatch.Stop(); - Debug.WriteLine(name + ":" + stopwatch.ElapsedMilliseconds + "ms","Wox"); + DebugHelper.WriteLine(name + ":" + stopwatch.ElapsedMilliseconds + "ms"); } } } diff --git a/Wox.Infrastructure/Wox.Infrastructure.csproj b/Wox.Infrastructure/Wox.Infrastructure.csproj index ca13df96fb..75a45afeea 100644 --- a/Wox.Infrastructure/Wox.Infrastructure.csproj +++ b/Wox.Infrastructure/Wox.Infrastructure.csproj @@ -58,6 +58,7 @@ + diff --git a/Wox.Plugin/IPublicAPI.cs b/Wox.Plugin/IPublicAPI.cs index 1e9ec5c059..b564480db8 100644 --- a/Wox.Plugin/IPublicAPI.cs +++ b/Wox.Plugin/IPublicAPI.cs @@ -15,7 +15,13 @@ namespace Wox.Plugin /// /// /// - void PushResults(Query query,PluginMetadata plugin, List results); + void PushResults(Query query, PluginMetadata plugin, List results); + + /// + /// Show context menu with giving results + /// + /// + void ShowContextMenu(PluginMetadata plugin, List results); /// /// Execute command @@ -63,7 +69,7 @@ namespace Wox.Plugin /// Open setting dialog /// void OpenSettingDialog(); - + /// /// Show loading animation /// diff --git a/Wox.Plugin/Query.cs b/Wox.Plugin/Query.cs index 4a01199142..dee9628773 100644 --- a/Wox.Plugin/Query.cs +++ b/Wox.Plugin/Query.cs @@ -33,6 +33,8 @@ namespace Wox.Plugin return string.Empty; } + internal bool IsIntantQuery { get; set; } + /// /// Return first search split by space if it has /// diff --git a/Wox.Plugin/Result.cs b/Wox.Plugin/Result.cs index 6c1938fa43..5248cbb57c 100644 --- a/Wox.Plugin/Result.cs +++ b/Wox.Plugin/Result.cs @@ -73,6 +73,11 @@ namespace Wox.Plugin /// public List ContextMenu { get; set; } + /// + /// Additional data associate with this result + /// + public object ContextData { get; set; } + /// /// Plugin ID that generate this result /// diff --git a/Wox/ImageLoader/ImageLoader.cs b/Wox/ImageLoader/ImageLoader.cs index e0f87147e6..8fa9f9c5d8 100644 --- a/Wox/ImageLoader/ImageLoader.cs +++ b/Wox/ImageLoader/ImageLoader.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Drawing; using System.IO; using System.Runtime.InteropServices; @@ -79,42 +80,49 @@ namespace Wox.ImageLoader public static ImageSource Load(string path, bool addToCache = true) { + Stopwatch sw = new Stopwatch(); + sw.Start(); + if (string.IsNullOrEmpty(path)) return null; if (addToCache) { ImageCacheStroage.Instance.Add(path); } + ImageSource img = null; if (imageCache.ContainsKey(path)) { - return imageCache[path]; + img = imageCache[path]; } - - ImageSource img = null; - string ext = Path.GetExtension(path).ToLower(); - - if (path.StartsWith("data:", StringComparison.OrdinalIgnoreCase)) + else { - img = new BitmapImage(new Uri(path)); - } - else if (selfExts.Contains(ext) && File.Exists(path)) - { - img = GetIcon(path); - } - else if (!string.IsNullOrEmpty(path) && imageExts.Contains(ext) && File.Exists(path)) - { - img = new BitmapImage(new Uri(path)); - } + string ext = Path.GetExtension(path).ToLower(); - - if (img != null && addToCache) - { - if (!imageCache.ContainsKey(path)) + if (path.StartsWith("data:", StringComparison.OrdinalIgnoreCase)) { - imageCache.Add(path, img); + img = new BitmapImage(new Uri(path)); + } + else if (selfExts.Contains(ext) && File.Exists(path)) + { + img = GetIcon(path); + } + else if (!string.IsNullOrEmpty(path) && imageExts.Contains(ext) && File.Exists(path)) + { + img = new BitmapImage(new Uri(path)); + } + + + if (img != null && addToCache) + { + if (!imageCache.ContainsKey(path)) + { + imageCache.Add(path, img); + } } } + sw.Stop(); + DebugHelper.WriteLine(string.Format("Loading image path: {0} - {1}ms",path,sw.ElapsedMilliseconds)); return img; } diff --git a/Wox/MainWindow.xaml.cs b/Wox/MainWindow.xaml.cs index fb7c1789fd..95a6e81bbf 100644 --- a/Wox/MainWindow.xaml.cs +++ b/Wox/MainWindow.xaml.cs @@ -157,6 +157,23 @@ namespace Wox UpdateResultView(results); } + public void ShowContextMenu(PluginMetadata plugin, List results) + { + if (results != null && results.Count > 0) + { + results.ForEach(o => + { + o.PluginDirectory = plugin.PluginDirectory; + o.PluginID = plugin.ID; + o.ContextMenu = null; + }); + pnlContextMenu.Clear(); + pnlContextMenu.AddResults(results); + pnlContextMenu.Visibility = Visibility.Visible; + pnlResult.Visibility = Visibility.Collapsed; + } + } + #endregion public MainWindow() @@ -226,7 +243,7 @@ namespace Wox void pnlResult_RightMouseClickEvent(Result result) { - ShowContextMenu(result); + ShowContextMenuFromResult(result); } void MainWindow_Closing(object sender, CancelEventArgs e) @@ -261,7 +278,7 @@ namespace Wox private void CheckUpdate() { - UpdaterManager.Instance.PrepareUpdateReady+=OnPrepareUpdateReady; + UpdaterManager.Instance.PrepareUpdateReady += OnPrepareUpdateReady; UpdaterManager.Instance.UpdateError += OnUpdateError; UpdaterManager.Instance.CheckUpdate(); } @@ -368,6 +385,8 @@ namespace Wox lastQuery = tbQuery.Text; toolTip.IsOpen = false; pnlResult.Dirty = true; + int searchDelay = GetSearchDelay(lastQuery); + Dispatcher.DelayInvoke("UpdateSearch", o => { @@ -381,6 +400,7 @@ namespace Wox }, TimeSpan.FromMilliseconds(100), null); queryHasReturn = false; Query query = new Query(lastQuery); + query.IsIntantQuery = searchDelay == 0; FireBeforeWoxQueryEvent(query); Query(query); Dispatcher.DelayInvoke("ShowProgressbar", originQuery => @@ -391,15 +411,18 @@ namespace Wox } }, TimeSpan.FromMilliseconds(150), tbQuery.Text); FireAfterWoxQueryEvent(query); - }, TimeSpan.FromMilliseconds(GetSearchDelay(lastQuery))); + }, TimeSpan.FromMilliseconds(searchDelay)); } private int GetSearchDelay(string query) { if (!string.IsNullOrEmpty(query) && PluginManager.IsInstantSearch(query)) { + DebugHelper.WriteLine("execute query without delay"); return 0; } + + DebugHelper.WriteLine("execute query with 200ms delay"); return 200; } @@ -551,7 +574,7 @@ namespace Wox } else { - ShowContextMenu(GetActiveResult()); + ShowContextMenuFromResult(GetActiveResult()); } } break; @@ -609,7 +632,7 @@ namespace Wox Result activeResult = GetActiveResult(); if (GlobalHotkey.Instance.CheckModifiers().ShiftPressed) { - ShowContextMenu(activeResult); + ShowContextMenuFromResult(activeResult); } else { @@ -740,7 +763,7 @@ namespace Wox } } - private void ShowContextMenu(Result result) + private void ShowContextMenuFromResult(Result result) { if (result.ContextMenu != null && result.ContextMenu.Count > 0) {