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('\\')); + } + } } } 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.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) 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/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) 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