From eb094eaebbe8842d329b791de0c1ff697a7f935a Mon Sep 17 00:00:00 2001 From: cxfksword Date: Sat, 22 Mar 2014 13:50:20 +0800 Subject: [PATCH 1/4] Filter duplicate program item --- Wox.Plugin.System/Programs.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Wox.Plugin.System/Programs.cs b/Wox.Plugin.System/Programs.cs index 9d61401325..0e657152c1 100644 --- a/Wox.Plugin.System/Programs.cs +++ b/Wox.Plugin.System/Programs.cs @@ -124,6 +124,10 @@ namespace Wox.Plugin.System }); installedList.AddRange(list); } + + // filter duplicate program + installedList = installedList.GroupBy(x => new { x.ExecutePath, x.ExecuteName }) + .Select(g => g.First()).ToList(); } private void ScoreFilter(Program p) From dbdd6c701b0ec8a77cfc8d85d6645f5ccdc2087f Mon Sep 17 00:00:00 2001 From: cxfksword Date: Sat, 22 Mar 2014 14:01:36 +0800 Subject: [PATCH 2/4] Add support ClickOnce application ex. Github for Windows use this file extension --- Wox.Plugin.System/ProgramSources/FileSystemProgramSource.cs | 2 +- Wox/ImagePathConverter.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Wox.Plugin.System/ProgramSources/FileSystemProgramSource.cs b/Wox.Plugin.System/ProgramSources/FileSystemProgramSource.cs index 57440ed1f2..07b6d8a6a2 100644 --- a/Wox.Plugin.System/ProgramSources/FileSystemProgramSource.cs +++ b/Wox.Plugin.System/ProgramSources/FileSystemProgramSource.cs @@ -9,7 +9,7 @@ namespace Wox.Plugin.System.ProgramSources public class FileSystemProgramSource : AbstractProgramSource { public string BaseDirectory; - public List Suffixes = new List() { "lnk", "exe" }; + public List Suffixes = new List() { "lnk", "exe", "appref-ms" }; public FileSystemProgramSource(string baseDirectory) { diff --git a/Wox/ImagePathConverter.cs b/Wox/ImagePathConverter.cs index 0879cf78a4..c6122869b1 100644 --- a/Wox/ImagePathConverter.cs +++ b/Wox/ImagePathConverter.cs @@ -18,7 +18,7 @@ namespace Wox private static List selfExts = new List() { ".exe", ".lnk", ".ani", ".cur", - ".sln" + ".sln", ".appref-ms" }; private static ImageSource GetIcon(string fileName) From 3b092763952d7cdf8dc3b3bec21f3674caa8217a Mon Sep 17 00:00:00 2001 From: cxfksword Date: Sat, 22 Mar 2014 15:02:28 +0800 Subject: [PATCH 3/4] Fix Alt+Space hotkey affect by system if no disable control box, sometimes awake Wox with alt+space hotkey, the first input key is swallowed by system --- Wox/Helper/WindowIntelopHelper.cs | 31 +++++++++++++++++++++++++++++++ Wox/MainWindow.xaml.cs | 2 ++ Wox/Wox.csproj | 1 + 3 files changed, 34 insertions(+) create mode 100644 Wox/Helper/WindowIntelopHelper.cs diff --git a/Wox/Helper/WindowIntelopHelper.cs b/Wox/Helper/WindowIntelopHelper.cs new file mode 100644 index 0000000000..2e5179b7b4 --- /dev/null +++ b/Wox/Helper/WindowIntelopHelper.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Runtime.InteropServices; +using System.Windows; + +namespace Wox.Helper +{ + public class WindowIntelopHelper + { + private const int GWL_STYLE = -16; //WPF's Message code for Title Bar's Style + private const int WS_SYSMENU = 0x80000; //WPF's Message code for System Menu + + [DllImport("user32.dll", SetLastError = true)] + private static extern int GetWindowLong(IntPtr hWnd, int nIndex); + + [DllImport("user32.dll")] + private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong); + + /// + /// disable windows toolbar's control box + /// this will also disable system menu with Alt+Space hotkey + /// + public static void DisableControlBox(Window win) + { + var hwnd = new System.Windows.Interop.WindowInteropHelper(win).Handle; + SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_SYSMENU); + } + } +} diff --git a/Wox/MainWindow.xaml.cs b/Wox/MainWindow.xaml.cs index c11ebf1a44..4256d4920f 100644 --- a/Wox/MainWindow.xaml.cs +++ b/Wox/MainWindow.xaml.cs @@ -90,6 +90,8 @@ namespace Wox InitProgressbarAnimation(); //only works for win7+ //DwmDropShadow.DropShadowToWindow(this); + + WindowIntelopHelper.DisableControlBox(this); } private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) diff --git a/Wox/Wox.csproj b/Wox/Wox.csproj index e2c64949b2..3cefced8cf 100644 --- a/Wox/Wox.csproj +++ b/Wox/Wox.csproj @@ -107,6 +107,7 @@ + ProgramSourceSetting.xaml From f30f6378ac6b28c51a9b51b778bbdf12e9810654 Mon Sep 17 00:00:00 2001 From: cxfksword Date: Sat, 22 Mar 2014 16:25:22 +0800 Subject: [PATCH 4/4] Add Directory Plugin support list child directory and search --- Wox.Plugin.System/DirectoryIndicator.cs | 124 +++++++++++++++++++++--- 1 file changed, 113 insertions(+), 11 deletions(-) diff --git a/Wox.Plugin.System/DirectoryIndicator.cs b/Wox.Plugin.System/DirectoryIndicator.cs index 6d6a6878d5..dfc8dcc6b0 100644 --- a/Wox.Plugin.System/DirectoryIndicator.cs +++ b/Wox.Plugin.System/DirectoryIndicator.cs @@ -10,33 +10,135 @@ namespace Wox.Plugin.System { public class DirectoryIndicator : BaseSystemPlugin { + private static List driverNames = null; + private static Dictionary parentDirectories = new Dictionary(); + protected override List QueryInternal(Query query) { List results = new List(); - if (string.IsNullOrEmpty(query.RawQuery)) return results; + if (string.IsNullOrEmpty(query.RawQuery)) + { + // clear the cache + if (parentDirectories.Count > 0) + parentDirectories.Clear(); + + return results; + } + + var input = query.RawQuery.ToLower(); + if (driverNames.FirstOrDefault(x => input.StartsWith(x)) == null) return results; if (Directory.Exists(query.RawQuery)) { - Result result = new Result + // show all child directory + if (input.EndsWith("\\") || input.EndsWith("/")) { - Title = "Open this directory", - SubTitle = string.Format("path: {0}", query.RawQuery), - Score = 50, - IcoPath = "Images/folder.png", - Action = (c) => + var dirInfo = new DirectoryInfo(query.RawQuery); + var dirs = dirInfo.GetDirectories(); + + var parentDirKey = input.TrimEnd('\\', '/'); + if (!parentDirectories.ContainsKey(parentDirKey)) + parentDirectories.Add(parentDirKey, dirs); + + foreach (var dir in dirs) { - Process.Start(query.RawQuery); - return true; + if ((dir.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) + continue; + + var dirPath = dir.FullName; + Result result = new Result + { + Title = dir.Name, + SubTitle = "Open this directory", + IcoPath = "Images/folder.png", + Action = (c) => + { + Process.Start(dirPath); + return true; + } + }; + results.Add(result); } - }; - results.Add(result); + + if (results.Count == 0) + { + Result result = new Result + { + Title = "No files in this directory", + SubTitle = "", + IcoPath = "Images/folder.png", + }; + results.Add(result); + } + } + else + { + Result result = new Result + { + Title = "Open this directory", + SubTitle = string.Format("path: {0}", query.RawQuery), + Score = 50, + IcoPath = "Images/folder.png", + Action = (c) => + { + Process.Start(query.RawQuery); + return true; + } + }; + results.Add(result); + } + } + // change to search in current directory + var parentDir = Path.GetDirectoryName(input); + if (!string.IsNullOrEmpty(parentDir) && results.Count == 0) + { + parentDir = parentDir.TrimEnd('\\', '/'); + if (parentDirectories.ContainsKey(parentDir)) + { + var dirs = parentDirectories[parentDir]; + var queryFileName = Path.GetFileName(query.RawQuery).ToLower(); + foreach (var dir in dirs) + { + if ((dir.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) + continue; + + if (!dir.Name.ToLower().StartsWith(queryFileName)) + continue; + + var dirPath = dir.FullName; + Result result = new Result + { + Title = dir.Name, + SubTitle = "Open this directory", + IcoPath = "Images/folder.png", + Action = (c) => + { + Process.Start(dirPath); + return true; + } + }; + results.Add(result); + } + } + } + + return results; } protected override void InitInternal(PluginInitContext context) { + if (driverNames == null) + { + driverNames = new List(); + var allDrives = DriveInfo.GetDrives(); + foreach (var driver in allDrives) + { + driverNames.Add(driver.Name.ToLower().TrimEnd('\\')); + } + } } }