mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 03:07:04 +02:00
Add custom context menu setting for findfile plugin and improve the search speed.
This commit is contained in:
46
Plugins/Wox.Plugin.FindFile/FindFileContextMenuStorage.cs
Normal file
46
Plugins/Wox.Plugin.FindFile/FindFileContextMenuStorage.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
using Wox.Infrastructure.Storage;
|
||||
|
||||
namespace Wox.Plugin.FindFile
|
||||
{
|
||||
public class FindFileContextMenuStorage : BaseStorage<FindFileContextMenuStorage>
|
||||
{
|
||||
[JsonProperty]
|
||||
public List<ContextMenu> ContextMenus = new List<ContextMenu>();
|
||||
|
||||
protected override string ConfigName
|
||||
{
|
||||
get { return "FindFileContextMenu"; }
|
||||
}
|
||||
|
||||
protected override FindFileContextMenuStorage LoadDefaultConfig()
|
||||
{
|
||||
ContextMenus = new List<ContextMenu>()
|
||||
{
|
||||
new ContextMenu()
|
||||
{
|
||||
Name = "Open Containing Folder",
|
||||
Command = "explorer.exe",
|
||||
Argument = " /select \"{path}\""
|
||||
}
|
||||
};
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public class ContextMenu
|
||||
{
|
||||
[JsonProperty]
|
||||
public string Name { get; set; }
|
||||
|
||||
[JsonProperty]
|
||||
public string Command { get; set; }
|
||||
|
||||
[JsonProperty]
|
||||
public string Argument { get; set; }
|
||||
}
|
||||
}
|
||||
BIN
Plugins/Wox.Plugin.FindFile/Images/list.png
Normal file
BIN
Plugins/Wox.Plugin.FindFile/Images/list.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.7 KiB |
@@ -39,7 +39,7 @@ namespace Wox.Plugin.FindFile.MFTSearch
|
||||
{
|
||||
if (string.IsNullOrEmpty(item)) return new List<MFTSearchRecord>();
|
||||
|
||||
List<USNRecord> found = cache.FindByName(item);
|
||||
List<USNRecord> found = cache.FindByName(item,100);
|
||||
found.ForEach(x => FillPath(x.VolumeName, x, cache));
|
||||
return found.ConvertAll(o => new MFTSearchRecord(o));
|
||||
}
|
||||
|
||||
@@ -71,17 +71,22 @@ namespace Wox.Plugin.FindFile.MFTSearch
|
||||
}
|
||||
}
|
||||
|
||||
public List<USNRecord> FindByName(string filename)
|
||||
public List<USNRecord> FindByName(string filename, long maxResult = -1)
|
||||
{
|
||||
filename = filename.ToLower();
|
||||
var fileQuery = from filesInVolumeDic in VolumeRecords.Values
|
||||
from eachFilePair in filesInVolumeDic
|
||||
where eachFilePair.Value.Name.ToLower().Contains(filename)
|
||||
select eachFilePair.Value;
|
||||
|
||||
List<USNRecord> result = new List<USNRecord>();
|
||||
|
||||
result.AddRange(fileQuery);
|
||||
foreach (Dictionary<ulong, USNRecord> dictionary in VolumeRecords.Values)
|
||||
{
|
||||
foreach (var usnRecord in dictionary)
|
||||
{
|
||||
if (usnRecord.Value.Name.IndexOf(filename, StringComparison.OrdinalIgnoreCase) >= 0)
|
||||
{
|
||||
result.Add(usnRecord.Value);
|
||||
if (maxResult > 0 && result.Count() >= maxResult) break;
|
||||
}
|
||||
if (maxResult > 0 && result.Count() >= maxResult) break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -5,12 +5,13 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using System.Text;
|
||||
using System.Windows.Controls;
|
||||
using Wox.Infrastructure;
|
||||
using Wox.Plugin.FindFile.MFTSearch;
|
||||
|
||||
namespace Wox.Plugin.FindFile
|
||||
{
|
||||
public class Main : IPlugin
|
||||
public class Main : IPlugin, ISettingProvider
|
||||
{
|
||||
private PluginInitContext context;
|
||||
private bool initial = false;
|
||||
@@ -78,27 +79,36 @@ namespace Wox.Plugin.FindFile
|
||||
|
||||
if (!record.IsFolder)
|
||||
{
|
||||
contextMenus.Add(new Result()
|
||||
foreach (ContextMenu contextMenu in FindFileContextMenuStorage.Instance.ContextMenus)
|
||||
{
|
||||
Title = "Open Containing Folder",
|
||||
Action = _ =>
|
||||
contextMenus.Add(new Result()
|
||||
{
|
||||
try
|
||||
Title = contextMenu.Name,
|
||||
Action = _ =>
|
||||
{
|
||||
Process.Start("explorer.exe", string.Format("/select, \"{0}\"", record.FullPath));
|
||||
}
|
||||
catch
|
||||
{
|
||||
context.API.ShowMsg("Can't open " + record.FullPath, string.Empty, string.Empty);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
IcoPath = "Images/folder.png"
|
||||
});
|
||||
string argument = contextMenu.Argument.Replace("{path}", record.FullPath);
|
||||
try
|
||||
{
|
||||
Process.Start(contextMenu.Command,argument);
|
||||
}
|
||||
catch
|
||||
{
|
||||
context.API.ShowMsg("Can't start " + record.FullPath, string.Empty, string.Empty);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
IcoPath = "Images/list.png"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return contextMenus;
|
||||
}
|
||||
|
||||
public Control CreateSettingPanel()
|
||||
{
|
||||
return new Setting();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile />
|
||||
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
|
||||
<RestorePackages>true</RestorePackages>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
@@ -33,15 +35,36 @@
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\packages\log4net.2.0.3\lib\net35-full\log4net.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\packages\Newtonsoft.Json.6.0.5\lib\net35\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="PresentationCore" />
|
||||
<Reference Include="PresentationFramework" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Windows.Controls.Input.Toolkit">
|
||||
<HintPath>..\..\packages\WPFToolkit.3.5.50211.1\lib\System.Windows.Controls.Input.Toolkit.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Windows.Controls.Layout.Toolkit">
|
||||
<HintPath>..\..\packages\WPFToolkit.3.5.50211.1\lib\System.Windows.Controls.Layout.Toolkit.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="WindowsBase" />
|
||||
<Reference Include="WPFToolkit, Version=3.5.40128.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\WPFToolkit.3.5.50211.1\lib\WPFToolkit.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="FindFileContextMenuStorage.cs" />
|
||||
<Compile Include="Main.cs" />
|
||||
<Compile Include="MFTSearch\MFTSearcher.cs" />
|
||||
<Compile Include="MFTSearch\MFTSearcherCache.cs" />
|
||||
@@ -51,6 +74,9 @@
|
||||
<Compile Include="MFTSearch\USNRecord.cs" />
|
||||
<Compile Include="MFTSearch\VolumeMonitor.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Setting.xaml.cs">
|
||||
<DependentUpon>Setting.xaml</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Wox.Infrastructure\Wox.Infrastructure.csproj">
|
||||
@@ -72,6 +98,9 @@
|
||||
<Content Include="Images\file.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Images\list.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Images\open.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
@@ -80,11 +109,19 @@
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
<None Include="plugin.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Page Include="Setting.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
|
||||
6
Plugins/Wox.Plugin.FindFile/packages.config
Normal file
6
Plugins/Wox.Plugin.FindFile/packages.config
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="log4net" version="2.0.3" targetFramework="net35" />
|
||||
<package id="Newtonsoft.Json" version="6.0.5" targetFramework="net35" />
|
||||
<package id="WPFToolkit" version="3.5.50211.1" targetFramework="net35" />
|
||||
</packages>
|
||||
20
Plugins/Wox.Plugin.FindFile/setting.xaml
Normal file
20
Plugins/Wox.Plugin.FindFile/setting.xaml
Normal file
@@ -0,0 +1,20 @@
|
||||
<UserControl x:Class="Wox.Plugin.FindFile.Setting"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:controls="http://schemas.microsoft.com/wpf/2008/toolkit"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="300" d:DesignWidth="600">
|
||||
<TabControl Height="auto" Margin="10" VerticalAlignment="Top">
|
||||
<TabItem Header="Context Menu">
|
||||
<controls:DataGrid x:Name="menuGrid" AutoGenerateColumns="False" CanUserAddRows="True" CanUserDeleteRows="True" Height="420">
|
||||
<controls:DataGrid.Columns>
|
||||
<controls:DataGridTextColumn Header="Name" Width="150" Binding="{Binding Name}" />
|
||||
<controls:DataGridTextColumn Header="Command" Width="250" Binding="{Binding Command}" />
|
||||
<controls:DataGridTextColumn Header="Arguments" Width="*" Binding="{Binding Argument}" />
|
||||
</controls:DataGrid.Columns>
|
||||
</controls:DataGrid>
|
||||
</TabItem>
|
||||
</TabControl>
|
||||
</UserControl>
|
||||
31
Plugins/Wox.Plugin.FindFile/setting.xaml.cs
Normal file
31
Plugins/Wox.Plugin.FindFile/setting.xaml.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace Wox.Plugin.FindFile
|
||||
{
|
||||
public partial class Setting : UserControl
|
||||
{
|
||||
public Setting()
|
||||
{
|
||||
InitializeComponent();
|
||||
menuGrid.ItemsSource = FindFileContextMenuStorage.Instance.ContextMenus;
|
||||
menuGrid.CurrentCellChanged += menuGrid_CurrentCellChanged;
|
||||
}
|
||||
|
||||
void menuGrid_CurrentCellChanged(object sender, EventArgs e)
|
||||
{
|
||||
FindFileContextMenuStorage.Instance.Save();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user