Merge pull request #61 from cxfksword/master

Fix Alt+Space hotkey bug
This commit is contained in:
qianlifeng 2014-03-22 16:40:42 +08:00
commit 51eda2ef74
7 changed files with 153 additions and 13 deletions

View File

@ -10,12 +10,68 @@ namespace Wox.Plugin.System
{ {
public class DirectoryIndicator : BaseSystemPlugin public class DirectoryIndicator : BaseSystemPlugin
{ {
private static List<string> driverNames = null;
private static Dictionary<string, DirectoryInfo[]> parentDirectories = new Dictionary<string, DirectoryInfo[]>();
protected override List<Result> QueryInternal(Query query) protected override List<Result> QueryInternal(Query query)
{ {
List<Result> results = new List<Result>(); List<Result> results = new List<Result>();
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)) if (Directory.Exists(query.RawQuery))
{
// show all child directory
if (input.EndsWith("\\") || input.EndsWith("/"))
{
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)
{
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);
}
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 Result result = new Result
{ {
@ -32,11 +88,57 @@ namespace Wox.Plugin.System
results.Add(result); 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; return results;
} }
protected override void InitInternal(PluginInitContext context) protected override void InitInternal(PluginInitContext context)
{ {
if (driverNames == null)
{
driverNames = new List<string>();
var allDrives = DriveInfo.GetDrives();
foreach (var driver in allDrives)
{
driverNames.Add(driver.Name.ToLower().TrimEnd('\\'));
}
}
} }
} }

View File

@ -9,7 +9,7 @@ namespace Wox.Plugin.System.ProgramSources
public class FileSystemProgramSource : AbstractProgramSource public class FileSystemProgramSource : AbstractProgramSource
{ {
public string BaseDirectory; public string BaseDirectory;
public List<string> Suffixes = new List<string>() { "lnk", "exe" }; public List<string> Suffixes = new List<string>() { "lnk", "exe", "appref-ms" };
public FileSystemProgramSource(string baseDirectory) public FileSystemProgramSource(string baseDirectory)
{ {

View File

@ -124,6 +124,10 @@ namespace Wox.Plugin.System
}); });
installedList.AddRange(list); 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) private void ScoreFilter(Program p)

View File

@ -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);
/// <summary>
/// disable windows toolbar's control box
/// this will also disable system menu with Alt+Space hotkey
/// </summary>
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);
}
}
}

View File

@ -18,7 +18,7 @@ namespace Wox
private static List<string> selfExts = new List<string>() { private static List<string> selfExts = new List<string>() {
".exe", ".lnk", ".exe", ".lnk",
".ani", ".cur", ".ani", ".cur",
".sln" ".sln", ".appref-ms"
}; };
private static ImageSource GetIcon(string fileName) private static ImageSource GetIcon(string fileName)

View File

@ -90,6 +90,8 @@ namespace Wox
InitProgressbarAnimation(); InitProgressbarAnimation();
//only works for win7+ //only works for win7+
//DwmDropShadow.DropShadowToWindow(this); //DwmDropShadow.DropShadowToWindow(this);
WindowIntelopHelper.DisableControlBox(this);
} }
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)

View File

@ -107,6 +107,7 @@
<Compile Include="Commands\CommandFactory.cs" /> <Compile Include="Commands\CommandFactory.cs" />
<Compile Include="Commands\PluginCommand.cs" /> <Compile Include="Commands\PluginCommand.cs" />
<Compile Include="Commands\SystemCommand.cs" /> <Compile Include="Commands\SystemCommand.cs" />
<Compile Include="Helper\WindowIntelopHelper.cs" />
<Compile Include="ProgramSourceSetting.xaml.cs"> <Compile Include="ProgramSourceSetting.xaml.cs">
<DependentUpon>ProgramSourceSetting.xaml</DependentUpon> <DependentUpon>ProgramSourceSetting.xaml</DependentUpon>
</Compile> </Compile>