From 288be8dd716710db5c55ad0443fe4cb9b560ab5c Mon Sep 17 00:00:00 2001 From: qianlifeng Date: Wed, 7 Jan 2015 22:23:10 +0800 Subject: [PATCH 1/2] update plugin languages --- Plugins/Wox.Plugin.CMD/Languages/zh-cn.xaml | 14 +- Plugins/Wox.Plugin.CMD/Languages/zh-tw.xaml | 8 + Plugins/Wox.Plugin.CMD/Wox.Plugin.CMD.csproj | 242 +++++++-------- .../Wox.Plugin.Folder/Languages/zh-cn.xaml | 20 +- .../Wox.Plugin.Folder/Languages/zh-tw.xaml | 20 +- .../Wox.Plugin.Folder.csproj | 238 +++++++-------- .../Wox.Plugin.Program/Languages/zh-tw.xaml | 24 ++ .../Wox.Plugin.Program.csproj | 270 ++++++++--------- Plugins/Wox.Plugin.Sys/Languages/en.xaml | 15 + Plugins/Wox.Plugin.Sys/Languages/zh-cn.xaml | 15 + Plugins/Wox.Plugin.Sys/Languages/zh-tw.xaml | 15 + Plugins/Wox.Plugin.Sys/Sys.cs | 34 ++- Plugins/Wox.Plugin.Sys/SysSettings.xaml | 4 +- Plugins/Wox.Plugin.Sys/Wox.Plugin.Sys.csproj | 15 + .../Wox.Plugin.WebSearch/Languages/zh-cn.xaml | 54 ++-- .../Wox.Plugin.WebSearch/Languages/zh-tw.xaml | 54 ++-- .../Wox.Plugin.WebSearch.csproj | 286 +++++++++--------- Wox.Core/Plugin/PluginManager.cs | 4 + Wox.Core/UI/ResourceMerger.cs | 6 +- 19 files changed, 724 insertions(+), 614 deletions(-) create mode 100644 Plugins/Wox.Plugin.CMD/Languages/zh-tw.xaml create mode 100644 Plugins/Wox.Plugin.Program/Languages/zh-tw.xaml create mode 100644 Plugins/Wox.Plugin.Sys/Languages/en.xaml create mode 100644 Plugins/Wox.Plugin.Sys/Languages/zh-cn.xaml create mode 100644 Plugins/Wox.Plugin.Sys/Languages/zh-tw.xaml diff --git a/Plugins/Wox.Plugin.CMD/Languages/zh-cn.xaml b/Plugins/Wox.Plugin.CMD/Languages/zh-cn.xaml index 989e0c3d79..0847dda6ce 100644 --- a/Plugins/Wox.Plugin.CMD/Languages/zh-cn.xaml +++ b/Plugins/Wox.Plugin.CMD/Languages/zh-cn.xaml @@ -1,8 +1,8 @@ - - - 替换 Win+R - 执行后不关闭命令窗口 - + + + 替换 Win+R + 执行后不关闭命令窗口 + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.CMD/Languages/zh-tw.xaml b/Plugins/Wox.Plugin.CMD/Languages/zh-tw.xaml new file mode 100644 index 0000000000..8ac28c3639 --- /dev/null +++ b/Plugins/Wox.Plugin.CMD/Languages/zh-tw.xaml @@ -0,0 +1,8 @@ + + + 替換 Win+R + 執行後不關閉命令窗口 + + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.CMD/Wox.Plugin.CMD.csproj b/Plugins/Wox.Plugin.CMD/Wox.Plugin.CMD.csproj index e7e53944d4..fa40001d77 100644 --- a/Plugins/Wox.Plugin.CMD/Wox.Plugin.CMD.csproj +++ b/Plugins/Wox.Plugin.CMD/Wox.Plugin.CMD.csproj @@ -1,122 +1,122 @@ - - - - - Debug - AnyCPU - {C21BFF9C-2C99-4B5F-B7C9-A5E6DDDB37B0} - Library - Properties - Wox.Plugin.CMD - Wox.Plugin.CMD - v3.5 - 512 - ..\..\ - true - - - true - full - false - ..\..\Output\Debug\Plugins\Wox.Plugin.CMD\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - False - ..\..\packages\log4net.2.0.3\lib\net35-full\log4net.dll - - - False - ..\..\packages\Newtonsoft.Json.6.0.7\lib\net35\Newtonsoft.Json.dll - - - - - - - - - - - - - ..\..\packages\InputSimulator.1.0.4.0\lib\net20\WindowsInput.dll - - - - - - CMDSetting.xaml - - - - - - - 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 - - - - - PreserveNewest - - - - - - - 这台计算机上缺少此项目引用的 NuGet 程序包。启用“NuGet 程序包还原”可下载这些程序包。有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。 - - - - + + + + + Debug + AnyCPU + {C21BFF9C-2C99-4B5F-B7C9-A5E6DDDB37B0} + Library + Properties + Wox.Plugin.CMD + Wox.Plugin.CMD + v3.5 + 512 + ..\..\ + true + + + true + full + false + ..\..\Output\Debug\Plugins\Wox.Plugin.CMD\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + False + ..\..\packages\log4net.2.0.3\lib\net35-full\log4net.dll + + + False + ..\..\packages\Newtonsoft.Json.6.0.7\lib\net35\Newtonsoft.Json.dll + + + + + + + + + + + + + ..\..\packages\InputSimulator.1.0.4.0\lib\net20\WindowsInput.dll + + + + + + CMDSetting.xaml + + + + + + + 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 + + + + + PreserveNewest + + + + + + + 这台计算机上缺少此项目引用的 NuGet 程序包。启用“NuGet 程序包还原”可下载这些程序包。有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。 + + + + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Folder/Languages/zh-cn.xaml b/Plugins/Wox.Plugin.Folder/Languages/zh-cn.xaml index 745f49a5a2..9f1ccabe99 100644 --- a/Plugins/Wox.Plugin.Folder/Languages/zh-cn.xaml +++ b/Plugins/Wox.Plugin.Folder/Languages/zh-cn.xaml @@ -1,11 +1,11 @@ - - - 删除 - 编辑 - 添加 - 文件夹路径 - 请选择一个文件夹 - + + + 删除 + 编辑 + 添加 + 文件夹路径 + 请选择一个文件夹 + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Folder/Languages/zh-tw.xaml b/Plugins/Wox.Plugin.Folder/Languages/zh-tw.xaml index 4d718e3eb6..ddc0809a64 100644 --- a/Plugins/Wox.Plugin.Folder/Languages/zh-tw.xaml +++ b/Plugins/Wox.Plugin.Folder/Languages/zh-tw.xaml @@ -1,11 +1,11 @@ - - - 刪除 - 編輯 - 添加 - 文件夾路徑 - 請選擇一個文件夾 - + + + 刪除 + 編輯 + 添加 + 文件夾路徑 + 請選擇一個文件夾 + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Folder/Wox.Plugin.Folder.csproj b/Plugins/Wox.Plugin.Folder/Wox.Plugin.Folder.csproj index 9af75f72b3..416fffab72 100644 --- a/Plugins/Wox.Plugin.Folder/Wox.Plugin.Folder.csproj +++ b/Plugins/Wox.Plugin.Folder/Wox.Plugin.Folder.csproj @@ -1,120 +1,120 @@ - - - - - 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 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - False - ..\..\packages\log4net.2.0.3\lib\net35-full\log4net.dll - - - False - ..\..\packages\Newtonsoft.Json.6.0.7\lib\net35\Newtonsoft.Json.dll - - - - - - - - - - - - - - - - - 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 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + False + ..\..\packages\log4net.2.0.3\lib\net35-full\log4net.dll + + + False + ..\..\packages\Newtonsoft.Json.6.0.7\lib\net35\Newtonsoft.Json.dll + + + + + + + + + + + + + + + + + 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}。 + + + + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Program/Languages/zh-tw.xaml b/Plugins/Wox.Plugin.Program/Languages/zh-tw.xaml new file mode 100644 index 0000000000..d56fc2d4cd --- /dev/null +++ b/Plugins/Wox.Plugin.Program/Languages/zh-tw.xaml @@ -0,0 +1,24 @@ + + + + 刪除 + 編輯 + 增加 + 位置 + 索引文件後綴 + 重新索引 + 索引中 + + + 請先選擇一項 + 你確定要刪除{0}嗎? + + 更新 + Wox僅索引下列後綴的文件: + (每個後綴以英文狀態下的分號分隔) + 成功更新索引文件後綴 + 文件後綴不能為空 + + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Program/Wox.Plugin.Program.csproj b/Plugins/Wox.Plugin.Program/Wox.Plugin.Program.csproj index 05eb883153..06c57a2cfb 100644 --- a/Plugins/Wox.Plugin.Program/Wox.Plugin.Program.csproj +++ b/Plugins/Wox.Plugin.Program/Wox.Plugin.Program.csproj @@ -1,136 +1,136 @@ - - - - - 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 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\..\packages\log4net.2.0.3\lib\net35-full\log4net.dll - - - False - ..\..\packages\Newtonsoft.Json.6.0.7\lib\net35\Newtonsoft.Json.dll - - - - - - - - - - - - - - - - - - - - ProgramSetting.xaml - - - - - - - - - ProgramSuffixes.xaml - - - - - - - - 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 - - - - - - - - 这台计算机上缺少此项目引用的 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 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\..\packages\log4net.2.0.3\lib\net35-full\log4net.dll + + + False + ..\..\packages\Newtonsoft.Json.6.0.7\lib\net35\Newtonsoft.Json.dll + + + + + + + + + + + + + + + + + + + + ProgramSetting.xaml + + + + + + + + + ProgramSuffixes.xaml + + + + + + + + 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 + + + + + + + + 这台计算机上缺少此项目引用的 NuGet 程序包。启用“NuGet 程序包还原”可下载这些程序包。有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。 + + + + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Sys/Languages/en.xaml b/Plugins/Wox.Plugin.Sys/Languages/en.xaml new file mode 100644 index 0000000000..280d5ff506 --- /dev/null +++ b/Plugins/Wox.Plugin.Sys/Languages/en.xaml @@ -0,0 +1,15 @@ + + + Command + Description + + Shutdown Computer + Log off + Lock this computer + Close Wox + Restart Wox + Tweak this app + + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Sys/Languages/zh-cn.xaml b/Plugins/Wox.Plugin.Sys/Languages/zh-cn.xaml new file mode 100644 index 0000000000..5abec64ce5 --- /dev/null +++ b/Plugins/Wox.Plugin.Sys/Languages/zh-cn.xaml @@ -0,0 +1,15 @@ + + + 命令 + 描述 + + 关闭电脑 + 注销 + 锁定这台电脑 + 退出Wox + 重启Wox + 设置 + + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Sys/Languages/zh-tw.xaml b/Plugins/Wox.Plugin.Sys/Languages/zh-tw.xaml new file mode 100644 index 0000000000..e393f0d8bd --- /dev/null +++ b/Plugins/Wox.Plugin.Sys/Languages/zh-tw.xaml @@ -0,0 +1,15 @@ + + + 命令 + 描述 + + 關閉電腦 + 註銷 + 鎖定這臺電腦 + 退出Wox + 重啟Wox + 設置 + + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Sys/Sys.cs b/Plugins/Wox.Plugin.Sys/Sys.cs index 69f7646e24..2351f55735 100644 --- a/Plugins/Wox.Plugin.Sys/Sys.cs +++ b/Plugins/Wox.Plugin.Sys/Sys.cs @@ -1,13 +1,16 @@ using System.Collections.Generic; using System.Diagnostics; +using System.IO; +using System.Reflection; using System.Runtime.InteropServices; using System.Windows.Forms; namespace Wox.Plugin.Sys { - public class Sys : IPlugin, ISettingProvider + public class Sys : IPlugin, ISettingProvider ,IPluginI18n { List availableResults = new List(); + private PluginInitContext context; #region DllImport @@ -32,9 +35,12 @@ namespace Wox.Plugin.Sys public List Query(Query query) { if (query.RawQuery.EndsWith(" ") || query.RawQuery.Length <= 1) return new List(); + if (availableResults.Count == 0) + { + LoadCommands(); + } List results = new List(); - foreach (Result availableResult in availableResults) { if (availableResult.Title.ToLower().StartsWith(query.RawQuery.ToLower())) @@ -47,11 +53,16 @@ namespace Wox.Plugin.Sys public void Init(PluginInitContext context) { - availableResults.AddRange(new Result[] { + this.context = context; + } + + private void LoadCommands() + { + availableResults.AddRange(new Result[] { new Result { Title = "Shutdown", - SubTitle = "Shutdown Computer", + SubTitle = context.API.GetTranslation("wox_plugin_sys_shutdown_computer"), Score = 100, IcoPath = "Images\\exit.png", Action = (c) => @@ -65,7 +76,7 @@ namespace Wox.Plugin.Sys new Result { Title = "Log off", - SubTitle = "Log off current user", + SubTitle = context.API.GetTranslation("wox_plugin_sys_log_off"), Score = 100, IcoPath = "Images\\logoff.png", Action = (c) => ExitWindowsEx(EWX_LOGOFF, 0) @@ -73,7 +84,7 @@ namespace Wox.Plugin.Sys new Result { Title = "Lock", - SubTitle = "Lock this computer", + SubTitle = context.API.GetTranslation("wox_plugin_sys_lock"), Score = 100, IcoPath = "Images\\lock.png", Action = (c) => @@ -85,7 +96,7 @@ namespace Wox.Plugin.Sys new Result { Title = "Exit", - SubTitle = "Close this app", + SubTitle = context.API.GetTranslation("wox_plugin_sys_exit"), Score = 110, IcoPath = "Images\\app.png", Action = (c) => @@ -97,7 +108,7 @@ namespace Wox.Plugin.Sys new Result { Title = "Restart Wox", - SubTitle = "Restart Wox", + SubTitle = context.API.GetTranslation("wox_plugin_sys_restart"), Score = 110, IcoPath = "Images\\restart.png", Action = (c) => @@ -115,7 +126,7 @@ namespace Wox.Plugin.Sys new Result { Title = "Settings", - SubTitle = "Tweak this app", + SubTitle = context.API.GetTranslation("wox_plugin_sys_setting"), Score = 100, IcoPath = "Images\\app.png", Action = (c) => @@ -127,7 +138,10 @@ namespace Wox.Plugin.Sys }); } + public string GetLanguagesFolder() + { + return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Languages"); - + } } } diff --git a/Plugins/Wox.Plugin.Sys/SysSettings.xaml b/Plugins/Wox.Plugin.Sys/SysSettings.xaml index 09de8f3709..5ef2443a56 100644 --- a/Plugins/Wox.Plugin.Sys/SysSettings.xaml +++ b/Plugins/Wox.Plugin.Sys/SysSettings.xaml @@ -9,14 +9,14 @@ - + - + diff --git a/Plugins/Wox.Plugin.Sys/Wox.Plugin.Sys.csproj b/Plugins/Wox.Plugin.Sys/Wox.Plugin.Sys.csproj index b7e956920d..e43980995c 100644 --- a/Plugins/Wox.Plugin.Sys/Wox.Plugin.Sys.csproj +++ b/Plugins/Wox.Plugin.Sys/Wox.Plugin.Sys.csproj @@ -64,6 +64,21 @@ + + MSBuild:Compile + Designer + PreserveNewest + + + MSBuild:Compile + Designer + PreserveNewest + + + MSBuild:Compile + Designer + PreserveNewest + MSBuild:Compile Designer diff --git a/Plugins/Wox.Plugin.WebSearch/Languages/zh-cn.xaml b/Plugins/Wox.Plugin.WebSearch/Languages/zh-cn.xaml index 6e13e40ceb..f82419b67d 100644 --- a/Plugins/Wox.Plugin.WebSearch/Languages/zh-cn.xaml +++ b/Plugins/Wox.Plugin.WebSearch/Languages/zh-cn.xaml @@ -1,28 +1,28 @@ - - - 删除 - 编辑 - 添加 - 触发关键字 - URL - 启用搜索建议 - 请选择一项 - 你确定要删除 {0} 吗? - - - - 标题 - 启用 - 图标 - 选择图标 - 取消 - 非法的网页搜索 - 请输入标题 - 请输入触发关键字 - 请输入URL - 触发关键字已经存在,请选择一个新的关键字 - 操作成功 - + + + 删除 + 编辑 + 添加 + 触发关键字 + URL + 启用搜索建议 + 请选择一项 + 你确定要删除 {0} 吗? + + + + 标题 + 启用 + 图标 + 选择图标 + 取消 + 非法的网页搜索 + 请输入标题 + 请输入触发关键字 + 请输入URL + 触发关键字已经存在,请选择一个新的关键字 + 操作成功 + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.WebSearch/Languages/zh-tw.xaml b/Plugins/Wox.Plugin.WebSearch/Languages/zh-tw.xaml index e5ba22a86a..def9146a81 100644 --- a/Plugins/Wox.Plugin.WebSearch/Languages/zh-tw.xaml +++ b/Plugins/Wox.Plugin.WebSearch/Languages/zh-tw.xaml @@ -1,28 +1,28 @@ - - - 刪除 - 編輯 - 添加 - 觸發關鍵字 - URL - 啟用搜索建議 - 請選擇一項 - 你確定要刪除 {0} 嗎? - - - - 標題 - 啟用 - 圖標 - 選擇圖標 - 取消 - 非法的網頁搜索 - 請輸入標題 - 請輸入觸發關鍵字 - 請輸入URL - 觸發關鍵字已經存在,請選擇一個新的關鍵字 - 操作成功 - + + + 刪除 + 編輯 + 添加 + 觸發關鍵字 + URL + 啟用搜索建議 + 請選擇一項 + 你確定要刪除 {0} 嗎? + + + + 標題 + 啟用 + 圖標 + 選擇圖標 + 取消 + 非法的網頁搜索 + 請輸入標題 + 請輸入觸發關鍵字 + 請輸入URL + 觸發關鍵字已經存在,請選擇一個新的關鍵字 + 操作成功 + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.WebSearch/Wox.Plugin.WebSearch.csproj b/Plugins/Wox.Plugin.WebSearch/Wox.Plugin.WebSearch.csproj index 7062faa9ef..dc388582f8 100644 --- a/Plugins/Wox.Plugin.WebSearch/Wox.Plugin.WebSearch.csproj +++ b/Plugins/Wox.Plugin.WebSearch/Wox.Plugin.WebSearch.csproj @@ -1,144 +1,144 @@ - - - - - Debug - AnyCPU - {403B57F2-1856-4FC7-8A24-36AB346B763E} - Library - Properties - Wox.Plugin.WebSearch - Wox.Plugin.WebSearch - v3.5 - 512 - ..\..\ - true - - - true - full - false - ..\..\Output\Debug\Plugins\Wox.Plugin.WebSearch\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\..\packages\log4net.2.0.3\lib\net35-full\log4net.dll - - - False - ..\..\packages\Newtonsoft.Json.6.0.7\lib\net35\Newtonsoft.Json.dll - - - - - - - - - - - - - - - - - - - WebSearchesSetting.xaml - - - - WebSearchSetting.xaml - - - - - MSBuild:Compile - Designer - PreserveNewest - - - MSBuild:Compile - Designer - PreserveNewest - - - MSBuild:Compile - Designer - PreserveNewest - - - MSBuild:Compile - Designer - - - MSBuild:Compile - Designer - - - - - - - - {B749F0DB-8E75-47DB-9E5E-265D16D0C0D2} - Wox.Core - - - {4fd29318-a8ab-4d8f-aa47-60bc241b8da3} - Wox.Infrastructure - - - {8451ecdd-2ea4-4966-bb0a-7bbc40138e80} - Wox.Plugin - - - - - - PreserveNewest - - - - - PreserveNewest - - - - - PreserveNewest - - - - - PreserveNewest - - - - - - - 这台计算机上缺少此项目引用的 NuGet 程序包。启用“NuGet 程序包还原”可下载这些程序包。有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。 - - - - + + + + + Debug + AnyCPU + {403B57F2-1856-4FC7-8A24-36AB346B763E} + Library + Properties + Wox.Plugin.WebSearch + Wox.Plugin.WebSearch + v3.5 + 512 + ..\..\ + true + + + true + full + false + ..\..\Output\Debug\Plugins\Wox.Plugin.WebSearch\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\..\packages\log4net.2.0.3\lib\net35-full\log4net.dll + + + False + ..\..\packages\Newtonsoft.Json.6.0.7\lib\net35\Newtonsoft.Json.dll + + + + + + + + + + + + + + + + + + + WebSearchesSetting.xaml + + + + WebSearchSetting.xaml + + + + + MSBuild:Compile + Designer + PreserveNewest + + + MSBuild:Compile + Designer + PreserveNewest + + + MSBuild:Compile + Designer + PreserveNewest + + + MSBuild:Compile + Designer + + + MSBuild:Compile + Designer + + + + + + + + {B749F0DB-8E75-47DB-9E5E-265D16D0C0D2} + Wox.Core + + + {4fd29318-a8ab-4d8f-aa47-60bc241b8da3} + Wox.Infrastructure + + + {8451ecdd-2ea4-4966-bb0a-7bbc40138e80} + Wox.Plugin + + + + + + PreserveNewest + + + + + PreserveNewest + + + + + PreserveNewest + + + + + PreserveNewest + + + + + + + 这台计算机上缺少此项目引用的 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 f1badfc1d0..8620751f22 100644 --- a/Wox.Core/Plugin/PluginManager.cs +++ b/Wox.Core/Plugin/PluginManager.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Reflection; using System.Threading; using Wox.Core.Exception; +using Wox.Core.UI; using Wox.Core.UserSettings; using Wox.Infrastructure; using Wox.Infrastructure.Http; @@ -91,6 +92,9 @@ namespace Wox.Core.Plugin plugins.AddRange(new CSharpPluginLoader().LoadPlugin(pluginMetadatas)); plugins.AddRange(new JsonRPCPluginLoader().LoadPlugin(pluginMetadatas)); + //load plugin i18n languages + ResourceMerger.ApplyPluginLanguages(); + foreach (PluginPair pluginPair in plugins) { PluginPair pair = pluginPair; diff --git a/Wox.Core/UI/ResourceMerger.cs b/Wox.Core/UI/ResourceMerger.cs index c261576e6a..b2167a3cd3 100644 --- a/Wox.Core/UI/ResourceMerger.cs +++ b/Wox.Core/UI/ResourceMerger.cs @@ -13,10 +13,10 @@ namespace Wox.Core.UI { Application.Current.Resources.MergedDictionaries.Clear(); ApplyPluginLanguages(); - ApplyUIResources(); + ApplyThemeAndLanguageResources(); } - private static void ApplyUIResources() + private static void ApplyThemeAndLanguageResources() { var UIResourceType = typeof(IUIResource); var UIResources = AppDomain.CurrentDomain.GetAssemblies() @@ -30,7 +30,7 @@ namespace Wox.Core.UI } } - private static void ApplyPluginLanguages() + public static void ApplyPluginLanguages() { var pluginI18nType = typeof(IPluginI18n); var pluginI18ns = AppDomain.CurrentDomain.GetAssemblies() From 220ac2fa2debdfb774fa643e6008c1297a686844 Mon Sep 17 00:00:00 2001 From: qianlifeng Date: Thu, 8 Jan 2015 22:49:42 +0800 Subject: [PATCH 2/2] Fix a global hotkey issues in CMD, which will hang Wox on init. --- Plugins/Wox.Plugin.CMD/CMD.cs | 9 +- Plugins/Wox.Plugin.Folder/FolderPlugin.cs | 2 +- Plugins/Wox.Plugin.Program/Images/cmd.png | Bin 0 -> 1633 bytes Plugins/Wox.Plugin.Program/Programs.cs | 1 + .../Wox.Plugin.Program.csproj | 3 + Wox.Core/Plugin/PluginManager.cs | 5 +- Wox.Infrastructure/Hotkey/GlobalHotkey.cs | 113 +++--------------- Wox.Infrastructure/Hotkey/InterceptKeys.cs | 38 ++++++ Wox.Infrastructure/Hotkey/KeyEvent.cs | 25 ++++ Wox.Infrastructure/Wox.Infrastructure.csproj | 2 + Wox.Plugin/EventHandler.cs | 9 ++ Wox.Plugin/IPublicAPI.cs | 2 + Wox/HotkeyControl.xaml.cs | 2 +- Wox/MainWindow.xaml.cs | 76 ++++++------ Wox/SettingWindow.xaml.cs | 14 +-- 15 files changed, 148 insertions(+), 153 deletions(-) create mode 100644 Plugins/Wox.Plugin.Program/Images/cmd.png create mode 100644 Wox.Infrastructure/Hotkey/InterceptKeys.cs create mode 100644 Wox.Infrastructure/Hotkey/KeyEvent.cs diff --git a/Plugins/Wox.Plugin.CMD/CMD.cs b/Plugins/Wox.Plugin.CMD/CMD.cs index 7cd9fe2f5b..993a5795a1 100644 --- a/Plugins/Wox.Plugin.CMD/CMD.cs +++ b/Plugins/Wox.Plugin.CMD/CMD.cs @@ -13,7 +13,6 @@ namespace Wox.Plugin.CMD { public class CMD : IPlugin, ISettingProvider,IPluginI18n { - private readonly GlobalHotkey globalHotkey = new GlobalHotkey(); private PluginInitContext context; private bool WinRStroked; private readonly KeyboardSimulator keyboardSimulator = new KeyboardSimulator(new InputSimulator()); @@ -174,20 +173,20 @@ namespace Wox.Plugin.CMD public void Init(PluginInitContext context) { this.context = context; - globalHotkey.hookedKeyboardCallback += KListener_hookedKeyboardCallback; + context.API.GlobalKeyboardEvent += API_GlobalKeyboardEvent; } - private bool KListener_hookedKeyboardCallback(KeyEvent keyevent, int vkcode, SpecialKeyState state) + bool API_GlobalKeyboardEvent(int keyevent, int vkcode, SpecialKeyState state) { if (CMDStorage.Instance.ReplaceWinR) { - if (keyevent == KeyEvent.WM_KEYDOWN && vkcode == (int)Keys.R && state.WinPressed) + if (keyevent == (int)KeyEvent.WM_KEYDOWN && vkcode == (int)Keys.R && state.WinPressed) { WinRStroked = true; OnWinRPressed(); return false; } - if (keyevent == KeyEvent.WM_KEYUP && WinRStroked && vkcode == (int)Keys.LWin) + if (keyevent == (int)KeyEvent.WM_KEYUP && WinRStroked && vkcode == (int)Keys.LWin) { WinRStroked = false; keyboardSimulator.ModifiedKeyStroke(VirtualKeyCode.LWIN, VirtualKeyCode.CONTROL); diff --git a/Plugins/Wox.Plugin.Folder/FolderPlugin.cs b/Plugins/Wox.Plugin.Folder/FolderPlugin.cs index 809e90f9fb..0d50ce0ca0 100644 --- a/Plugins/Wox.Plugin.Folder/FolderPlugin.cs +++ b/Plugins/Wox.Plugin.Folder/FolderPlugin.cs @@ -82,7 +82,7 @@ namespace Wox.Plugin.Folder } }).ToList(); - if (!driverNames.Any(input.StartsWith)) + if (driverNames != null && !driverNames.Any(input.StartsWith)) return results; if (!input.EndsWith("\\")) diff --git a/Plugins/Wox.Plugin.Program/Images/cmd.png b/Plugins/Wox.Plugin.Program/Images/cmd.png new file mode 100644 index 0000000000000000000000000000000000000000..4e4ca094437e8b4f15f4b09e1831c72545864ccf GIT binary patch literal 1633 zcmV-n2A=teP)|z=9CLhAz6IL1a->h*YA2k~jgAU^{-zNWm$}Th{q$$7=!YgH|p8br|O5BHzfdY0B~KGjEsy-PEAey zWLcJNjDa!c<7P^B)2h{K(f#}Pze=T2f3#XH!vR2RO)8a2CYem0t<`GI*47r3Qa#Au zC(DD3bB=sI565x*jZ$e;O8FeXJ^&>pgb;Loex5EYEI>*L08mPGz;ru5Y8_v9uM>#` zu3o*0OP4MY5JD-X=#&5e3;-!5eBVbHhA0#Y*xA`ZyWNKG`v`)d1FAc~Vds7zsZ1?!a|jT)%!D=gyr2A*9D)x8wLY zYR?!0&N-WynD}C2W8?Eiy-s@=&|MFXkB?(!W(Gq;L%4VE9@f^@005NIo*)O&eONiP z)&M}2Qe<;;bG^}M^p>C-bvm8K{QNv#zI=&xyA7>1a=9Eh=a5pO(P*I2Xdn#3zomg# z%t|Q}hM_K(%YXVopnF6Z2M>Y(ckkW>00<#KDaFN$7cn0%AWFc`uS#d2Y_O+NVC~&(HKJyaux@UhtOeT_%J{{t*De~ zHJh7J6q$VnJdY+4iL)I5doRZIJ!twJ7W6me4g62T{Hltl#)y)1K0B)q6nrp1@z~26bt=( zi9`bFbQ*jA0Vcl3hqGDA7%NIC31`gAUA|0aXJ?_i+N|R+24eOo-QSIG9wI*i%i_ke zZM0i0Bc<#-$ZNHlezv?!gCM9FV2A*eF-93v9>5Mhlg<+u)o*MiD@O zDD+XUR`BgNUmGFC*0pQbW@@$C^H!@B?Q*j(5<&F{jQmOQ&Q-UtR7-NiyqDV(kBmsl~ntRwv<#PG=m6a9B7~_mFn=v-P7&|eP z$&7tEI$CsHw-~eLdfwPbE;oEK`w3^1Qp>WaQcAC_t*r_n{9bi@fW@rYwoNU|Vw6&g zbDm_3rILxn$y_dXW;CBK7Cdi!WMstqb#d{RrKP1GtJP}sQ2-o=jdM;c%VL~!W{k14 z)=CKBM^U8zp}7A+`wL@BoR9x#)=mHb03~!qSaf7zbY(hYa%Ew3WdJfTF)%GKGA%JN zR536*Gch_fI4v+XIxsLq5ff(s001R)MObuXVRU6WZEs|0W_bWIFfceRFfuJNH&ih= fIyE#pG&C(RHaajcNaF4900000NkvXXu0mjfN!jGN literal 0 HcmV?d00001 diff --git a/Plugins/Wox.Plugin.Program/Programs.cs b/Plugins/Wox.Plugin.Program/Programs.cs index afcd078a13..9c4d2d423d 100644 --- a/Plugins/Wox.Plugin.Program/Programs.cs +++ b/Plugins/Wox.Plugin.Program/Programs.cs @@ -4,6 +4,7 @@ using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; +using System.Threading; using System.Windows; using Wox.Infrastructure; using Wox.Plugin.Program.ProgramSources; diff --git a/Plugins/Wox.Plugin.Program/Wox.Plugin.Program.csproj b/Plugins/Wox.Plugin.Program/Wox.Plugin.Program.csproj index 06c57a2cfb..5c24ffab52 100644 --- a/Plugins/Wox.Plugin.Program/Wox.Plugin.Program.csproj +++ b/Plugins/Wox.Plugin.Program/Wox.Plugin.Program.csproj @@ -81,6 +81,9 @@ PreserveNewest + + PreserveNewest + MSBuild:Compile Designer diff --git a/Wox.Core/Plugin/PluginManager.cs b/Wox.Core/Plugin/PluginManager.cs index 8620751f22..4ea7f5ebe8 100644 --- a/Wox.Core/Plugin/PluginManager.cs +++ b/Wox.Core/Plugin/PluginManager.cs @@ -100,7 +100,7 @@ namespace Wox.Core.Plugin PluginPair pair = pluginPair; ThreadPool.QueueUserWorkItem(o => { - using (new Timeit("Init Plugin: " + pair.Metadata.Name)) + using (new Timeit(string.Format("Init {0}", pair.Metadata.Name))) { pair.Plugin.Init(new PluginInitContext() { @@ -109,8 +109,7 @@ namespace Wox.Core.Plugin API = API }); } - }) - ; + }); } } diff --git a/Wox.Infrastructure/Hotkey/GlobalHotkey.cs b/Wox.Infrastructure/Hotkey/GlobalHotkey.cs index 8a6f31323b..d07b5180db 100644 --- a/Wox.Infrastructure/Hotkey/GlobalHotkey.cs +++ b/Wox.Infrastructure/Hotkey/GlobalHotkey.cs @@ -1,114 +1,17 @@ using System; -using System.Diagnostics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using Wox.Plugin; namespace Wox.Infrastructure.Hotkey { - public enum KeyEvent : int - { - /// - /// Key down - /// - WM_KEYDOWN = 256, - - /// - /// Key up - /// - WM_KEYUP = 257, - - /// - /// System key up - /// - WM_SYSKEYUP = 261, - - /// - /// System key down - /// - WM_SYSKEYDOWN = 260 - } - - public static class InterceptKeys - { - public delegate IntPtr LowLevelKeyboardProc(int nCode, UIntPtr wParam, IntPtr lParam); - - private static int WH_KEYBOARD_LL = 13; - - public static IntPtr SetHook(LowLevelKeyboardProc proc) - { - using (Process curProcess = Process.GetCurrentProcess()) - using (ProcessModule curModule = curProcess.MainModule) - { - return SetWindowsHookEx(WH_KEYBOARD_LL, proc, GetModuleHandle(curModule.ModuleName), 0); - } - } - - [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] - public static extern IntPtr SetWindowsHookEx(int idHook, LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId); - - [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] - [return: MarshalAs(UnmanagedType.Bool)] - public static extern bool UnhookWindowsHookEx(IntPtr hhk); - - [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] - public static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, UIntPtr wParam, IntPtr lParam); - - [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] - public static extern IntPtr GetModuleHandle(string lpModuleName); - - [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)] - public static extern short GetKeyState(int keyCode); - - [DllImport("user32.dll")] - internal static extern uint SendInput(uint nInputs, [MarshalAs(UnmanagedType.LPArray), In] INPUT[] pInputs, int cbSize); - } - - [StructLayout(LayoutKind.Explicit)] - public struct INPUT - { - [FieldOffset(0)] - public Int32 type;//0-MOUSEINPUT;1-KEYBDINPUT;2-HARDWAREINPUT - [FieldOffset(4)] - public KEYBDINPUT ki; - [FieldOffset(4)] - public MOUSEINPUT mi; - [FieldOffset(4)] - public HARDWAREINPUT hi; - } - [StructLayout(LayoutKind.Sequential)] - public struct MOUSEINPUT - { - public Int32 dx; - public Int32 dy; - public Int32 mouseData; - public Int32 dwFlags; - public Int32 time; - public IntPtr dwExtraInfo; - } - [StructLayout(LayoutKind.Sequential)] - public struct KEYBDINPUT - { - public Int16 wVk; - public Int16 wScan; - public Int32 dwFlags; - public Int32 time; - public IntPtr dwExtraInfo; - } - [StructLayout(LayoutKind.Sequential)] - public struct HARDWAREINPUT - { - public Int32 uMsg; - public Int16 wParamL; - public Int16 wParamH; - } - /// /// Listens keyboard globally. /// Uses WH_KEYBOARD_LL. /// public class GlobalHotkey : IDisposable { + private static GlobalHotkey instance; private InterceptKeys.LowLevelKeyboardProc hookedLowLevelKeyboardProc; private IntPtr hookId = IntPtr.Zero; public delegate bool KeyboardCallback(KeyEvent keyEvent, int vkCode, SpecialKeyState state); @@ -120,7 +23,19 @@ namespace Wox.Infrastructure.Hotkey private const int VK_ALT = 0x12; private const int VK_WIN = 91; - public GlobalHotkey() + public static GlobalHotkey Instance + { + get + { + if (instance == null) + { + instance = new GlobalHotkey(); + } + return instance; + } + } + + private GlobalHotkey() { // We have to store the LowLevelKeyboardProc, so that it is not garbage collected runtime hookedLowLevelKeyboardProc = LowLevelKeyboardProc; diff --git a/Wox.Infrastructure/Hotkey/InterceptKeys.cs b/Wox.Infrastructure/Hotkey/InterceptKeys.cs new file mode 100644 index 0000000000..ef8dd576df --- /dev/null +++ b/Wox.Infrastructure/Hotkey/InterceptKeys.cs @@ -0,0 +1,38 @@ +using System; +using System.Diagnostics; +using System.Runtime.InteropServices; + +namespace Wox.Infrastructure.Hotkey +{ + internal static class InterceptKeys + { + public delegate IntPtr LowLevelKeyboardProc(int nCode, UIntPtr wParam, IntPtr lParam); + + private const int WH_KEYBOARD_LL = 13; + + public static IntPtr SetHook(LowLevelKeyboardProc proc) + { + using (Process curProcess = Process.GetCurrentProcess()) + using (ProcessModule curModule = curProcess.MainModule) + { + return SetWindowsHookEx(WH_KEYBOARD_LL, proc, GetModuleHandle(curModule.ModuleName), 0); + } + } + + [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] + public static extern IntPtr SetWindowsHookEx(int idHook, LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId); + + [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool UnhookWindowsHookEx(IntPtr hhk); + + [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] + public static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, UIntPtr wParam, IntPtr lParam); + + [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] + public static extern IntPtr GetModuleHandle(string lpModuleName); + + [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)] + public static extern short GetKeyState(int keyCode); + } +} \ No newline at end of file diff --git a/Wox.Infrastructure/Hotkey/KeyEvent.cs b/Wox.Infrastructure/Hotkey/KeyEvent.cs new file mode 100644 index 0000000000..f1b6eefd0c --- /dev/null +++ b/Wox.Infrastructure/Hotkey/KeyEvent.cs @@ -0,0 +1,25 @@ +namespace Wox.Infrastructure.Hotkey +{ + public enum KeyEvent:int + { + /// + /// Key down + /// + WM_KEYDOWN = 256, + + /// + /// Key up + /// + WM_KEYUP = 257, + + /// + /// System key up + /// + WM_SYSKEYUP = 261, + + /// + /// System key down + /// + WM_SYSKEYDOWN = 260 + } +} \ No newline at end of file diff --git a/Wox.Infrastructure/Wox.Infrastructure.csproj b/Wox.Infrastructure/Wox.Infrastructure.csproj index 4c23af6316..a2b334b077 100644 --- a/Wox.Infrastructure/Wox.Infrastructure.csproj +++ b/Wox.Infrastructure/Wox.Infrastructure.csproj @@ -59,6 +59,8 @@ + + diff --git a/Wox.Plugin/EventHandler.cs b/Wox.Plugin/EventHandler.cs index 0fd8461deb..f3ef7e2e2d 100644 --- a/Wox.Plugin/EventHandler.cs +++ b/Wox.Plugin/EventHandler.cs @@ -8,6 +8,15 @@ namespace Wox.Plugin { public delegate void WoxKeyDownEventHandler(object sender, WoxKeyDownEventArgs e); + /// + /// Global keyboard events + /// + /// WM_KEYDOWN = 256,WM_KEYUP = 257,WM_SYSKEYUP = 261,WM_SYSKEYDOWN = 260 + /// + /// + /// return true to continue handling, return false to intercept system handling + public delegate bool WoxGlobalKeyboardEventHandler(int keyevent, int vkcode, SpecialKeyState state); + public class WoxKeyDownEventArgs { public string Query { get; set; } diff --git a/Wox.Plugin/IPublicAPI.cs b/Wox.Plugin/IPublicAPI.cs index 49279d7900..231faf4a7f 100644 --- a/Wox.Plugin/IPublicAPI.cs +++ b/Wox.Plugin/IPublicAPI.cs @@ -41,5 +41,7 @@ namespace Wox.Plugin List GetAllPlugins(); event WoxKeyDownEventHandler BackKeyDownEvent; + + event WoxGlobalKeyboardEventHandler GlobalKeyboardEvent; } } diff --git a/Wox/HotkeyControl.xaml.cs b/Wox/HotkeyControl.xaml.cs index e1650d197b..1725f64019 100644 --- a/Wox/HotkeyControl.xaml.cs +++ b/Wox/HotkeyControl.xaml.cs @@ -43,7 +43,7 @@ namespace Wox Key key = (e.Key == Key.System ? e.SystemKey : e.Key); string text = string.Empty; - SpecialKeyState specialKeyState = new GlobalHotkey().CheckModifiers(); + SpecialKeyState specialKeyState = GlobalHotkey.Instance.CheckModifiers(); if (specialKeyState.AltPressed) { text += "Alt"; diff --git a/Wox/MainWindow.xaml.cs b/Wox/MainWindow.xaml.cs index ed76bf6351..54061baf14 100644 --- a/Wox/MainWindow.xaml.cs +++ b/Wox/MainWindow.xaml.cs @@ -1,8 +1,10 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Diagnostics; -using System.IO; +using System.Drawing; using System.Linq; +using System.Net; using System.Threading; using System.Windows; using System.Windows.Controls; @@ -10,8 +12,6 @@ using System.Windows.Forms; using System.Windows.Input; using System.Windows.Interop; using System.Windows.Media.Animation; -using WindowsInput; -using WindowsInput.Native; using NHotkey; using NHotkey.Wpf; using Wox.Core.i18n; @@ -21,25 +21,18 @@ using Wox.Core.UserSettings; using Wox.Helper; using Wox.Infrastructure; using Wox.Infrastructure.Hotkey; -using Wox.Infrastructure.Storage; using Wox.Plugin; using Wox.Storage; using Wox.Update; -using Application = System.Windows.Application; using Brushes = System.Windows.Media.Brushes; using Color = System.Windows.Media.Color; using ContextMenu = System.Windows.Forms.ContextMenu; +using DataFormats = System.Windows.DataFormats; using DragEventArgs = System.Windows.DragEventArgs; -using FontFamily = System.Windows.Media.FontFamily; using KeyEventArgs = System.Windows.Input.KeyEventArgs; using MenuItem = System.Windows.Forms.MenuItem; using MessageBox = System.Windows.MessageBox; -using MouseButton = System.Windows.Input.MouseButton; -using Path = System.IO.Path; -using Rectangle = System.Drawing.Rectangle; -using TextBox = System.Windows.Controls.TextBox; using ToolTip = System.Windows.Controls.ToolTip; -using Wox.Infrastructure.Logger; namespace Wox { @@ -48,10 +41,6 @@ namespace Wox #region Properties - private static readonly object locker = new object(); - public static bool initialized = false; - - private static readonly List waitShowResultList = new List(); private readonly Storyboard progressBarStoryboard = new Storyboard(); private NotifyIcon notifyIcon; private bool queryHasReturn; @@ -59,7 +48,6 @@ namespace Wox private ToolTip toolTip = new ToolTip(); private bool ignoreTextChange = false; - private readonly GlobalHotkey globalHotkey = new GlobalHotkey(); #endregion @@ -143,6 +131,7 @@ namespace Wox } public event WoxKeyDownEventHandler BackKeyDownEvent; + public event WoxGlobalKeyboardEventHandler GlobalKeyboardEvent; public void PushResults(Query query, PluginMetadata plugin, List results) { @@ -166,26 +155,27 @@ namespace Wox public MainWindow() { InitializeComponent(); - + ThreadPool.SetMaxThreads(30, 10); + ThreadPool.SetMinThreads(10, 5); if (UserSettingStorage.Instance.OpacityMode == OpacityMode.LayeredWindow) + { this.AllowsTransparency = true; + } - System.Net.WebRequest.RegisterPrefix("data", new DataWebRequestFactory()); - + WebRequest.RegisterPrefix("data", new DataWebRequestFactory()); + GlobalHotkey.Instance.hookedKeyboardCallback += KListener_hookedKeyboardCallback; progressBar.ToolTip = toolTip; InitialTray(); pnlResult.LeftMouseClickEvent += SelectResult; pnlContextMenu.LeftMouseClickEvent += SelectResult; pnlResult.RightMouseClickEvent += pnlResult_RightMouseClickEvent; - ThreadPool.SetMaxThreads(30, 10); ThemeManager.Theme.ChangeTheme(UserSettingStorage.Instance.Theme); InternationalizationManager.Internationalization.ChangeLanguage(UserSettingStorage.Instance.Language); SetHotkey(UserSettingStorage.Instance.Hotkey, OnHotkey); SetCustomPluginHotkey(); - Closing += MainWindow_Closing; //since MainWIndow implement IPublicAPI, so we need to finish ctor MainWindow object before //PublicAPI invoke in plugin init methods. E.g FolderPlugin @@ -199,7 +189,16 @@ namespace Wox Thread.Sleep(50); PreLoadImages(); }); - ThreadPool.QueueUserWorkItem(o => CheckUpdate()); + CheckUpdate(); + } + + private bool KListener_hookedKeyboardCallback(KeyEvent keyevent, int vkcode, SpecialKeyState state) + { + if (GlobalKeyboardEvent != null) + { + return GlobalKeyboardEvent((int)keyevent, vkcode, state); + } + return true; } private void PreLoadImages() @@ -214,18 +213,21 @@ namespace Wox void CheckUpdate() { - Release release = new UpdateChecker().CheckUpgrade(); - if (release != null && !UserSettingStorage.Instance.DontPromptUpdateMsg) + ThreadPool.QueueUserWorkItem(o => { - Dispatcher.Invoke(new Action(() => + Release release = new UpdateChecker().CheckUpgrade(); + if (release != null && !UserSettingStorage.Instance.DontPromptUpdateMsg) { - NewVersionWindow newVersinoWindow = new NewVersionWindow(); - newVersinoWindow.Show(); - })); - } + Dispatcher.Invoke(new Action(() => + { + NewVersionWindow newVersinoWindow = new NewVersionWindow(); + newVersinoWindow.Show(); + })); + } + }); } - void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e) + void MainWindow_Closing(object sender, CancelEventArgs e) { UserSettingStorage.Instance.WindowLeft = Left; UserSettingStorage.Instance.WindowTop = Top; @@ -370,7 +372,7 @@ namespace Wox } }, TimeSpan.FromSeconds(0), lastQuery); } - }, TimeSpan.FromMilliseconds(ShouldNotDelayQuery ? 0 : 150)); + }, TimeSpan.FromMilliseconds(ShouldNotDelayQuery ? 0 : 200)); } private void BackToResultMode() @@ -482,7 +484,7 @@ namespace Wox break; case Key.Tab: - if (globalHotkey.CheckModifiers().ShiftPressed) + if (GlobalHotkey.Instance.CheckModifiers().ShiftPressed) { SelectPrevItem(); } @@ -534,7 +536,7 @@ namespace Wox case Key.Enter: Result activeResult = GetActiveResult(); - if (globalHotkey.CheckModifiers().ShiftPressed) + if (GlobalHotkey.Instance.CheckModifiers().ShiftPressed) { ShowContextMenu(activeResult); } @@ -600,7 +602,7 @@ namespace Wox { bool hideWindow = result.Action(new ActionContext() { - SpecialKeyState = globalHotkey.CheckModifiers() + SpecialKeyState = GlobalHotkey.Instance.CheckModifiers() }); if (hideWindow) { @@ -611,7 +613,7 @@ namespace Wox } } - public void OnUpdateResultView(List list) + private void OnUpdateResultView(List list) { queryHasReturn = true; progressBar.Dispatcher.Invoke(new Action(StopProgress)); @@ -663,10 +665,10 @@ namespace Wox private void MainWindow_OnDrop(object sender, DragEventArgs e) { - if (e.Data.GetDataPresent(System.Windows.DataFormats.FileDrop)) + if (e.Data.GetDataPresent(DataFormats.FileDrop)) { // Note that you can have more than one file. - string[] files = (string[])e.Data.GetData(System.Windows.DataFormats.FileDrop); + string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); if (files[0].ToLower().EndsWith(".wox")) { PluginManager.InstallPlugin(files[0]); diff --git a/Wox/SettingWindow.xaml.cs b/Wox/SettingWindow.xaml.cs index 56f5f3435c..b7c1ca520f 100644 --- a/Wox/SettingWindow.xaml.cs +++ b/Wox/SettingWindow.xaml.cs @@ -105,48 +105,48 @@ namespace Wox { Title = "Wox is an effective launcher for windows", SubTitle = "Wox provide bundles of features let you access infomations quickly.", - IcoPath = "Images/work.png", + IcoPath = "Images/app.png", PluginDirectory = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) }, new Result() { Title = "Search applications", SubTitle = "Search applications, files (via everything plugin) and browser bookmarks", - IcoPath = "Images/work.png", + IcoPath = "Images/app.png", PluginDirectory = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) }, new Result() { Title = "Search web contents with shortcuts", SubTitle = "e.g. search google with g keyword or youtube keyword)", - IcoPath = "Images/work.png", + IcoPath = "Images/app.png", PluginDirectory = Path.GetDirectoryName(Application.ExecutablePath) }, new Result() { Title = "clipboard history ", - IcoPath = "Images/work.png", + IcoPath = "Images/app.png", PluginDirectory = Path.GetDirectoryName(Application.ExecutablePath) }, new Result() { Title = "Themes support", SubTitle = "get more themes from http://www.getwox.com/theme", - IcoPath = "Images/work.png", + IcoPath = "Images/app.png", PluginDirectory = Path.GetDirectoryName(Application.ExecutablePath) }, new Result() { Title = "Plugins support", SubTitle = "get more plugins from http://www.getwox.com/plugin", - IcoPath = "Images/work.png", + IcoPath = "Images/app.png", PluginDirectory = Path.GetDirectoryName(Application.ExecutablePath) }, new Result() { Title = "Wox is an open-source software", SubTitle = "Wox benefits from the open-source community a lot", - IcoPath = "Images/work.png", + IcoPath = "Images/app.png", PluginDirectory = Path.GetDirectoryName(Application.ExecutablePath) } });