mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-06-07 09:28:03 +08:00
Allow searches in context menu
This commit is contained in:
parent
998eecb94d
commit
82d30c6e74
@ -11,13 +11,13 @@ namespace Wox.Plugin.Everything
|
|||||||
{
|
{
|
||||||
public class ContextMenuStorage : JsonStrorage<ContextMenuStorage>
|
public class ContextMenuStorage : JsonStrorage<ContextMenuStorage>
|
||||||
{
|
{
|
||||||
[JsonProperty]
|
[JsonProperty] public List<ContextMenu> ContextMenus = new List<ContextMenu>();
|
||||||
public List<ContextMenu> ContextMenus = new List<ContextMenu>();
|
|
||||||
|
|
||||||
|
|
||||||
[JsonProperty]
|
[JsonProperty]
|
||||||
public int MaxSearchCount { get; set; }
|
public int MaxSearchCount { get; set; }
|
||||||
|
|
||||||
|
public IPublicAPI API { get; set; }
|
||||||
|
|
||||||
protected override string ConfigName
|
protected override string ConfigName
|
||||||
{
|
{
|
||||||
get { return "EverythingContextMenu"; }
|
get { return "EverythingContextMenu"; }
|
||||||
@ -28,20 +28,14 @@ namespace Wox.Plugin.Everything
|
|||||||
get { return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); }
|
get { return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void OnAfterLoad(ContextMenuStorage obj)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
protected override ContextMenuStorage LoadDefault()
|
protected override ContextMenuStorage LoadDefault()
|
||||||
{
|
{
|
||||||
ContextMenus = new List<ContextMenu>()
|
|
||||||
{
|
|
||||||
new ContextMenu()
|
|
||||||
{
|
|
||||||
Name = "Open Containing Folder",
|
|
||||||
Command = "explorer.exe",
|
|
||||||
Argument = " /select,\"{path}\"",
|
|
||||||
ImagePath ="Images\\folder.png"
|
|
||||||
}
|
|
||||||
};
|
|
||||||
MaxSearchCount = 100;
|
MaxSearchCount = 100;
|
||||||
Save();
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -60,4 +54,4 @@ namespace Wox.Plugin.Everything
|
|||||||
[JsonProperty]
|
[JsonProperty]
|
||||||
public string ImagePath { get; set; }
|
public string ImagePath { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
11
Plugins/Wox.Plugin.Everything/Languages/en.xaml
Normal file
11
Plugins/Wox.Plugin.Everything/Languages/en.xaml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:system="clr-namespace:System;assembly=mscorlib">
|
||||||
|
|
||||||
|
<system:String x:Key="wox_plugin_everything_is_not_running">Everything is not runnin</system:String>
|
||||||
|
<system:String x:Key="wox_plugin_everything_query_error">Everything plugin has an error (enter to copy error message)</system:String>
|
||||||
|
<system:String x:Key="wox_plugin_everything_copied">Copied</system:String>
|
||||||
|
<system:String x:Key="wox_plugin_everything_canot_start">Can't start {0}</system:String>
|
||||||
|
<system:String x:Key="wox_plugin_everything_open_containing_folder">Open containing folder</system:String>
|
||||||
|
|
||||||
|
</ResourceDictionary>
|
11
Plugins/Wox.Plugin.Everything/Languages/zh-cn.xaml
Normal file
11
Plugins/Wox.Plugin.Everything/Languages/zh-cn.xaml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:system="clr-namespace:System;assembly=mscorlib">
|
||||||
|
|
||||||
|
<system:String x:Key="wox_plugin_everything_is_not_running">Everything没有运行,我们将自动为您启动内置Everything,请稍后进行查询</system:String>
|
||||||
|
<system:String x:Key="wox_plugin_everything_query_error">Everything插件发生了一个错误(回车拷贝具体错误信息)</system:String>
|
||||||
|
<system:String x:Key="wox_plugin_everything_copied">拷贝成功</system:String>
|
||||||
|
<system:String x:Key="wox_plugin_everything_canot_start">不能启动 {0}</system:String>
|
||||||
|
<system:String x:Key="wox_plugin_everything_open_containing_folder">打开所属文件夹</system:String>
|
||||||
|
|
||||||
|
</ResourceDictionary>
|
11
Plugins/Wox.Plugin.Everything/Languages/zh-tw.xaml
Normal file
11
Plugins/Wox.Plugin.Everything/Languages/zh-tw.xaml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:system="clr-namespace:System;assembly=mscorlib">
|
||||||
|
|
||||||
|
<system:String x:Key="wox_plugin_everything_is_not_running">Everything沒有運行,我們將自動為您啟動內置Everything,請稍後進行查詢</system:String>
|
||||||
|
<system:String x:Key="wox_plugin_everything_query_error">Everything插件發生了一個錯誤(回車拷貝具體錯誤信息)</system:String>
|
||||||
|
<system:String x:Key="wox_plugin_everything_copied">拷貝成功</system:String>
|
||||||
|
<system:String x:Key="wox_plugin_everything_canot_start">不能啟動 {0}</system:String>
|
||||||
|
<system:String x:Key="wox_plugin_everything_open_containing_folder">打開所屬文件夾</system:String>
|
||||||
|
|
||||||
|
</ResourceDictionary>
|
@ -9,7 +9,7 @@ using Wox.Plugin.Everything.Everything;
|
|||||||
|
|
||||||
namespace Wox.Plugin.Everything
|
namespace Wox.Plugin.Everything
|
||||||
{
|
{
|
||||||
public class Main : IPlugin
|
public class Main : IPlugin, IPluginI18n
|
||||||
{
|
{
|
||||||
PluginInitContext context;
|
PluginInitContext context;
|
||||||
EverythingAPI api = new EverythingAPI();
|
EverythingAPI api = new EverythingAPI();
|
||||||
@ -59,7 +59,7 @@ namespace Wox.Plugin.Everything
|
|||||||
StartEverything();
|
StartEverything();
|
||||||
results.Add(new Result()
|
results.Add(new Result()
|
||||||
{
|
{
|
||||||
Title = "Everything is not running, we already run it for you now. Try search again",
|
Title = context.API.GetTranslation("wox_plugin_everything_is_not_running"),
|
||||||
IcoPath = "Images\\warning.png"
|
IcoPath = "Images\\warning.png"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -67,12 +67,12 @@ namespace Wox.Plugin.Everything
|
|||||||
{
|
{
|
||||||
results.Add(new Result()
|
results.Add(new Result()
|
||||||
{
|
{
|
||||||
Title = "Everything plugin has an error (enter to copy error message)",
|
Title = context.API.GetTranslation("wox_plugin_everything_query_error"),
|
||||||
SubTitle = e.Message,
|
SubTitle = e.Message,
|
||||||
Action = _ =>
|
Action = _ =>
|
||||||
{
|
{
|
||||||
System.Windows.Clipboard.SetText(e.Message + "\r\n" + e.StackTrace);
|
System.Windows.Clipboard.SetText(e.Message + "\r\n" + e.StackTrace);
|
||||||
context.API.ShowMsg("Copied", "Error message has copied to your clipboard", string.Empty);
|
context.API.ShowMsg(context.API.GetTranslation("wox_plugin_everything_copied"), null, string.Empty);
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
IcoPath = "Images\\error.png"
|
IcoPath = "Images\\error.png"
|
||||||
@ -114,9 +114,13 @@ namespace Wox.Plugin.Everything
|
|||||||
{
|
{
|
||||||
List<Result> contextMenus = new List<Result>();
|
List<Result> contextMenus = new List<Result>();
|
||||||
|
|
||||||
|
List<ContextMenu> availableContextMenus = new List<ContextMenu>();
|
||||||
|
availableContextMenus.AddRange(GetDefaultContextMenu());
|
||||||
|
availableContextMenus.AddRange(ContextMenuStorage.Instance.ContextMenus);
|
||||||
|
|
||||||
if (record.Type == ResultType.File)
|
if (record.Type == ResultType.File)
|
||||||
{
|
{
|
||||||
foreach (ContextMenu contextMenu in ContextMenuStorage.Instance.ContextMenus)
|
foreach (ContextMenu contextMenu in availableContextMenus)
|
||||||
{
|
{
|
||||||
contextMenus.Add(new Result()
|
contextMenus.Add(new Result()
|
||||||
{
|
{
|
||||||
@ -126,11 +130,11 @@ namespace Wox.Plugin.Everything
|
|||||||
string argument = contextMenu.Argument.Replace("{path}", record.FullPath);
|
string argument = contextMenu.Argument.Replace("{path}", record.FullPath);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
System.Diagnostics.Process.Start(contextMenu.Command, argument);
|
Process.Start(contextMenu.Command, argument);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
context.API.ShowMsg("Can't start " + record.FullPath, string.Empty, string.Empty);
|
context.API.ShowMsg(string.Format(context.API.GetTranslation("wox_plugin_everything_canot_start"), record.FullPath), string.Empty, string.Empty);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -143,9 +147,25 @@ namespace Wox.Plugin.Everything
|
|||||||
return contextMenus;
|
return contextMenus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<ContextMenu> GetDefaultContextMenu()
|
||||||
|
{
|
||||||
|
List<ContextMenu> defaultContextMenus = new List<ContextMenu>();
|
||||||
|
ContextMenu openFolderContextMenu = new ContextMenu()
|
||||||
|
{
|
||||||
|
Name = context.API.GetTranslation("wox_plugin_everything_open_containing_folder"),
|
||||||
|
Command = "explorer.exe",
|
||||||
|
Argument = " /select,\"{path}\"",
|
||||||
|
ImagePath = "Images\\folder.png"
|
||||||
|
};
|
||||||
|
|
||||||
|
defaultContextMenus.Add(openFolderContextMenu);
|
||||||
|
return defaultContextMenus;
|
||||||
|
}
|
||||||
|
|
||||||
public void Init(PluginInitContext context)
|
public void Init(PluginInitContext context)
|
||||||
{
|
{
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
ContextMenuStorage.Instance.API = context.API;
|
||||||
|
|
||||||
LoadLibrary(Path.Combine(
|
LoadLibrary(Path.Combine(
|
||||||
Path.Combine(context.CurrentPluginMetadata.PluginDirectory, (IntPtr.Size == 4) ? "x86" : "x64"),
|
Path.Combine(context.CurrentPluginMetadata.PluginDirectory, (IntPtr.Size == 4) ? "x86" : "x64"),
|
||||||
@ -159,12 +179,20 @@ namespace Wox.Plugin.Everything
|
|||||||
{
|
{
|
||||||
if (!CheckEverythingIsRunning())
|
if (!CheckEverythingIsRunning())
|
||||||
{
|
{
|
||||||
Process p = new Process();
|
try
|
||||||
p.StartInfo.Verb = "runas";
|
{
|
||||||
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
|
Process p = new Process();
|
||||||
p.StartInfo.FileName = GetEverythingPath();
|
p.StartInfo.Verb = "runas";
|
||||||
p.StartInfo.UseShellExecute = true;
|
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
|
||||||
p.Start();
|
p.StartInfo.FileName = GetEverythingPath();
|
||||||
|
p.StartInfo.UseShellExecute = true;
|
||||||
|
p.Start();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
context.API.ShowMsg("Start Everything failed");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,5 +206,10 @@ namespace Wox.Plugin.Everything
|
|||||||
string everythingFolder = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "PortableEverything");
|
string everythingFolder = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "PortableEverything");
|
||||||
return Path.Combine(everythingFolder, "Everything.exe");
|
return Path.Combine(everythingFolder, "Everything.exe");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string GetLanguagesFolder()
|
||||||
|
{
|
||||||
|
return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Languages");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,130 +1,151 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
<ProjectGuid>{230AE83F-E92E-4E69-8355-426B305DA9C0}</ProjectGuid>
|
<ProjectGuid>{230AE83F-E92E-4E69-8355-426B305DA9C0}</ProjectGuid>
|
||||||
<OutputType>Library</OutputType>
|
<OutputType>Library</OutputType>
|
||||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
<RootNamespace>Wox.Plugin.Everything</RootNamespace>
|
<RootNamespace>Wox.Plugin.Everything</RootNamespace>
|
||||||
<AssemblyName>Wox.Plugin.Everything</AssemblyName>
|
<AssemblyName>Wox.Plugin.Everything</AssemblyName>
|
||||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||||
<FileAlignment>512</FileAlignment>
|
<FileAlignment>512</FileAlignment>
|
||||||
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\Wox\</SolutionDir>
|
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\Wox\</SolutionDir>
|
||||||
<RestorePackages>true</RestorePackages>
|
<RestorePackages>true</RestorePackages>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
<DebugType>full</DebugType>
|
<DebugType>full</DebugType>
|
||||||
<Optimize>false</Optimize>
|
<Optimize>false</Optimize>
|
||||||
<OutputPath>..\..\Output\Debug\Plugins\Wox.Plugin.Everything\</OutputPath>
|
<OutputPath>..\..\Output\Debug\Plugins\Wox.Plugin.Everything\</OutputPath>
|
||||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
<DebugType>pdbonly</DebugType>
|
<DebugType>pdbonly</DebugType>
|
||||||
<Optimize>true</Optimize>
|
<Optimize>true</Optimize>
|
||||||
<OutputPath>..\..\Output\Release\Plugins\Wox.Plugin.Everything\</OutputPath>
|
<OutputPath>..\..\Output\Release\Plugins\Wox.Plugin.Everything\</OutputPath>
|
||||||
<DefineConstants>TRACE</DefineConstants>
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<StartupObject />
|
<StartupObject />
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||||
<SpecificVersion>False</SpecificVersion>
|
<SpecificVersion>False</SpecificVersion>
|
||||||
<HintPath>..\..\packages\Newtonsoft.Json.6.0.8\lib\net35\Newtonsoft.Json.dll</HintPath>
|
<HintPath>..\..\packages\Newtonsoft.Json.6.0.8\lib\net35\Newtonsoft.Json.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="PresentationCore" />
|
<Reference Include="PresentationCore" />
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="System.Xml.Linq" />
|
<Reference Include="System.Xml.Linq" />
|
||||||
<Reference Include="System.Data.DataSetExtensions" />
|
<Reference Include="System.Data.DataSetExtensions" />
|
||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Everything\Exceptions\CreateThreadException.cs" />
|
<Compile Include="Everything\Exceptions\CreateThreadException.cs" />
|
||||||
<Compile Include="Everything\Exceptions\CreateWindowException.cs" />
|
<Compile Include="Everything\Exceptions\CreateWindowException.cs" />
|
||||||
<Compile Include="Everything\EverythingAPI.cs" />
|
<Compile Include="Everything\EverythingAPI.cs" />
|
||||||
<Compile Include="Everything\Exceptions\MemoryErrorException.cs" />
|
<Compile Include="Everything\Exceptions\MemoryErrorException.cs" />
|
||||||
<Compile Include="Everything\Exceptions\InvalidCallException.cs" />
|
<Compile Include="Everything\Exceptions\InvalidCallException.cs" />
|
||||||
<Compile Include="Everything\Exceptions\InvalidIndexException.cs" />
|
<Compile Include="Everything\Exceptions\InvalidIndexException.cs" />
|
||||||
<Compile Include="Everything\Exceptions\IPCErrorException.cs" />
|
<Compile Include="Everything\Exceptions\IPCErrorException.cs" />
|
||||||
<Compile Include="Everything\Exceptions\RegisterClassExException.cs" />
|
<Compile Include="Everything\Exceptions\RegisterClassExException.cs" />
|
||||||
<Compile Include="Everything\ResultType.cs" />
|
<Compile Include="Everything\ResultType.cs" />
|
||||||
<Compile Include="Everything\SearchResult.cs" />
|
<Compile Include="Everything\SearchResult.cs" />
|
||||||
<Compile Include="ContextMenuStorage.cs" />
|
<Compile Include="ContextMenuStorage.cs" />
|
||||||
<Compile Include="Main.cs" />
|
<Compile Include="Main.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="Images\error.png">
|
<Content Include="Images\error.png">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
<Content Include="Images\file.png">
|
<Content Include="Images\file.png">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
<Content Include="Images\find.png">
|
<Content Include="Images\find.png">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
<Content Include="Images\folder.png">
|
<Content Include="Images\folder.png">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
<Content Include="Images\image.png">
|
<Content Include="Images\image.png">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
<Content Include="Images\warning.png">
|
<Content Include="Images\warning.png">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
<None Include="PortableEverything\Everything.exe">
|
<None Include="PortableEverything\Everything.exe">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
<Content Include="x64\Everything.dll">
|
<Content Include="x64\Everything.dll">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
<Content Include="x86\Everything.dll">
|
<Content Include="x86\Everything.dll">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="plugin.json">
|
<None Include="plugin.json">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\Wox.Infrastructure\Wox.Infrastructure.csproj">
|
<ProjectReference Include="..\..\Wox.Infrastructure\Wox.Infrastructure.csproj">
|
||||||
<Project>{4fd29318-a8ab-4d8f-aa47-60bc241b8da3}</Project>
|
<Project>{4fd29318-a8ab-4d8f-aa47-60bc241b8da3}</Project>
|
||||||
<Name>Wox.Infrastructure</Name>
|
<Name>Wox.Infrastructure</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
<ProjectReference Include="..\..\Wox.Plugin\Wox.Plugin.csproj">
|
<ProjectReference Include="..\..\Wox.Plugin\Wox.Plugin.csproj">
|
||||||
<Project>{8451ecdd-2ea4-4966-bb0a-7bbc40138e80}</Project>
|
<Project>{8451ecdd-2ea4-4966-bb0a-7bbc40138e80}</Project>
|
||||||
<Name>Wox.Plugin</Name>
|
<Name>Wox.Plugin</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<ItemGroup>
|
||||||
<PropertyGroup>
|
<Content Include="Languages\en.xaml">
|
||||||
<PostBuildEvent>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
</PostBuildEvent>
|
<SubType>Designer</SubType>
|
||||||
</PropertyGroup>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
|
</Content>
|
||||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
</ItemGroup>
|
||||||
<PropertyGroup>
|
<ItemGroup>
|
||||||
<ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。启用“NuGet 程序包还原”可下载这些程序包。有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
|
<None Include="Languages\zh-cn.xaml">
|
||||||
</PropertyGroup>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
|
<SubType>Designer</SubType>
|
||||||
</Target>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="Languages\zh-tw.xaml">
|
||||||
|
<Generator>MSBuild:Compile</Generator>
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
<PropertyGroup>
|
||||||
|
<PostBuildEvent>
|
||||||
|
</PostBuildEvent>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
|
||||||
|
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||||
|
<PropertyGroup>
|
||||||
|
<ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。启用“NuGet 程序包还原”可下载这些程序包。有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
|
||||||
|
</Target>
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- 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.
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
<Target Name="BeforeBuild">
|
<Target Name="BeforeBuild">
|
||||||
</Target>
|
</Target>
|
||||||
<Target Name="AfterBuild">
|
<Target Name="AfterBuild">
|
||||||
</Target>
|
</Target>
|
||||||
-->
|
-->
|
||||||
</Project>
|
</Project>
|
@ -19,5 +19,8 @@
|
|||||||
<system:String x:Key="wox_plugin_program_split_by_tip">(Each suffix should split by ;)</system:String>
|
<system:String x:Key="wox_plugin_program_split_by_tip">(Each suffix should split by ;)</system:String>
|
||||||
<system:String x:Key="wox_plugin_program_update_file_suffixes">Sucessfully update file suffixes</system:String>
|
<system:String x:Key="wox_plugin_program_update_file_suffixes">Sucessfully update file suffixes</system:String>
|
||||||
<system:String x:Key="wox_plugin_program_suffixes_cannot_empty">File suffixes can't be empty</system:String>
|
<system:String x:Key="wox_plugin_program_suffixes_cannot_empty">File suffixes can't be empty</system:String>
|
||||||
|
|
||||||
|
<system:String x:Key="wox_plugin_program_run_as_administrator">Run As Administrator</system:String>
|
||||||
|
<system:String x:Key="wox_plugin_program_open_containing_folder">Open containing folder</system:String>
|
||||||
|
|
||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
@ -1,24 +1,27 @@
|
|||||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:system="clr-namespace:System;assembly=mscorlib">
|
xmlns:system="clr-namespace:System;assembly=mscorlib">
|
||||||
|
|
||||||
<!--Program setting-->
|
<!--Program setting-->
|
||||||
<system:String x:Key="wox_plugin_program_delete">删除</system:String>
|
<system:String x:Key="wox_plugin_program_delete">删除</system:String>
|
||||||
<system:String x:Key="wox_plugin_program_edit">编辑</system:String>
|
<system:String x:Key="wox_plugin_program_edit">编辑</system:String>
|
||||||
<system:String x:Key="wox_plugin_program_add">增加</system:String>
|
<system:String x:Key="wox_plugin_program_add">增加</system:String>
|
||||||
<system:String x:Key="wox_plugin_program_location">位置</system:String>
|
<system:String x:Key="wox_plugin_program_location">位置</system:String>
|
||||||
<system:String x:Key="wox_plugin_program_suffixes">索引文件后缀</system:String>
|
<system:String x:Key="wox_plugin_program_suffixes">索引文件后缀</system:String>
|
||||||
<system:String x:Key="wox_plugin_program_reindex">重新索引</system:String>
|
<system:String x:Key="wox_plugin_program_reindex">重新索引</system:String>
|
||||||
<system:String x:Key="wox_plugin_program_indexing">索引中</system:String>
|
<system:String x:Key="wox_plugin_program_indexing">索引中</system:String>
|
||||||
|
|
||||||
|
|
||||||
<system:String x:Key="wox_plugin_program_pls_select_program_source">请先选择一项</system:String>
|
<system:String x:Key="wox_plugin_program_pls_select_program_source">请先选择一项</system:String>
|
||||||
<system:String x:Key="wox_plugin_program_delete_program_source">你确定要删除{0}吗?</system:String>
|
<system:String x:Key="wox_plugin_program_delete_program_source">你确定要删除{0}吗?</system:String>
|
||||||
|
|
||||||
<system:String x:Key="wox_plugin_program_update">更新</system:String>
|
<system:String x:Key="wox_plugin_program_update">更新</system:String>
|
||||||
<system:String x:Key="wox_plugin_program_only_index_tip">Wox仅索引下列后缀的文件:</system:String>
|
<system:String x:Key="wox_plugin_program_only_index_tip">Wox仅索引下列后缀的文件:</system:String>
|
||||||
<system:String x:Key="wox_plugin_program_split_by_tip">(每个后缀以英文状态下的分号分隔)</system:String>
|
<system:String x:Key="wox_plugin_program_split_by_tip">(每个后缀以英文状态下的分号分隔)</system:String>
|
||||||
<system:String x:Key="wox_plugin_program_update_file_suffixes">成功更新索引文件后缀</system:String>
|
<system:String x:Key="wox_plugin_program_update_file_suffixes">成功更新索引文件后缀</system:String>
|
||||||
<system:String x:Key="wox_plugin_program_suffixes_cannot_empty">文件后缀不能为空</system:String>
|
<system:String x:Key="wox_plugin_program_suffixes_cannot_empty">文件后缀不能为空</system:String>
|
||||||
|
|
||||||
|
<system:String x:Key="wox_plugin_program_run_as_administrator">以管理员身份运行</system:String>
|
||||||
|
<system:String x:Key="wox_plugin_program_open_containing_folder">打开所属文件夹</system:String>
|
||||||
|
|
||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
@ -1,24 +1,26 @@
|
|||||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:system="clr-namespace:System;assembly=mscorlib">
|
xmlns:system="clr-namespace:System;assembly=mscorlib">
|
||||||
|
|
||||||
<!--Program setting-->
|
<!--Program setting-->
|
||||||
<system:String x:Key="wox_plugin_program_delete">刪除</system:String>
|
<system:String x:Key="wox_plugin_program_delete">刪除</system:String>
|
||||||
<system:String x:Key="wox_plugin_program_edit">編輯</system:String>
|
<system:String x:Key="wox_plugin_program_edit">編輯</system:String>
|
||||||
<system:String x:Key="wox_plugin_program_add">增加</system:String>
|
<system:String x:Key="wox_plugin_program_add">增加</system:String>
|
||||||
<system:String x:Key="wox_plugin_program_location">位置</system:String>
|
<system:String x:Key="wox_plugin_program_location">位置</system:String>
|
||||||
<system:String x:Key="wox_plugin_program_suffixes">索引文件後綴</system:String>
|
<system:String x:Key="wox_plugin_program_suffixes">索引文件後綴</system:String>
|
||||||
<system:String x:Key="wox_plugin_program_reindex">重新索引</system:String>
|
<system:String x:Key="wox_plugin_program_reindex">重新索引</system:String>
|
||||||
<system:String x:Key="wox_plugin_program_indexing">索引中</system:String>
|
<system:String x:Key="wox_plugin_program_indexing">索引中</system:String>
|
||||||
|
|
||||||
|
|
||||||
<system:String x:Key="wox_plugin_program_pls_select_program_source">請先選擇一項</system:String>
|
<system:String x:Key="wox_plugin_program_pls_select_program_source">請先選擇一項</system:String>
|
||||||
<system:String x:Key="wox_plugin_program_delete_program_source">你確定要刪除{0}嗎?</system:String>
|
<system:String x:Key="wox_plugin_program_delete_program_source">你確定要刪除{0}嗎?</system:String>
|
||||||
|
|
||||||
<system:String x:Key="wox_plugin_program_update">更新</system:String>
|
<system:String x:Key="wox_plugin_program_update">更新</system:String>
|
||||||
<system:String x:Key="wox_plugin_program_only_index_tip">Wox僅索引下列後綴的文件:</system:String>
|
<system:String x:Key="wox_plugin_program_only_index_tip">Wox僅索引下列後綴的文件:</system:String>
|
||||||
<system:String x:Key="wox_plugin_program_split_by_tip">(每個後綴以英文狀態下的分號分隔)</system:String>
|
<system:String x:Key="wox_plugin_program_split_by_tip">(每個後綴以英文狀態下的分號分隔)</system:String>
|
||||||
<system:String x:Key="wox_plugin_program_update_file_suffixes">成功更新索引文件後綴</system:String>
|
<system:String x:Key="wox_plugin_program_update_file_suffixes">成功更新索引文件後綴</system:String>
|
||||||
<system:String x:Key="wox_plugin_program_suffixes_cannot_empty">文件後綴不能為空</system:String>
|
<system:String x:Key="wox_plugin_program_suffixes_cannot_empty">文件後綴不能為空</system:String>
|
||||||
|
|
||||||
|
<system:String x:Key="wox_plugin_program_run_as_administrator">以管理員身份運行</system:String>
|
||||||
|
<system:String x:Key="wox_plugin_program_open_containing_folder">打開所屬文件夾</system:String>
|
||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
@ -48,7 +48,7 @@ namespace Wox.Plugin.Program
|
|||||||
{
|
{
|
||||||
new Result()
|
new Result()
|
||||||
{
|
{
|
||||||
Title = "Run As Administrator",
|
Title = context.API.GetTranslation("wox_plugin_program_run_as_administrator"),
|
||||||
Action = _ =>
|
Action = _ =>
|
||||||
{
|
{
|
||||||
context.API.HideApp();
|
context.API.HideApp();
|
||||||
@ -59,7 +59,7 @@ namespace Wox.Plugin.Program
|
|||||||
},
|
},
|
||||||
new Result()
|
new Result()
|
||||||
{
|
{
|
||||||
Title = "Open Containing Folder",
|
Title = context.API.GetTranslation("wox_plugin_program_open_containing_folder"),
|
||||||
Action = _ =>
|
Action = _ =>
|
||||||
{
|
{
|
||||||
context.API.HideApp();
|
context.API.HideApp();
|
||||||
@ -85,8 +85,8 @@ namespace Wox.Plugin.Program
|
|||||||
static string ResolveShortcut(string filePath)
|
static string ResolveShortcut(string filePath)
|
||||||
{
|
{
|
||||||
// IWshRuntimeLibrary is in the COM library "Windows Script Host Object Model"
|
// IWshRuntimeLibrary is in the COM library "Windows Script Host Object Model"
|
||||||
IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();
|
WshShell shell = new WshShell();
|
||||||
IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(filePath);
|
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(filePath);
|
||||||
return shortcut.TargetPath;
|
return shortcut.TargetPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
33
Wox.Infrastructure/StringMatcher.cs
Normal file
33
Wox.Infrastructure/StringMatcher.cs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Wox.Infrastructure
|
||||||
|
{
|
||||||
|
public class StringMatcher
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Check if a candidate is match with the source
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <param name="candidate"></param>
|
||||||
|
/// <returns>Match score</returns>
|
||||||
|
public static int Match(string source, string candidate)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(source) || string.IsNullOrEmpty(candidate)) return 0;
|
||||||
|
|
||||||
|
FuzzyMatcher matcher = FuzzyMatcher.Create(candidate);
|
||||||
|
int score = matcher.Evaluate(source).Score;
|
||||||
|
if (score > 0) return score;
|
||||||
|
|
||||||
|
score = matcher.Evaluate(source.Unidecode()).Score;
|
||||||
|
return score;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool IsMatch(string source, string candidate)
|
||||||
|
{
|
||||||
|
return Match(source, candidate) > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -66,6 +66,7 @@
|
|||||||
<Compile Include="Storage\BinaryStorage.cs" />
|
<Compile Include="Storage\BinaryStorage.cs" />
|
||||||
<Compile Include="Storage\IStorage.cs" />
|
<Compile Include="Storage\IStorage.cs" />
|
||||||
<Compile Include="Storage\JsonStorage.cs" />
|
<Compile Include="Storage\JsonStorage.cs" />
|
||||||
|
<Compile Include="StringMatcher.cs" />
|
||||||
<Compile Include="Timeit.cs" />
|
<Compile Include="Timeit.cs" />
|
||||||
<Compile Include="Unidecoder.Characters.cs" />
|
<Compile Include="Unidecoder.Characters.cs" />
|
||||||
<Compile Include="Http\HttpRequest.cs" />
|
<Compile Include="Http\HttpRequest.cs" />
|
||||||
|
@ -42,6 +42,12 @@ namespace Wox.Plugin
|
|||||||
/// </param>
|
/// </param>
|
||||||
void ChangeQuery(string query, bool requery = false);
|
void ChangeQuery(string query, bool requery = false);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Just change the query text, this won't raise search
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="query"></param>
|
||||||
|
void ChangeQueryText(string query);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Close Wox
|
/// Close Wox
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -63,7 +69,7 @@ namespace Wox.Plugin
|
|||||||
/// <param name="title">Message title</param>
|
/// <param name="title">Message title</param>
|
||||||
/// <param name="subTitle">Message subtitle</param>
|
/// <param name="subTitle">Message subtitle</param>
|
||||||
/// <param name="iconPath">Message icon path (relative path to your plugin folder)</param>
|
/// <param name="iconPath">Message icon path (relative path to your plugin folder)</param>
|
||||||
void ShowMsg(string title, string subTitle, string iconPath);
|
void ShowMsg(string title, string subTitle = "", string iconPath = "");
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Open setting dialog
|
/// Open setting dialog
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.1 KiB |
BIN
Wox/Images/up.png
Normal file
BIN
Wox/Images/up.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.0 KiB |
@ -5,6 +5,8 @@
|
|||||||
<system:String x:Key="registerHotkeyFailed">Register hotkey: {0} failed</system:String>
|
<system:String x:Key="registerHotkeyFailed">Register hotkey: {0} failed</system:String>
|
||||||
<system:String x:Key="couldnotStartCmd">Could not start {0}</system:String>
|
<system:String x:Key="couldnotStartCmd">Could not start {0}</system:String>
|
||||||
<system:String x:Key="invalidWoxPluginFileFormat">Invalid wox plugin file format</system:String>
|
<system:String x:Key="invalidWoxPluginFileFormat">Invalid wox plugin file format</system:String>
|
||||||
|
<system:String x:Key="setAsTopMostInThisQuery">Set as topmost in this query</system:String>
|
||||||
|
<system:String x:Key="cancelTopMostInThisQuery">Cancel topmost in this query</system:String>
|
||||||
|
|
||||||
|
|
||||||
<!--Setting General-->
|
<!--Setting General-->
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
<system:String x:Key="registerHotkeyFailed">注册热键:{0} 失败</system:String>
|
<system:String x:Key="registerHotkeyFailed">注册热键:{0} 失败</system:String>
|
||||||
<system:String x:Key="couldnotStartCmd">启动命令 {0} 失败</system:String>
|
<system:String x:Key="couldnotStartCmd">启动命令 {0} 失败</system:String>
|
||||||
<system:String x:Key="invalidWoxPluginFileFormat">不是合法的Wox插件格式</system:String>
|
<system:String x:Key="invalidWoxPluginFileFormat">不是合法的Wox插件格式</system:String>
|
||||||
|
<system:String x:Key="setAsTopMostInThisQuery">在当前查询中置顶</system:String>
|
||||||
|
<system:String x:Key="cancelTopMostInThisQuery">取消置顶</system:String>
|
||||||
|
|
||||||
|
|
||||||
<!--设置,通用-->
|
<!--设置,通用-->
|
||||||
|
@ -5,7 +5,8 @@
|
|||||||
<system:String x:Key="registerHotkeyFailed">註冊熱鍵:{0} 失敗</system:String>
|
<system:String x:Key="registerHotkeyFailed">註冊熱鍵:{0} 失敗</system:String>
|
||||||
<system:String x:Key="couldnotStartCmd">啟動命令 {0} 失敗</system:String>
|
<system:String x:Key="couldnotStartCmd">啟動命令 {0} 失敗</system:String>
|
||||||
<system:String x:Key="invalidWoxPluginFileFormat">不是合法的Wox插件格式</system:String>
|
<system:String x:Key="invalidWoxPluginFileFormat">不是合法的Wox插件格式</system:String>
|
||||||
|
<system:String x:Key="setAsTopMostInThisQuery">在當前查詢中置頂</system:String>
|
||||||
|
<system:String x:Key="cancelTopMostInThisQuery">取消置頂</system:String>
|
||||||
|
|
||||||
<!--設置,通用-->
|
<!--設置,通用-->
|
||||||
<system:String x:Key="woxsettings">Wox設置</system:String>
|
<system:String x:Key="woxsettings">Wox設置</system:String>
|
||||||
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
@ -11,7 +12,6 @@ using System.Windows;
|
|||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Windows.Interop;
|
|
||||||
using System.Windows.Media.Animation;
|
using System.Windows.Media.Animation;
|
||||||
using NHotkey;
|
using NHotkey;
|
||||||
using NHotkey.Wpf;
|
using NHotkey.Wpf;
|
||||||
@ -25,18 +25,14 @@ using Wox.Infrastructure;
|
|||||||
using Wox.Infrastructure.Hotkey;
|
using Wox.Infrastructure.Hotkey;
|
||||||
using Wox.Plugin;
|
using Wox.Plugin;
|
||||||
using Wox.Storage;
|
using Wox.Storage;
|
||||||
using Brushes = System.Windows.Media.Brushes;
|
|
||||||
using Color = System.Windows.Media.Color;
|
|
||||||
using ContextMenu = System.Windows.Forms.ContextMenu;
|
using ContextMenu = System.Windows.Forms.ContextMenu;
|
||||||
using DataFormats = System.Windows.DataFormats;
|
using DataFormats = System.Windows.DataFormats;
|
||||||
using DragEventArgs = System.Windows.DragEventArgs;
|
using DragEventArgs = System.Windows.DragEventArgs;
|
||||||
|
using IDataObject = System.Windows.IDataObject;
|
||||||
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
|
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
|
||||||
using MenuItem = System.Windows.Forms.MenuItem;
|
using MenuItem = System.Windows.Forms.MenuItem;
|
||||||
using MessageBox = System.Windows.MessageBox;
|
using MessageBox = System.Windows.MessageBox;
|
||||||
using ToolTip = System.Windows.Controls.ToolTip;
|
using ToolTip = System.Windows.Controls.ToolTip;
|
||||||
using Wox.Infrastructure.Logger;
|
|
||||||
using IDataObject = System.Windows.IDataObject;
|
|
||||||
using System.IO;
|
|
||||||
|
|
||||||
namespace Wox
|
namespace Wox
|
||||||
{
|
{
|
||||||
@ -52,6 +48,8 @@ namespace Wox
|
|||||||
private ToolTip toolTip = new ToolTip();
|
private ToolTip toolTip = new ToolTip();
|
||||||
|
|
||||||
private bool ignoreTextChange = false;
|
private bool ignoreTextChange = false;
|
||||||
|
private List<Result> CurrentContextMenus = new List<Result>();
|
||||||
|
private string textBeforeEnterContextMenuMode;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -70,6 +68,16 @@ namespace Wox
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ChangeQueryText(string query)
|
||||||
|
{
|
||||||
|
Dispatcher.Invoke(new Action(() =>
|
||||||
|
{
|
||||||
|
ignoreTextChange = true;
|
||||||
|
tbQuery.Text = query;
|
||||||
|
tbQuery.CaretIndex = tbQuery.Text.Length;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
public void CloseApp()
|
public void CloseApp()
|
||||||
{
|
{
|
||||||
Dispatcher.Invoke(new Action(() =>
|
Dispatcher.Invoke(new Action(() =>
|
||||||
@ -380,13 +388,43 @@ namespace Wox
|
|||||||
notifyIcon.ContextMenu = new ContextMenu(childen);
|
notifyIcon.ContextMenu = new ContextMenu(childen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void QueryContextMenu()
|
||||||
|
{
|
||||||
|
pnlContextMenu.Clear();
|
||||||
|
var query = tbQuery.Text.ToLower();
|
||||||
|
if (string.IsNullOrEmpty(query))
|
||||||
|
{
|
||||||
|
pnlContextMenu.AddResults(CurrentContextMenus);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
List<Result> filterResults = new List<Result>();
|
||||||
|
foreach (Result contextMenu in CurrentContextMenus)
|
||||||
|
{
|
||||||
|
if (StringMatcher.IsMatch(contextMenu.Title, query)
|
||||||
|
|| StringMatcher.IsMatch(contextMenu.SubTitle, query))
|
||||||
|
{
|
||||||
|
filterResults.Add(contextMenu);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pnlContextMenu.AddResults(filterResults);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void TextBoxBase_OnTextChanged(object sender, TextChangedEventArgs e)
|
private void TextBoxBase_OnTextChanged(object sender, TextChangedEventArgs e)
|
||||||
{
|
{
|
||||||
if (ignoreTextChange) { ignoreTextChange = false; return; }
|
if (ignoreTextChange) { ignoreTextChange = false; return; }
|
||||||
|
|
||||||
lastQuery = tbQuery.Text;
|
|
||||||
toolTip.IsOpen = false;
|
toolTip.IsOpen = false;
|
||||||
pnlResult.Dirty = true;
|
pnlResult.Dirty = true;
|
||||||
|
|
||||||
|
if (IsInContextMenuMode)
|
||||||
|
{
|
||||||
|
QueryContextMenu();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
lastQuery = tbQuery.Text;
|
||||||
int searchDelay = GetSearchDelay(lastQuery);
|
int searchDelay = GetSearchDelay(lastQuery);
|
||||||
|
|
||||||
Dispatcher.DelayInvoke("UpdateSearch",
|
Dispatcher.DelayInvoke("UpdateSearch",
|
||||||
@ -464,11 +502,11 @@ namespace Wox
|
|||||||
{
|
{
|
||||||
PluginManager.Query(q);
|
PluginManager.Query(q);
|
||||||
StopProgress();
|
StopProgress();
|
||||||
BackToResultMode();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void BackToResultMode()
|
private void BackToResultMode()
|
||||||
{
|
{
|
||||||
|
ChangeQueryText(textBeforeEnterContextMenuMode);
|
||||||
pnlResult.Visibility = Visibility.Visible;
|
pnlResult.Visibility = Visibility.Visible;
|
||||||
pnlContextMenu.Visibility = Visibility.Collapsed;
|
pnlContextMenu.Visibility = Visibility.Collapsed;
|
||||||
}
|
}
|
||||||
@ -490,6 +528,7 @@ namespace Wox
|
|||||||
|
|
||||||
private void HideWox()
|
private void HideWox()
|
||||||
{
|
{
|
||||||
|
BackToResultMode();
|
||||||
Hide();
|
Hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -553,7 +592,7 @@ namespace Wox
|
|||||||
|
|
||||||
case Key.N:
|
case Key.N:
|
||||||
case Key.J:
|
case Key.J:
|
||||||
if (GlobalHotkey.Instance.CheckModifiers().AltPressed)
|
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
|
||||||
{
|
{
|
||||||
SelectNextItem();
|
SelectNextItem();
|
||||||
}
|
}
|
||||||
@ -561,14 +600,14 @@ namespace Wox
|
|||||||
|
|
||||||
case Key.P:
|
case Key.P:
|
||||||
case Key.K:
|
case Key.K:
|
||||||
if (GlobalHotkey.Instance.CheckModifiers().AltPressed)
|
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
|
||||||
{
|
{
|
||||||
SelectPrevItem();
|
SelectPrevItem();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Key.O:
|
case Key.O:
|
||||||
if (GlobalHotkey.Instance.CheckModifiers().AltPressed)
|
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
|
||||||
{
|
{
|
||||||
if (IsInContextMenuMode)
|
if (IsInContextMenuMode)
|
||||||
{
|
{
|
||||||
@ -592,7 +631,7 @@ namespace Wox
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case Key.D:
|
case Key.D:
|
||||||
if (GlobalHotkey.Instance.CheckModifiers().AltPressed)
|
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
|
||||||
{
|
{
|
||||||
pnlResult.SelectNextPage();
|
pnlResult.SelectNextPage();
|
||||||
}
|
}
|
||||||
@ -604,7 +643,7 @@ namespace Wox
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case Key.U:
|
case Key.U:
|
||||||
if (GlobalHotkey.Instance.CheckModifiers().AltPressed)
|
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
|
||||||
{
|
{
|
||||||
pnlResult.SelectPrevPage();
|
pnlResult.SelectPrevPage();
|
||||||
}
|
}
|
||||||
@ -774,7 +813,7 @@ namespace Wox
|
|||||||
{
|
{
|
||||||
if (TopMostRecordStorage.Instance.IsTopMost(result))
|
if (TopMostRecordStorage.Instance.IsTopMost(result))
|
||||||
{
|
{
|
||||||
result.ContextMenu.Add(new Result("Remove top most in this query", "Images\\topmost.png")
|
result.ContextMenu.Add(new Result(GetTranslation("cancelTopMostInThisQuery"), "Images\\down.png")
|
||||||
{
|
{
|
||||||
PluginDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
|
PluginDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
|
||||||
Action = _ =>
|
Action = _ =>
|
||||||
@ -787,7 +826,7 @@ namespace Wox
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result.ContextMenu.Add(new Result("Set as top most in this query", "Images\\topmost.png")
|
result.ContextMenu.Add(new Result(GetTranslation("setAsTopMostInThisQuery"), "Images\\up.png")
|
||||||
{
|
{
|
||||||
PluginDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
|
PluginDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
|
||||||
Action = _ =>
|
Action = _ =>
|
||||||
@ -804,8 +843,11 @@ namespace Wox
|
|||||||
{
|
{
|
||||||
if (result.ContextMenu != null && result.ContextMenu.Count > 0)
|
if (result.ContextMenu != null && result.ContextMenu.Count > 0)
|
||||||
{
|
{
|
||||||
|
textBeforeEnterContextMenuMode = tbQuery.Text;
|
||||||
|
ChangeQueryText("");
|
||||||
pnlContextMenu.Clear();
|
pnlContextMenu.Clear();
|
||||||
pnlContextMenu.AddResults(result.ContextMenu);
|
pnlContextMenu.AddResults(result.ContextMenu);
|
||||||
|
CurrentContextMenus = result.ContextMenu;
|
||||||
pnlContextMenu.Visibility = Visibility.Visible;
|
pnlContextMenu.Visibility = Visibility.Visible;
|
||||||
pnlResult.Visibility = Visibility.Collapsed;
|
pnlResult.Visibility = Visibility.Collapsed;
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
<Image x:Name="imgIco" Width="32" Height="32" HorizontalAlignment="Left" ></Image>
|
<Image x:Name="imgIco" Width="32" Height="32" HorizontalAlignment="Left" ></Image>
|
||||||
<Grid HorizontalAlignment="Stretch" Margin="5 0 0 0" Grid.Column="1" VerticalAlignment="Stretch">
|
<Grid HorizontalAlignment="Stretch" Margin="5 0 0 0" Grid.Column="1" VerticalAlignment="Stretch">
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
<RowDefinition Height="29"></RowDefinition>
|
<RowDefinition></RowDefinition>
|
||||||
<RowDefinition></RowDefinition>
|
<RowDefinition></RowDefinition>
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
<TextBlock x:Name="tbTitle" FontSize="16" Foreground="#37392c" FontWeight="Medium">Title</TextBlock>
|
<TextBlock x:Name="tbTitle" FontSize="16" Foreground="#37392c" FontWeight="Medium">Title</TextBlock>
|
||||||
|
@ -57,8 +57,11 @@ namespace Wox {
|
|||||||
public void Show(string title, string subTitle, string icopath) {
|
public void Show(string title, string subTitle, string icopath) {
|
||||||
tbTitle.Text = title;
|
tbTitle.Text = title;
|
||||||
tbSubTitle.Text = subTitle;
|
tbSubTitle.Text = subTitle;
|
||||||
|
if (string.IsNullOrEmpty(subTitle))
|
||||||
|
{
|
||||||
|
tbSubTitle.Visibility = Visibility.Collapsed;
|
||||||
|
}
|
||||||
if (!File.Exists(icopath)) {
|
if (!File.Exists(icopath)) {
|
||||||
//icopath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), "Images\\app.png");
|
|
||||||
imgIco.Source = new BitmapImage(new Uri("Images\\app.png", UriKind.Relative));
|
imgIco.Source = new BitmapImage(new Uri("Images\\app.png", UriKind.Relative));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -180,7 +180,10 @@
|
|||||||
<Resource Include="Images\update.png">
|
<Resource Include="Images\update.png">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</Resource>
|
</Resource>
|
||||||
<None Include="Images\topmost.png">
|
<None Include="Images\up.png">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Include="Images\down.png">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
<Content Include="Languages\en.xaml">
|
<Content Include="Languages\en.xaml">
|
||||||
|
850
Wox/ias03vpr.pm0
Normal file
850
Wox/ias03vpr.pm0
Normal file
@ -0,0 +1,850 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using System.Windows.Media.Animation;
|
||||||
|
using NHotkey;
|
||||||
|
using NHotkey.Wpf;
|
||||||
|
using Wox.Core.i18n;
|
||||||
|
using Wox.Core.Plugin;
|
||||||
|
using Wox.Core.Theme;
|
||||||
|
using Wox.Core.Updater;
|
||||||
|
using Wox.Core.UserSettings;
|
||||||
|
using Wox.Helper;
|
||||||
|
using Wox.Infrastructure;
|
||||||
|
using Wox.Infrastructure.Hotkey;
|
||||||
|
using Wox.Plugin;
|
||||||
|
using Wox.Storage;
|
||||||
|
using ContextMenu = System.Windows.Forms.ContextMenu;
|
||||||
|
using DataFormats = System.Windows.DataFormats;
|
||||||
|
using DragEventArgs = System.Windows.DragEventArgs;
|
||||||
|
using IDataObject = System.Windows.IDataObject;
|
||||||
|
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
|
||||||
|
using MenuItem = System.Windows.Forms.MenuItem;
|
||||||
|
using MessageBox = System.Windows.MessageBox;
|
||||||
|
using ToolTip = System.Windows.Controls.ToolTip;
|
||||||
|
|
||||||
|
namespace Wox
|
||||||
|
{
|
||||||
|
public partial class MainWindow : IPublicAPI
|
||||||
|
{
|
||||||
|
|
||||||
|
#region Properties
|
||||||
|
|
||||||
|
private readonly Storyboard progressBarStoryboard = new Storyboard();
|
||||||
|
private NotifyIcon notifyIcon;
|
||||||
|
private bool queryHasReturn;
|
||||||
|
private string lastQuery;
|
||||||
|
private ToolTip toolTip = new ToolTip();
|
||||||
|
|
||||||
|
private bool ignoreTextChange = false;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Public API
|
||||||
|
|
||||||
|
public void ChangeQuery(string query, bool requery = false)
|
||||||
|
{
|
||||||
|
Dispatcher.Invoke(new Action(() =>
|
||||||
|
{
|
||||||
|
tbQuery.Text = query;
|
||||||
|
tbQuery.CaretIndex = tbQuery.Text.Length;
|
||||||
|
if (requery)
|
||||||
|
{
|
||||||
|
TextBoxBase_OnTextChanged(null, null);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CloseApp()
|
||||||
|
{
|
||||||
|
Dispatcher.Invoke(new Action(() =>
|
||||||
|
{
|
||||||
|
notifyIcon.Visible = false;
|
||||||
|
Close();
|
||||||
|
Environment.Exit(0);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void HideApp()
|
||||||
|
{
|
||||||
|
Dispatcher.Invoke(new Action(HideWox));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ShowApp()
|
||||||
|
{
|
||||||
|
Dispatcher.Invoke(new Action(() => ShowWox()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ShowMsg(string title, string subTitle, string iconPath)
|
||||||
|
{
|
||||||
|
Dispatcher.Invoke(new Action(() =>
|
||||||
|
{
|
||||||
|
var m = new Msg { Owner = GetWindow(this) };
|
||||||
|
m.Show(title, subTitle, iconPath);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OpenSettingDialog()
|
||||||
|
{
|
||||||
|
Dispatcher.Invoke(new Action(() => WindowOpener.Open<SettingWindow>(this)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void StartLoadingBar()
|
||||||
|
{
|
||||||
|
Dispatcher.Invoke(new Action(StartProgress));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void StopLoadingBar()
|
||||||
|
{
|
||||||
|
Dispatcher.Invoke(new Action(StopProgress));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void InstallPlugin(string path)
|
||||||
|
{
|
||||||
|
Dispatcher.Invoke(new Action(() => PluginManager.InstallPlugin(path)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ReloadPlugins()
|
||||||
|
{
|
||||||
|
Dispatcher.Invoke(new Action(() => PluginManager.Init(this)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetTranslation(string key)
|
||||||
|
{
|
||||||
|
return InternationalizationManager.Instance.GetTranslation(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<PluginPair> GetAllPlugins()
|
||||||
|
{
|
||||||
|
return PluginManager.AllPlugins;
|
||||||
|
}
|
||||||
|
|
||||||
|
public event WoxKeyDownEventHandler BackKeyDownEvent;
|
||||||
|
public event WoxGlobalKeyboardEventHandler GlobalKeyboardEvent;
|
||||||
|
public event AfterWoxQueryEventHandler AfterWoxQueryEvent;
|
||||||
|
public event AfterWoxQueryEventHandler BeforeWoxQueryEvent;
|
||||||
|
public event ResultItemDropEventHandler ResultItemDropEvent;
|
||||||
|
|
||||||
|
public void PushResults(Query query, PluginMetadata plugin, List<Result> results)
|
||||||
|
{
|
||||||
|
results.ForEach(o =>
|
||||||
|
{
|
||||||
|
o.PluginDirectory = plugin.PluginDirectory;
|
||||||
|
o.PluginID = plugin.ID;
|
||||||
|
o.OriginQuery = query;
|
||||||
|
if (o.ContextMenu != null)
|
||||||
|
{
|
||||||
|
o.ContextMenu.ForEach(t =>
|
||||||
|
{
|
||||||
|
t.PluginDirectory = plugin.PluginDirectory;
|
||||||
|
t.PluginID = plugin.ID;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
UpdateResultView(results);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ShowContextMenu(PluginMetadata plugin, List<Result> results)
|
||||||
|
{
|
||||||
|
if (results != null && results.Count > 0)
|
||||||
|
{
|
||||||
|
results.ForEach(o =>
|
||||||
|
{
|
||||||
|
o.PluginDirectory = plugin.PluginDirectory;
|
||||||
|
o.PluginID = plugin.ID;
|
||||||
|
o.ContextMenu = null;
|
||||||
|
});
|
||||||
|
pnlContextMenu.Clear();
|
||||||
|
pnlContextMenu.AddResults(results);
|
||||||
|
pnlContextMenu.Visibility = Visibility.Visible;
|
||||||
|
pnlResult.Visibility = Visibility.Collapsed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
public MainWindow()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
ThreadPool.SetMaxThreads(30, 10);
|
||||||
|
ThreadPool.SetMinThreads(10, 5);
|
||||||
|
|
||||||
|
WebRequest.RegisterPrefix("data", new DataWebRequestFactory());
|
||||||
|
GlobalHotkey.Instance.hookedKeyboardCallback += KListener_hookedKeyboardCallback;
|
||||||
|
progressBar.ToolTip = toolTip;
|
||||||
|
InitialTray();
|
||||||
|
pnlResult.LeftMouseClickEvent += SelectResult;
|
||||||
|
pnlResult.ItemDropEvent += pnlResult_ItemDropEvent;
|
||||||
|
pnlContextMenu.LeftMouseClickEvent += SelectResult;
|
||||||
|
pnlResult.RightMouseClickEvent += pnlResult_RightMouseClickEvent;
|
||||||
|
|
||||||
|
ThemeManager.Theme.ChangeTheme(UserSettingStorage.Instance.Theme);
|
||||||
|
InternationalizationManager.Instance.ChangeLanguage(UserSettingStorage.Instance.Language);
|
||||||
|
|
||||||
|
SetHotkey(UserSettingStorage.Instance.Hotkey, OnHotkey);
|
||||||
|
SetCustomPluginHotkey();
|
||||||
|
|
||||||
|
Closing += MainWindow_Closing;
|
||||||
|
//since MainWIndow implement IPublicAPI, so we need to finish ctor MainWindow object before
|
||||||
|
//PublicAPI invoke in plugin init methods. E.g FolderPlugin
|
||||||
|
ThreadPool.QueueUserWorkItem(o =>
|
||||||
|
{
|
||||||
|
Thread.Sleep(50);
|
||||||
|
PluginManager.Init(this);
|
||||||
|
});
|
||||||
|
ThreadPool.QueueUserWorkItem(o =>
|
||||||
|
{
|
||||||
|
Thread.Sleep(50);
|
||||||
|
PreLoadImages();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void pnlResult_ItemDropEvent(Result result, IDataObject dropDataObject, DragEventArgs args)
|
||||||
|
{
|
||||||
|
PluginPair pluginPair = PluginManager.AllPlugins.FirstOrDefault(o => o.Metadata.ID == result.PluginID);
|
||||||
|
if (ResultItemDropEvent != null && pluginPair != null)
|
||||||
|
{
|
||||||
|
foreach (var delegateHandler in ResultItemDropEvent.GetInvocationList())
|
||||||
|
{
|
||||||
|
if (delegateHandler.Target == pluginPair.Plugin)
|
||||||
|
{
|
||||||
|
delegateHandler.DynamicInvoke(result, dropDataObject, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool KListener_hookedKeyboardCallback(KeyEvent keyevent, int vkcode, SpecialKeyState state)
|
||||||
|
{
|
||||||
|
if (GlobalKeyboardEvent != null)
|
||||||
|
{
|
||||||
|
return GlobalKeyboardEvent((int)keyevent, vkcode, state);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PreLoadImages()
|
||||||
|
{
|
||||||
|
ImageLoader.ImageLoader.PreloadImages();
|
||||||
|
}
|
||||||
|
|
||||||
|
void pnlResult_RightMouseClickEvent(Result result)
|
||||||
|
{
|
||||||
|
ShowContextMenuFromResult(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow_Closing(object sender, CancelEventArgs e)
|
||||||
|
{
|
||||||
|
UserSettingStorage.Instance.WindowLeft = Left;
|
||||||
|
UserSettingStorage.Instance.WindowTop = Top;
|
||||||
|
UserSettingStorage.Instance.Save();
|
||||||
|
this.HideWox();
|
||||||
|
e.Cancel = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
if (UserSettingStorage.Instance.WindowLeft == 0
|
||||||
|
&& UserSettingStorage.Instance.WindowTop == 0)
|
||||||
|
{
|
||||||
|
Left = UserSettingStorage.Instance.WindowLeft
|
||||||
|
= (SystemParameters.PrimaryScreenWidth - ActualWidth) / 2;
|
||||||
|
Top = UserSettingStorage.Instance.WindowTop
|
||||||
|
= (SystemParameters.PrimaryScreenHeight - ActualHeight) / 5;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Left = UserSettingStorage.Instance.WindowLeft;
|
||||||
|
Top = UserSettingStorage.Instance.WindowTop;
|
||||||
|
}
|
||||||
|
|
||||||
|
InitProgressbarAnimation();
|
||||||
|
WindowIntelopHelper.DisableControlBox(this);
|
||||||
|
CheckUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CheckUpdate()
|
||||||
|
{
|
||||||
|
UpdaterManager.Instance.PrepareUpdateReady += OnPrepareUpdateReady;
|
||||||
|
UpdaterManager.Instance.UpdateError += OnUpdateError;
|
||||||
|
UpdaterManager.Instance.CheckUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnUpdateError(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
string updateError = InternationalizationManager.Instance.GetTranslation("update_wox_update_error");
|
||||||
|
MessageBox.Show(updateError);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnPrepareUpdateReady(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Dispatcher.Invoke(new Action(() =>
|
||||||
|
{
|
||||||
|
new WoxUpdate().ShowDialog();
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetHotkey(string hotkeyStr, EventHandler<HotkeyEventArgs> action)
|
||||||
|
{
|
||||||
|
var hotkey = new HotkeyModel(hotkeyStr);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
HotkeyManager.Current.AddOrReplace(hotkeyStr, hotkey.CharKey, hotkey.ModifierKeys, action);
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
string errorMsg = string.Format(InternationalizationManager.Instance.GetTranslation("registerHotkeyFailed"), hotkeyStr);
|
||||||
|
MessageBox.Show(errorMsg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RemoveHotkey(string hotkeyStr)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(hotkeyStr))
|
||||||
|
{
|
||||||
|
HotkeyManager.Current.Remove(hotkeyStr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetCustomPluginHotkey()
|
||||||
|
{
|
||||||
|
if (UserSettingStorage.Instance.CustomPluginHotkeys == null) return;
|
||||||
|
foreach (CustomPluginHotkey hotkey in UserSettingStorage.Instance.CustomPluginHotkeys)
|
||||||
|
{
|
||||||
|
CustomPluginHotkey hotkey1 = hotkey;
|
||||||
|
SetHotkey(hotkey.Hotkey, delegate
|
||||||
|
{
|
||||||
|
ShowApp();
|
||||||
|
ChangeQuery(hotkey1.ActionKeyword, true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnHotkey(object sender, HotkeyEventArgs e)
|
||||||
|
{
|
||||||
|
ToggleWox();
|
||||||
|
e.Handled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ToggleWox()
|
||||||
|
{
|
||||||
|
if (!IsVisible)
|
||||||
|
{
|
||||||
|
ShowWox();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
HideWox();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitProgressbarAnimation()
|
||||||
|
{
|
||||||
|
var da = new DoubleAnimation(progressBar.X2, ActualWidth + 100, new Duration(new TimeSpan(0, 0, 0, 0, 1600)));
|
||||||
|
var da1 = new DoubleAnimation(progressBar.X1, ActualWidth, new Duration(new TimeSpan(0, 0, 0, 0, 1600)));
|
||||||
|
Storyboard.SetTargetProperty(da, new PropertyPath("(Line.X2)"));
|
||||||
|
Storyboard.SetTargetProperty(da1, new PropertyPath("(Line.X1)"));
|
||||||
|
progressBarStoryboard.Children.Add(da);
|
||||||
|
progressBarStoryboard.Children.Add(da1);
|
||||||
|
progressBarStoryboard.RepeatBehavior = RepeatBehavior.Forever;
|
||||||
|
progressBar.Visibility = Visibility.Hidden;
|
||||||
|
progressBar.BeginStoryboard(progressBarStoryboard);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitialTray()
|
||||||
|
{
|
||||||
|
notifyIcon = new NotifyIcon { Text = "Wox", Icon = Properties.Resources.app, Visible = true };
|
||||||
|
notifyIcon.Click += (o, e) => ShowWox();
|
||||||
|
var open = new MenuItem("Open");
|
||||||
|
open.Click += (o, e) => ShowWox();
|
||||||
|
var setting = new MenuItem("Settings");
|
||||||
|
setting.Click += (o, e) => OpenSettingDialog();
|
||||||
|
var exit = new MenuItem("Exit");
|
||||||
|
exit.Click += (o, e) => CloseApp();
|
||||||
|
MenuItem[] childen = { open, setting, exit };
|
||||||
|
notifyIcon.ContextMenu = new ContextMenu(childen);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void TextBoxBase_OnTextChanged(object sender, TextChangedEventArgs e)
|
||||||
|
{
|
||||||
|
if (ignoreTextChange) { ignoreTextChange = false; return; }
|
||||||
|
|
||||||
|
lastQuery = tbQuery.Text;
|
||||||
|
toolTip.IsOpen = false;
|
||||||
|
pnlResult.Dirty = true;
|
||||||
|
int searchDelay = GetSearchDelay(lastQuery);
|
||||||
|
|
||||||
|
Dispatcher.DelayInvoke("UpdateSearch",
|
||||||
|
o =>
|
||||||
|
{
|
||||||
|
Dispatcher.DelayInvoke("ClearResults", i =>
|
||||||
|
{
|
||||||
|
// first try to use clear method inside pnlResult, which is more closer to the add new results
|
||||||
|
// and this will not bring splash issues.After waiting 100ms, if there still no results added, we
|
||||||
|
// must clear the result. otherwise, it will be confused why the query changed, but the results
|
||||||
|
// didn't.
|
||||||
|
if (pnlResult.Dirty) pnlResult.Clear();
|
||||||
|
}, TimeSpan.FromMilliseconds(100), null);
|
||||||
|
queryHasReturn = false;
|
||||||
|
Query query = new Query(lastQuery);
|
||||||
|
query.IsIntantQuery = searchDelay == 0;
|
||||||
|
FireBeforeWoxQueryEvent(query);
|
||||||
|
Query(query);
|
||||||
|
Dispatcher.DelayInvoke("ShowProgressbar", originQuery =>
|
||||||
|
{
|
||||||
|
if (!queryHasReturn && originQuery == tbQuery.Text && !string.IsNullOrEmpty(lastQuery))
|
||||||
|
{
|
||||||
|
StartProgress();
|
||||||
|
}
|
||||||
|
}, TimeSpan.FromMilliseconds(150), tbQuery.Text);
|
||||||
|
FireAfterWoxQueryEvent(query);
|
||||||
|
}, TimeSpan.FromMilliseconds(searchDelay));
|
||||||
|
}
|
||||||
|
|
||||||
|
private int GetSearchDelay(string query)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(query) && PluginManager.IsInstantQuery(query))
|
||||||
|
{
|
||||||
|
DebugHelper.WriteLine("execute query without delay");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
DebugHelper.WriteLine("execute query with 200ms delay");
|
||||||
|
return 200;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FireAfterWoxQueryEvent(Query q)
|
||||||
|
{
|
||||||
|
if (AfterWoxQueryEvent != null)
|
||||||
|
{
|
||||||
|
//We shouldn't let those events slow down real query
|
||||||
|
//so I put it in the new thread
|
||||||
|
ThreadPool.QueueUserWorkItem(o =>
|
||||||
|
{
|
||||||
|
AfterWoxQueryEvent(new WoxQueryEventArgs()
|
||||||
|
{
|
||||||
|
Query = q
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FireBeforeWoxQueryEvent(Query q)
|
||||||
|
{
|
||||||
|
if (BeforeWoxQueryEvent != null)
|
||||||
|
{
|
||||||
|
//We shouldn't let those events slow down real query
|
||||||
|
//so I put it in the new thread
|
||||||
|
ThreadPool.QueueUserWorkItem(o =>
|
||||||
|
{
|
||||||
|
BeforeWoxQueryEvent(new WoxQueryEventArgs()
|
||||||
|
{
|
||||||
|
Query = q
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Query(Query q)
|
||||||
|
{
|
||||||
|
PluginManager.Query(q);
|
||||||
|
StopProgress();
|
||||||
|
BackToResultMode();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BackToResultMode()
|
||||||
|
{
|
||||||
|
pnlResult.Visibility = Visibility.Visible;
|
||||||
|
pnlContextMenu.Visibility = Visibility.Collapsed;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Border_OnMouseDown(object sender, MouseButtonEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.ChangedButton == MouseButton.Left) DragMove();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void StartProgress()
|
||||||
|
{
|
||||||
|
progressBar.Visibility = Visibility.Visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void StopProgress()
|
||||||
|
{
|
||||||
|
progressBar.Visibility = Visibility.Hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HideWox()
|
||||||
|
{
|
||||||
|
Hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ShowWox(bool selectAll = true)
|
||||||
|
{
|
||||||
|
UserSettingStorage.Instance.IncreaseActivateTimes();
|
||||||
|
if (!double.IsNaN(Left) && !double.IsNaN(Top))
|
||||||
|
{
|
||||||
|
var origScreen = Screen.FromRectangle(new Rectangle((int)Left, (int)Top, (int)ActualWidth, (int)ActualHeight));
|
||||||
|
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
|
||||||
|
var coordX = (Left - origScreen.WorkingArea.Left) / (origScreen.WorkingArea.Width - ActualWidth);
|
||||||
|
var coordY = (Top - origScreen.WorkingArea.Top) / (origScreen.WorkingArea.Height - ActualHeight);
|
||||||
|
Left = (screen.WorkingArea.Width - ActualWidth) * coordX + screen.WorkingArea.Left;
|
||||||
|
Top = (screen.WorkingArea.Height - ActualHeight) * coordY + screen.WorkingArea.Top;
|
||||||
|
}
|
||||||
|
|
||||||
|
Show();
|
||||||
|
Activate();
|
||||||
|
Focus();
|
||||||
|
tbQuery.Focus();
|
||||||
|
if (selectAll) tbQuery.SelectAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void MainWindow_OnDeactivated(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (UserSettingStorage.Instance.HideWhenDeactive)
|
||||||
|
{
|
||||||
|
HideWox();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void TbQuery_OnPreviewKeyDown(object sender, KeyEventArgs e)
|
||||||
|
{
|
||||||
|
//when alt is pressed, the real key should be e.SystemKey
|
||||||
|
Key key = (e.Key == Key.System ? e.SystemKey : e.Key);
|
||||||
|
switch (key)
|
||||||
|
{
|
||||||
|
case Key.Escape:
|
||||||
|
if (IsInContextMenuMode)
|
||||||
|
{
|
||||||
|
BackToResultMode();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
HideWox();
|
||||||
|
}
|
||||||
|
e.Handled = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.Tab:
|
||||||
|
if (GlobalHotkey.Instance.CheckModifiers().ShiftPressed)
|
||||||
|
{
|
||||||
|
SelectPrevItem();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SelectNextItem();
|
||||||
|
}
|
||||||
|
e.Handled = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.N:
|
||||||
|
case Key.J:
|
||||||
|
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
|
||||||
|
{
|
||||||
|
SelectNextItem();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.P:
|
||||||
|
case Key.K:
|
||||||
|
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
|
||||||
|
{
|
||||||
|
SelectPrevItem();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.O:
|
||||||
|
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
|
||||||
|
{
|
||||||
|
if (IsInContextMenuMode)
|
||||||
|
{
|
||||||
|
BackToResultMode();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ShowContextMenuFromResult(GetActiveResult());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.Down:
|
||||||
|
SelectNextItem();
|
||||||
|
e.Handled = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.Up:
|
||||||
|
SelectPrevItem();
|
||||||
|
e.Handled = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.D:
|
||||||
|
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
|
||||||
|
{
|
||||||
|
pnlResult.SelectNextPage();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.PageDown:
|
||||||
|
pnlResult.SelectNextPage();
|
||||||
|
e.Handled = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.U:
|
||||||
|
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
|
||||||
|
{
|
||||||
|
pnlResult.SelectPrevPage();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.PageUp:
|
||||||
|
pnlResult.SelectPrevPage();
|
||||||
|
e.Handled = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.Back:
|
||||||
|
if (BackKeyDownEvent != null)
|
||||||
|
{
|
||||||
|
BackKeyDownEvent(new WoxKeyDownEventArgs()
|
||||||
|
{
|
||||||
|
Query = tbQuery.Text,
|
||||||
|
keyEventArgs = e
|
||||||
|
});
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.F1:
|
||||||
|
Process.Start("http://doc.getwox.com");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.Enter:
|
||||||
|
Result activeResult = GetActiveResult();
|
||||||
|
if (GlobalHotkey.Instance.CheckModifiers().ShiftPressed)
|
||||||
|
{
|
||||||
|
ShowContextMenuFromResult(activeResult);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SelectResult(activeResult);
|
||||||
|
}
|
||||||
|
e.Handled = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.D1:
|
||||||
|
SelectItem(1);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.D2:
|
||||||
|
SelectItem(2);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.D3:
|
||||||
|
SelectItem(3);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.D4:
|
||||||
|
SelectItem(4);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.D5:
|
||||||
|
SelectItem(5);
|
||||||
|
break;
|
||||||
|
case Key.D6:
|
||||||
|
SelectItem(6);
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SelectItem(int index)
|
||||||
|
{
|
||||||
|
int zeroBasedIndex = index - 1;
|
||||||
|
SpecialKeyState keyState = GlobalHotkey.Instance.CheckModifiers();
|
||||||
|
if (keyState.AltPressed || keyState.CtrlPressed)
|
||||||
|
{
|
||||||
|
List<Result> visibleResults = pnlResult.GetVisibleResults();
|
||||||
|
if (zeroBasedIndex < visibleResults.Count)
|
||||||
|
{
|
||||||
|
SelectResult(visibleResults[zeroBasedIndex]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool IsInContextMenuMode
|
||||||
|
{
|
||||||
|
get { return pnlContextMenu.Visibility == Visibility.Visible; }
|
||||||
|
}
|
||||||
|
|
||||||
|
private Result GetActiveResult()
|
||||||
|
{
|
||||||
|
if (IsInContextMenuMode)
|
||||||
|
{
|
||||||
|
return pnlContextMenu.GetActiveResult();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return pnlResult.GetActiveResult();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SelectPrevItem()
|
||||||
|
{
|
||||||
|
if (IsInContextMenuMode)
|
||||||
|
{
|
||||||
|
pnlContextMenu.SelectPrev();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pnlResult.SelectPrev();
|
||||||
|
}
|
||||||
|
toolTip.IsOpen = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SelectNextItem()
|
||||||
|
{
|
||||||
|
if (IsInContextMenuMode)
|
||||||
|
{
|
||||||
|
pnlContextMenu.SelectNext();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pnlResult.SelectNext();
|
||||||
|
}
|
||||||
|
toolTip.IsOpen = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SelectResult(Result result)
|
||||||
|
{
|
||||||
|
if (result != null)
|
||||||
|
{
|
||||||
|
if (result.Action != null)
|
||||||
|
{
|
||||||
|
bool hideWindow = result.Action(new ActionContext()
|
||||||
|
{
|
||||||
|
SpecialKeyState = GlobalHotkey.Instance.CheckModifiers()
|
||||||
|
});
|
||||||
|
if (hideWindow)
|
||||||
|
{
|
||||||
|
HideWox();
|
||||||
|
}
|
||||||
|
UserSelectedRecordStorage.Instance.Add(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateResultView(List<Result> list)
|
||||||
|
{
|
||||||
|
queryHasReturn = true;
|
||||||
|
progressBar.Dispatcher.Invoke(new Action(StopProgress));
|
||||||
|
if (list == null || list.Count == 0) return;
|
||||||
|
|
||||||
|
if (list.Count > 0)
|
||||||
|
{
|
||||||
|
list.ForEach(o =>
|
||||||
|
{
|
||||||
|
o.Score += UserSelectedRecordStorage.Instance.GetSelectedCount(o) * 5;
|
||||||
|
if (o.ContextMenu == null)
|
||||||
|
{
|
||||||
|
o.ContextMenu = new List<Result>();
|
||||||
|
}
|
||||||
|
HanleTopMost(o);
|
||||||
|
});
|
||||||
|
List<Result> l = list.Where(o => o.OriginQuery != null && o.OriginQuery.RawQuery == lastQuery).ToList();
|
||||||
|
Dispatcher.Invoke(new Action(() =>
|
||||||
|
{
|
||||||
|
pnlResult.AddResults(l);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HanleTopMost(Result result)
|
||||||
|
{
|
||||||
|
if (TopMostRecordStorage.Instance.IsTopMost(result))
|
||||||
|
{
|
||||||
|
result.ContextMenu.Add(new Result("Remove top most in this query", "Images\\down.png")
|
||||||
|
{
|
||||||
|
PluginDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
|
||||||
|
Action = _ =>
|
||||||
|
{
|
||||||
|
TopMostRecordStorage.Instance.Remove(result);
|
||||||
|
ShowMsg("Succeed", "", "");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result.ContextMenu.Add(new Result("Set as top most in this query", "Images\\up.png")
|
||||||
|
{
|
||||||
|
PluginDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
|
||||||
|
Action = _ =>
|
||||||
|
{
|
||||||
|
TopMostRecordStorage.Instance.Add(result);
|
||||||
|
ShowMsg("Succeed", "", "");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ShowContextMenuFromResult(Result result)
|
||||||
|
{
|
||||||
|
if (result.ContextMenu != null && result.ContextMenu.Count > 0)
|
||||||
|
{
|
||||||
|
pnlContextMenu.Clear();
|
||||||
|
pnlContextMenu.AddResults(result.ContextMenu);
|
||||||
|
pnlContextMenu.Visibility = Visibility.Visible;
|
||||||
|
pnlResult.Visibility = Visibility.Collapsed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ShellRun(string cmd, bool runAsAdministrator = false)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(cmd))
|
||||||
|
throw new ArgumentNullException();
|
||||||
|
|
||||||
|
WindowsShellRun.Start(cmd, runAsAdministrator);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
string errorMsg = string.Format(InternationalizationManager.Instance.GetTranslation("couldnotStartCmd"), cmd);
|
||||||
|
ShowMsg(errorMsg, ex.Message, null);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void MainWindow_OnDrop(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Data.GetDataPresent(DataFormats.FileDrop))
|
||||||
|
{
|
||||||
|
// Note that you can have more than one file.
|
||||||
|
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
|
||||||
|
if (files[0].ToLower().EndsWith(".wox"))
|
||||||
|
{
|
||||||
|
PluginManager.InstallPlugin(files[0]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("invalidWoxPluginFileFormat"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void TbQuery_OnPreviewDragOver(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
e.Handled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
850
Wox/su54u2mz.xrz
Normal file
850
Wox/su54u2mz.xrz
Normal file
@ -0,0 +1,850 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using System.Windows.Media.Animation;
|
||||||
|
using NHotkey;
|
||||||
|
using NHotkey.Wpf;
|
||||||
|
using Wox.Core.i18n;
|
||||||
|
using Wox.Core.Plugin;
|
||||||
|
using Wox.Core.Theme;
|
||||||
|
using Wox.Core.Updater;
|
||||||
|
using Wox.Core.UserSettings;
|
||||||
|
using Wox.Helper;
|
||||||
|
using Wox.Infrastructure;
|
||||||
|
using Wox.Infrastructure.Hotkey;
|
||||||
|
using Wox.Plugin;
|
||||||
|
using Wox.Storage;
|
||||||
|
using ContextMenu = System.Windows.Forms.ContextMenu;
|
||||||
|
using DataFormats = System.Windows.DataFormats;
|
||||||
|
using DragEventArgs = System.Windows.DragEventArgs;
|
||||||
|
using IDataObject = System.Windows.IDataObject;
|
||||||
|
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
|
||||||
|
using MenuItem = System.Windows.Forms.MenuItem;
|
||||||
|
using MessageBox = System.Windows.MessageBox;
|
||||||
|
using ToolTip = System.Windows.Controls.ToolTip;
|
||||||
|
|
||||||
|
namespace Wox
|
||||||
|
{
|
||||||
|
public partial class MainWindow : IPublicAPI
|
||||||
|
{
|
||||||
|
|
||||||
|
#region Properties
|
||||||
|
|
||||||
|
private readonly Storyboard progressBarStoryboard = new Storyboard();
|
||||||
|
private NotifyIcon notifyIcon;
|
||||||
|
private bool queryHasReturn;
|
||||||
|
private string lastQuery;
|
||||||
|
private ToolTip toolTip = new ToolTip();
|
||||||
|
|
||||||
|
private bool ignoreTextChange = false;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Public API
|
||||||
|
|
||||||
|
public void ChangeQuery(string query, bool requery = false)
|
||||||
|
{
|
||||||
|
Dispatcher.Invoke(new Action(() =>
|
||||||
|
{
|
||||||
|
tbQuery.Text = query;
|
||||||
|
tbQuery.CaretIndex = tbQuery.Text.Length;
|
||||||
|
if (requery)
|
||||||
|
{
|
||||||
|
TextBoxBase_OnTextChanged(null, null);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CloseApp()
|
||||||
|
{
|
||||||
|
Dispatcher.Invoke(new Action(() =>
|
||||||
|
{
|
||||||
|
notifyIcon.Visible = false;
|
||||||
|
Close();
|
||||||
|
Environment.Exit(0);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void HideApp()
|
||||||
|
{
|
||||||
|
Dispatcher.Invoke(new Action(HideWox));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ShowApp()
|
||||||
|
{
|
||||||
|
Dispatcher.Invoke(new Action(() => ShowWox()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ShowMsg(string title, string subTitle, string iconPath)
|
||||||
|
{
|
||||||
|
Dispatcher.Invoke(new Action(() =>
|
||||||
|
{
|
||||||
|
var m = new Msg { Owner = GetWindow(this) };
|
||||||
|
m.Show(title, subTitle, iconPath);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OpenSettingDialog()
|
||||||
|
{
|
||||||
|
Dispatcher.Invoke(new Action(() => WindowOpener.Open<SettingWindow>(this)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void StartLoadingBar()
|
||||||
|
{
|
||||||
|
Dispatcher.Invoke(new Action(StartProgress));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void StopLoadingBar()
|
||||||
|
{
|
||||||
|
Dispatcher.Invoke(new Action(StopProgress));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void InstallPlugin(string path)
|
||||||
|
{
|
||||||
|
Dispatcher.Invoke(new Action(() => PluginManager.InstallPlugin(path)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ReloadPlugins()
|
||||||
|
{
|
||||||
|
Dispatcher.Invoke(new Action(() => PluginManager.Init(this)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetTranslation(string key)
|
||||||
|
{
|
||||||
|
return InternationalizationManager.Instance.GetTranslation(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<PluginPair> GetAllPlugins()
|
||||||
|
{
|
||||||
|
return PluginManager.AllPlugins;
|
||||||
|
}
|
||||||
|
|
||||||
|
public event WoxKeyDownEventHandler BackKeyDownEvent;
|
||||||
|
public event WoxGlobalKeyboardEventHandler GlobalKeyboardEvent;
|
||||||
|
public event AfterWoxQueryEventHandler AfterWoxQueryEvent;
|
||||||
|
public event AfterWoxQueryEventHandler BeforeWoxQueryEvent;
|
||||||
|
public event ResultItemDropEventHandler ResultItemDropEvent;
|
||||||
|
|
||||||
|
public void PushResults(Query query, PluginMetadata plugin, List<Result> results)
|
||||||
|
{
|
||||||
|
results.ForEach(o =>
|
||||||
|
{
|
||||||
|
o.PluginDirectory = plugin.PluginDirectory;
|
||||||
|
o.PluginID = plugin.ID;
|
||||||
|
o.OriginQuery = query;
|
||||||
|
if (o.ContextMenu != null)
|
||||||
|
{
|
||||||
|
o.ContextMenu.ForEach(t =>
|
||||||
|
{
|
||||||
|
t.PluginDirectory = plugin.PluginDirectory;
|
||||||
|
t.PluginID = plugin.ID;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
UpdateResultView(results);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ShowContextMenu(PluginMetadata plugin, List<Result> results)
|
||||||
|
{
|
||||||
|
if (results != null && results.Count > 0)
|
||||||
|
{
|
||||||
|
results.ForEach(o =>
|
||||||
|
{
|
||||||
|
o.PluginDirectory = plugin.PluginDirectory;
|
||||||
|
o.PluginID = plugin.ID;
|
||||||
|
o.ContextMenu = null;
|
||||||
|
});
|
||||||
|
pnlContextMenu.Clear();
|
||||||
|
pnlContextMenu.AddResults(results);
|
||||||
|
pnlContextMenu.Visibility = Visibility.Visible;
|
||||||
|
pnlResult.Visibility = Visibility.Collapsed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
public MainWindow()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
ThreadPool.SetMaxThreads(30, 10);
|
||||||
|
ThreadPool.SetMinThreads(10, 5);
|
||||||
|
|
||||||
|
WebRequest.RegisterPrefix("data", new DataWebRequestFactory());
|
||||||
|
GlobalHotkey.Instance.hookedKeyboardCallback += KListener_hookedKeyboardCallback;
|
||||||
|
progressBar.ToolTip = toolTip;
|
||||||
|
InitialTray();
|
||||||
|
pnlResult.LeftMouseClickEvent += SelectResult;
|
||||||
|
pnlResult.ItemDropEvent += pnlResult_ItemDropEvent;
|
||||||
|
pnlContextMenu.LeftMouseClickEvent += SelectResult;
|
||||||
|
pnlResult.RightMouseClickEvent += pnlResult_RightMouseClickEvent;
|
||||||
|
|
||||||
|
ThemeManager.Theme.ChangeTheme(UserSettingStorage.Instance.Theme);
|
||||||
|
InternationalizationManager.Instance.ChangeLanguage(UserSettingStorage.Instance.Language);
|
||||||
|
|
||||||
|
SetHotkey(UserSettingStorage.Instance.Hotkey, OnHotkey);
|
||||||
|
SetCustomPluginHotkey();
|
||||||
|
|
||||||
|
Closing += MainWindow_Closing;
|
||||||
|
//since MainWIndow implement IPublicAPI, so we need to finish ctor MainWindow object before
|
||||||
|
//PublicAPI invoke in plugin init methods. E.g FolderPlugin
|
||||||
|
ThreadPool.QueueUserWorkItem(o =>
|
||||||
|
{
|
||||||
|
Thread.Sleep(50);
|
||||||
|
PluginManager.Init(this);
|
||||||
|
});
|
||||||
|
ThreadPool.QueueUserWorkItem(o =>
|
||||||
|
{
|
||||||
|
Thread.Sleep(50);
|
||||||
|
PreLoadImages();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void pnlResult_ItemDropEvent(Result result, IDataObject dropDataObject, DragEventArgs args)
|
||||||
|
{
|
||||||
|
PluginPair pluginPair = PluginManager.AllPlugins.FirstOrDefault(o => o.Metadata.ID == result.PluginID);
|
||||||
|
if (ResultItemDropEvent != null && pluginPair != null)
|
||||||
|
{
|
||||||
|
foreach (var delegateHandler in ResultItemDropEvent.GetInvocationList())
|
||||||
|
{
|
||||||
|
if (delegateHandler.Target == pluginPair.Plugin)
|
||||||
|
{
|
||||||
|
delegateHandler.DynamicInvoke(result, dropDataObject, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool KListener_hookedKeyboardCallback(KeyEvent keyevent, int vkcode, SpecialKeyState state)
|
||||||
|
{
|
||||||
|
if (GlobalKeyboardEvent != null)
|
||||||
|
{
|
||||||
|
return GlobalKeyboardEvent((int)keyevent, vkcode, state);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PreLoadImages()
|
||||||
|
{
|
||||||
|
ImageLoader.ImageLoader.PreloadImages();
|
||||||
|
}
|
||||||
|
|
||||||
|
void pnlResult_RightMouseClickEvent(Result result)
|
||||||
|
{
|
||||||
|
ShowContextMenuFromResult(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow_Closing(object sender, CancelEventArgs e)
|
||||||
|
{
|
||||||
|
UserSettingStorage.Instance.WindowLeft = Left;
|
||||||
|
UserSettingStorage.Instance.WindowTop = Top;
|
||||||
|
UserSettingStorage.Instance.Save();
|
||||||
|
this.HideWox();
|
||||||
|
e.Cancel = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
if (UserSettingStorage.Instance.WindowLeft == 0
|
||||||
|
&& UserSettingStorage.Instance.WindowTop == 0)
|
||||||
|
{
|
||||||
|
Left = UserSettingStorage.Instance.WindowLeft
|
||||||
|
= (SystemParameters.PrimaryScreenWidth - ActualWidth) / 2;
|
||||||
|
Top = UserSettingStorage.Instance.WindowTop
|
||||||
|
= (SystemParameters.PrimaryScreenHeight - ActualHeight) / 5;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Left = UserSettingStorage.Instance.WindowLeft;
|
||||||
|
Top = UserSettingStorage.Instance.WindowTop;
|
||||||
|
}
|
||||||
|
|
||||||
|
InitProgressbarAnimation();
|
||||||
|
WindowIntelopHelper.DisableControlBox(this);
|
||||||
|
CheckUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CheckUpdate()
|
||||||
|
{
|
||||||
|
UpdaterManager.Instance.PrepareUpdateReady += OnPrepareUpdateReady;
|
||||||
|
UpdaterManager.Instance.UpdateError += OnUpdateError;
|
||||||
|
UpdaterManager.Instance.CheckUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnUpdateError(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
string updateError = InternationalizationManager.Instance.GetTranslation("update_wox_update_error");
|
||||||
|
MessageBox.Show(updateError);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnPrepareUpdateReady(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Dispatcher.Invoke(new Action(() =>
|
||||||
|
{
|
||||||
|
new WoxUpdate().ShowDialog();
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetHotkey(string hotkeyStr, EventHandler<HotkeyEventArgs> action)
|
||||||
|
{
|
||||||
|
var hotkey = new HotkeyModel(hotkeyStr);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
HotkeyManager.Current.AddOrReplace(hotkeyStr, hotkey.CharKey, hotkey.ModifierKeys, action);
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
string errorMsg = string.Format(InternationalizationManager.Instance.GetTranslation("registerHotkeyFailed"), hotkeyStr);
|
||||||
|
MessageBox.Show(errorMsg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RemoveHotkey(string hotkeyStr)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(hotkeyStr))
|
||||||
|
{
|
||||||
|
HotkeyManager.Current.Remove(hotkeyStr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetCustomPluginHotkey()
|
||||||
|
{
|
||||||
|
if (UserSettingStorage.Instance.CustomPluginHotkeys == null) return;
|
||||||
|
foreach (CustomPluginHotkey hotkey in UserSettingStorage.Instance.CustomPluginHotkeys)
|
||||||
|
{
|
||||||
|
CustomPluginHotkey hotkey1 = hotkey;
|
||||||
|
SetHotkey(hotkey.Hotkey, delegate
|
||||||
|
{
|
||||||
|
ShowApp();
|
||||||
|
ChangeQuery(hotkey1.ActionKeyword, true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnHotkey(object sender, HotkeyEventArgs e)
|
||||||
|
{
|
||||||
|
ToggleWox();
|
||||||
|
e.Handled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ToggleWox()
|
||||||
|
{
|
||||||
|
if (!IsVisible)
|
||||||
|
{
|
||||||
|
ShowWox();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
HideWox();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitProgressbarAnimation()
|
||||||
|
{
|
||||||
|
var da = new DoubleAnimation(progressBar.X2, ActualWidth + 100, new Duration(new TimeSpan(0, 0, 0, 0, 1600)));
|
||||||
|
var da1 = new DoubleAnimation(progressBar.X1, ActualWidth, new Duration(new TimeSpan(0, 0, 0, 0, 1600)));
|
||||||
|
Storyboard.SetTargetProperty(da, new PropertyPath("(Line.X2)"));
|
||||||
|
Storyboard.SetTargetProperty(da1, new PropertyPath("(Line.X1)"));
|
||||||
|
progressBarStoryboard.Children.Add(da);
|
||||||
|
progressBarStoryboard.Children.Add(da1);
|
||||||
|
progressBarStoryboard.RepeatBehavior = RepeatBehavior.Forever;
|
||||||
|
progressBar.Visibility = Visibility.Hidden;
|
||||||
|
progressBar.BeginStoryboard(progressBarStoryboard);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitialTray()
|
||||||
|
{
|
||||||
|
notifyIcon = new NotifyIcon { Text = "Wox", Icon = Properties.Resources.app, Visible = true };
|
||||||
|
notifyIcon.Click += (o, e) => ShowWox();
|
||||||
|
var open = new MenuItem("Open");
|
||||||
|
open.Click += (o, e) => ShowWox();
|
||||||
|
var setting = new MenuItem("Settings");
|
||||||
|
setting.Click += (o, e) => OpenSettingDialog();
|
||||||
|
var exit = new MenuItem("Exit");
|
||||||
|
exit.Click += (o, e) => CloseApp();
|
||||||
|
MenuItem[] childen = { open, setting, exit };
|
||||||
|
notifyIcon.ContextMenu = new ContextMenu(childen);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void TextBoxBase_OnTextChanged(object sender, TextChangedEventArgs e)
|
||||||
|
{
|
||||||
|
if (ignoreTextChange) { ignoreTextChange = false; return; }
|
||||||
|
|
||||||
|
lastQuery = tbQuery.Text;
|
||||||
|
toolTip.IsOpen = false;
|
||||||
|
pnlResult.Dirty = true;
|
||||||
|
int searchDelay = GetSearchDelay(lastQuery);
|
||||||
|
|
||||||
|
Dispatcher.DelayInvoke("UpdateSearch",
|
||||||
|
o =>
|
||||||
|
{
|
||||||
|
Dispatcher.DelayInvoke("ClearResults", i =>
|
||||||
|
{
|
||||||
|
// first try to use clear method inside pnlResult, which is more closer to the add new results
|
||||||
|
// and this will not bring splash issues.After waiting 100ms, if there still no results added, we
|
||||||
|
// must clear the result. otherwise, it will be confused why the query changed, but the results
|
||||||
|
// didn't.
|
||||||
|
if (pnlResult.Dirty) pnlResult.Clear();
|
||||||
|
}, TimeSpan.FromMilliseconds(100), null);
|
||||||
|
queryHasReturn = false;
|
||||||
|
Query query = new Query(lastQuery);
|
||||||
|
query.IsIntantQuery = searchDelay == 0;
|
||||||
|
FireBeforeWoxQueryEvent(query);
|
||||||
|
Query(query);
|
||||||
|
Dispatcher.DelayInvoke("ShowProgressbar", originQuery =>
|
||||||
|
{
|
||||||
|
if (!queryHasReturn && originQuery == tbQuery.Text && !string.IsNullOrEmpty(lastQuery))
|
||||||
|
{
|
||||||
|
StartProgress();
|
||||||
|
}
|
||||||
|
}, TimeSpan.FromMilliseconds(150), tbQuery.Text);
|
||||||
|
FireAfterWoxQueryEvent(query);
|
||||||
|
}, TimeSpan.FromMilliseconds(searchDelay));
|
||||||
|
}
|
||||||
|
|
||||||
|
private int GetSearchDelay(string query)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(query) && PluginManager.IsInstantQuery(query))
|
||||||
|
{
|
||||||
|
DebugHelper.WriteLine("execute query without delay");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
DebugHelper.WriteLine("execute query with 200ms delay");
|
||||||
|
return 200;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FireAfterWoxQueryEvent(Query q)
|
||||||
|
{
|
||||||
|
if (AfterWoxQueryEvent != null)
|
||||||
|
{
|
||||||
|
//We shouldn't let those events slow down real query
|
||||||
|
//so I put it in the new thread
|
||||||
|
ThreadPool.QueueUserWorkItem(o =>
|
||||||
|
{
|
||||||
|
AfterWoxQueryEvent(new WoxQueryEventArgs()
|
||||||
|
{
|
||||||
|
Query = q
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FireBeforeWoxQueryEvent(Query q)
|
||||||
|
{
|
||||||
|
if (BeforeWoxQueryEvent != null)
|
||||||
|
{
|
||||||
|
//We shouldn't let those events slow down real query
|
||||||
|
//so I put it in the new thread
|
||||||
|
ThreadPool.QueueUserWorkItem(o =>
|
||||||
|
{
|
||||||
|
BeforeWoxQueryEvent(new WoxQueryEventArgs()
|
||||||
|
{
|
||||||
|
Query = q
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Query(Query q)
|
||||||
|
{
|
||||||
|
PluginManager.Query(q);
|
||||||
|
StopProgress();
|
||||||
|
BackToResultMode();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BackToResultMode()
|
||||||
|
{
|
||||||
|
pnlResult.Visibility = Visibility.Visible;
|
||||||
|
pnlContextMenu.Visibility = Visibility.Collapsed;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Border_OnMouseDown(object sender, MouseButtonEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.ChangedButton == MouseButton.Left) DragMove();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void StartProgress()
|
||||||
|
{
|
||||||
|
progressBar.Visibility = Visibility.Visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void StopProgress()
|
||||||
|
{
|
||||||
|
progressBar.Visibility = Visibility.Hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HideWox()
|
||||||
|
{
|
||||||
|
Hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ShowWox(bool selectAll = true)
|
||||||
|
{
|
||||||
|
UserSettingStorage.Instance.IncreaseActivateTimes();
|
||||||
|
if (!double.IsNaN(Left) && !double.IsNaN(Top))
|
||||||
|
{
|
||||||
|
var origScreen = Screen.FromRectangle(new Rectangle((int)Left, (int)Top, (int)ActualWidth, (int)ActualHeight));
|
||||||
|
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
|
||||||
|
var coordX = (Left - origScreen.WorkingArea.Left) / (origScreen.WorkingArea.Width - ActualWidth);
|
||||||
|
var coordY = (Top - origScreen.WorkingArea.Top) / (origScreen.WorkingArea.Height - ActualHeight);
|
||||||
|
Left = (screen.WorkingArea.Width - ActualWidth) * coordX + screen.WorkingArea.Left;
|
||||||
|
Top = (screen.WorkingArea.Height - ActualHeight) * coordY + screen.WorkingArea.Top;
|
||||||
|
}
|
||||||
|
|
||||||
|
Show();
|
||||||
|
Activate();
|
||||||
|
Focus();
|
||||||
|
tbQuery.Focus();
|
||||||
|
if (selectAll) tbQuery.SelectAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void MainWindow_OnDeactivated(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (UserSettingStorage.Instance.HideWhenDeactive)
|
||||||
|
{
|
||||||
|
HideWox();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void TbQuery_OnPreviewKeyDown(object sender, KeyEventArgs e)
|
||||||
|
{
|
||||||
|
//when alt is pressed, the real key should be e.SystemKey
|
||||||
|
Key key = (e.Key == Key.System ? e.SystemKey : e.Key);
|
||||||
|
switch (key)
|
||||||
|
{
|
||||||
|
case Key.Escape:
|
||||||
|
if (IsInContextMenuMode)
|
||||||
|
{
|
||||||
|
BackToResultMode();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
HideWox();
|
||||||
|
}
|
||||||
|
e.Handled = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.Tab:
|
||||||
|
if (GlobalHotkey.Instance.CheckModifiers().ShiftPressed)
|
||||||
|
{
|
||||||
|
SelectPrevItem();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SelectNextItem();
|
||||||
|
}
|
||||||
|
e.Handled = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.N:
|
||||||
|
case Key.J:
|
||||||
|
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
|
||||||
|
{
|
||||||
|
SelectNextItem();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.P:
|
||||||
|
case Key.K:
|
||||||
|
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
|
||||||
|
{
|
||||||
|
SelectPrevItem();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.O:
|
||||||
|
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
|
||||||
|
{
|
||||||
|
if (IsInContextMenuMode)
|
||||||
|
{
|
||||||
|
BackToResultMode();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ShowContextMenuFromResult(GetActiveResult());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.Down:
|
||||||
|
SelectNextItem();
|
||||||
|
e.Handled = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.Up:
|
||||||
|
SelectPrevItem();
|
||||||
|
e.Handled = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.D:
|
||||||
|
if (GlobalHotkey.Instance.CheckModifiers().AltPressed)
|
||||||
|
{
|
||||||
|
pnlResult.SelectNextPage();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.PageDown:
|
||||||
|
pnlResult.SelectNextPage();
|
||||||
|
e.Handled = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.U:
|
||||||
|
if (GlobalHotkey.Instance.CheckModifiers().AltPressed)
|
||||||
|
{
|
||||||
|
pnlResult.SelectPrevPage();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.PageUp:
|
||||||
|
pnlResult.SelectPrevPage();
|
||||||
|
e.Handled = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.Back:
|
||||||
|
if (BackKeyDownEvent != null)
|
||||||
|
{
|
||||||
|
BackKeyDownEvent(new WoxKeyDownEventArgs()
|
||||||
|
{
|
||||||
|
Query = tbQuery.Text,
|
||||||
|
keyEventArgs = e
|
||||||
|
});
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.F1:
|
||||||
|
Process.Start("http://doc.getwox.com");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.Enter:
|
||||||
|
Result activeResult = GetActiveResult();
|
||||||
|
if (GlobalHotkey.Instance.CheckModifiers().ShiftPressed)
|
||||||
|
{
|
||||||
|
ShowContextMenuFromResult(activeResult);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SelectResult(activeResult);
|
||||||
|
}
|
||||||
|
e.Handled = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.D1:
|
||||||
|
SelectItem(1);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.D2:
|
||||||
|
SelectItem(2);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.D3:
|
||||||
|
SelectItem(3);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.D4:
|
||||||
|
SelectItem(4);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.D5:
|
||||||
|
SelectItem(5);
|
||||||
|
break;
|
||||||
|
case Key.D6:
|
||||||
|
SelectItem(6);
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SelectItem(int index)
|
||||||
|
{
|
||||||
|
int zeroBasedIndex = index - 1;
|
||||||
|
SpecialKeyState keyState = GlobalHotkey.Instance.CheckModifiers();
|
||||||
|
if (keyState.AltPressed || keyState.CtrlPressed)
|
||||||
|
{
|
||||||
|
List<Result> visibleResults = pnlResult.GetVisibleResults();
|
||||||
|
if (zeroBasedIndex < visibleResults.Count)
|
||||||
|
{
|
||||||
|
SelectResult(visibleResults[zeroBasedIndex]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool IsInContextMenuMode
|
||||||
|
{
|
||||||
|
get { return pnlContextMenu.Visibility == Visibility.Visible; }
|
||||||
|
}
|
||||||
|
|
||||||
|
private Result GetActiveResult()
|
||||||
|
{
|
||||||
|
if (IsInContextMenuMode)
|
||||||
|
{
|
||||||
|
return pnlContextMenu.GetActiveResult();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return pnlResult.GetActiveResult();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SelectPrevItem()
|
||||||
|
{
|
||||||
|
if (IsInContextMenuMode)
|
||||||
|
{
|
||||||
|
pnlContextMenu.SelectPrev();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pnlResult.SelectPrev();
|
||||||
|
}
|
||||||
|
toolTip.IsOpen = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SelectNextItem()
|
||||||
|
{
|
||||||
|
if (IsInContextMenuMode)
|
||||||
|
{
|
||||||
|
pnlContextMenu.SelectNext();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pnlResult.SelectNext();
|
||||||
|
}
|
||||||
|
toolTip.IsOpen = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SelectResult(Result result)
|
||||||
|
{
|
||||||
|
if (result != null)
|
||||||
|
{
|
||||||
|
if (result.Action != null)
|
||||||
|
{
|
||||||
|
bool hideWindow = result.Action(new ActionContext()
|
||||||
|
{
|
||||||
|
SpecialKeyState = GlobalHotkey.Instance.CheckModifiers()
|
||||||
|
});
|
||||||
|
if (hideWindow)
|
||||||
|
{
|
||||||
|
HideWox();
|
||||||
|
}
|
||||||
|
UserSelectedRecordStorage.Instance.Add(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateResultView(List<Result> list)
|
||||||
|
{
|
||||||
|
queryHasReturn = true;
|
||||||
|
progressBar.Dispatcher.Invoke(new Action(StopProgress));
|
||||||
|
if (list == null || list.Count == 0) return;
|
||||||
|
|
||||||
|
if (list.Count > 0)
|
||||||
|
{
|
||||||
|
list.ForEach(o =>
|
||||||
|
{
|
||||||
|
o.Score += UserSelectedRecordStorage.Instance.GetSelectedCount(o) * 5;
|
||||||
|
if (o.ContextMenu == null)
|
||||||
|
{
|
||||||
|
o.ContextMenu = new List<Result>();
|
||||||
|
}
|
||||||
|
HanleTopMost(o);
|
||||||
|
});
|
||||||
|
List<Result> l = list.Where(o => o.OriginQuery != null && o.OriginQuery.RawQuery == lastQuery).ToList();
|
||||||
|
Dispatcher.Invoke(new Action(() =>
|
||||||
|
{
|
||||||
|
pnlResult.AddResults(l);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HanleTopMost(Result result)
|
||||||
|
{
|
||||||
|
if (TopMostRecordStorage.Instance.IsTopMost(result))
|
||||||
|
{
|
||||||
|
result.ContextMenu.Add(new Result("Remove top most in this query", "Images\\down.png")
|
||||||
|
{
|
||||||
|
PluginDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
|
||||||
|
Action = _ =>
|
||||||
|
{
|
||||||
|
TopMostRecordStorage.Instance.Remove(result);
|
||||||
|
ShowMsg("Succeed", "", "");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result.ContextMenu.Add(new Result("Set as top most in this query", "Images\\up.png")
|
||||||
|
{
|
||||||
|
PluginDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
|
||||||
|
Action = _ =>
|
||||||
|
{
|
||||||
|
TopMostRecordStorage.Instance.Add(result);
|
||||||
|
ShowMsg("Succeed", "", "");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ShowContextMenuFromResult(Result result)
|
||||||
|
{
|
||||||
|
if (result.ContextMenu != null && result.ContextMenu.Count > 0)
|
||||||
|
{
|
||||||
|
pnlContextMenu.Clear();
|
||||||
|
pnlContextMenu.AddResults(result.ContextMenu);
|
||||||
|
pnlContextMenu.Visibility = Visibility.Visible;
|
||||||
|
pnlResult.Visibility = Visibility.Collapsed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ShellRun(string cmd, bool runAsAdministrator = false)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(cmd))
|
||||||
|
throw new ArgumentNullException();
|
||||||
|
|
||||||
|
WindowsShellRun.Start(cmd, runAsAdministrator);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
string errorMsg = string.Format(InternationalizationManager.Instance.GetTranslation("couldnotStartCmd"), cmd);
|
||||||
|
ShowMsg(errorMsg, ex.Message, null);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void MainWindow_OnDrop(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Data.GetDataPresent(DataFormats.FileDrop))
|
||||||
|
{
|
||||||
|
// Note that you can have more than one file.
|
||||||
|
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
|
||||||
|
if (files[0].ToLower().EndsWith(".wox"))
|
||||||
|
{
|
||||||
|
PluginManager.InstallPlugin(files[0]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("invalidWoxPluginFileFormat"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void TbQuery_OnPreviewDragOver(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
e.Handled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user