mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-04 11:59:07 +08:00
commit
51eda2ef74
@ -10,33 +10,135 @@ namespace Wox.Plugin.System
|
||||
{
|
||||
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)
|
||||
{
|
||||
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))
|
||||
{
|
||||
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<string>();
|
||||
var allDrives = DriveInfo.GetDrives();
|
||||
foreach (var driver in allDrives)
|
||||
{
|
||||
driverNames.Add(driver.Name.ToLower().TrimEnd('\\'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ namespace Wox.Plugin.System.ProgramSources
|
||||
public class FileSystemProgramSource : AbstractProgramSource
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
@ -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)
|
||||
|
31
Wox/Helper/WindowIntelopHelper.cs
Normal file
31
Wox/Helper/WindowIntelopHelper.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
@ -18,7 +18,7 @@ namespace Wox
|
||||
private static List<string> selfExts = new List<string>() {
|
||||
".exe", ".lnk",
|
||||
".ani", ".cur",
|
||||
".sln"
|
||||
".sln", ".appref-ms"
|
||||
};
|
||||
|
||||
private static ImageSource GetIcon(string fileName)
|
||||
|
@ -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)
|
||||
|
@ -107,6 +107,7 @@
|
||||
<Compile Include="Commands\CommandFactory.cs" />
|
||||
<Compile Include="Commands\PluginCommand.cs" />
|
||||
<Compile Include="Commands\SystemCommand.cs" />
|
||||
<Compile Include="Helper\WindowIntelopHelper.cs" />
|
||||
<Compile Include="ProgramSourceSetting.xaml.cs">
|
||||
<DependentUpon>ProgramSourceSetting.xaml</DependentUpon>
|
||||
</Compile>
|
||||
|
Loading…
Reference in New Issue
Block a user