Improve instant search ue

This commit is contained in:
qianlifeng
2015-02-04 23:16:41 +08:00
parent 5d9a94466a
commit 1d3f1fd7d0
23 changed files with 503 additions and 367 deletions

View File

@@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
@@ -20,6 +21,9 @@ namespace Wox.Plugin.CMD
public List<Result> Query(Query query) public List<Result> Query(Query query)
{ {
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
List<Result> results = new List<Result>(); List<Result> results = new List<Result>();
List<Result> pushedResults = new List<Result>(); List<Result> pushedResults = new List<Result>();
if (query.Search == ">") if (query.Search == ">")
@@ -76,6 +80,8 @@ namespace Wox.Plugin.CMD
catch (Exception) { } catch (Exception) { }
} }
stopwatch.Stop();
DebugHelper.WriteLine("CMD:" + stopwatch.ElapsedMilliseconds + "ms");
return results; return results;
} }

View File

@@ -326,8 +326,6 @@ namespace Wox.Plugin.ControlPanel
private static bool EnumRes(IntPtr hModule, IntPtr lpszType, IntPtr lpszName, IntPtr lParam) private static bool EnumRes(IntPtr hModule, IntPtr lpszType, IntPtr lpszName, IntPtr lParam)
{ {
//Debug.WriteLine("Type: " + GET_RESOURCE_NAME(lpszType));
//Debug.WriteLine("Name: " + GET_RESOURCE_NAME(lpszName));
defaultIconPtr = lpszName; defaultIconPtr = lpszName;
return false; return false;
} }

View File

@@ -9,14 +9,14 @@ using Control = System.Windows.Controls.Control;
namespace Wox.Plugin.Folder namespace Wox.Plugin.Folder
{ {
public class FolderPlugin : IPlugin, ISettingProvider,IPluginI18n public class FolderPlugin : IPlugin, ISettingProvider, IPluginI18n
{ {
private static List<string> driverNames; private static List<string> driverNames;
private PluginInitContext context; private PluginInitContext context;
public Control CreateSettingPanel() public Control CreateSettingPanel()
{ {
return new FileSystemSettings(context); return new FileSystemSettings(context.API);
} }
public void Init(PluginInitContext context) public void Init(PluginInitContext context)
@@ -32,11 +32,38 @@ namespace Wox.Plugin.Folder
} }
} }
void API_ResultItemDropEvent(Result result, IDataObject dropObject,DragEventArgs e) void API_ResultItemDropEvent(Result result, IDataObject dropObject, DragEventArgs e)
{ {
if (dropObject.GetDataPresent(DataFormats.FileDrop))
{
HanldeFilesDrop(result, dropObject);
}
e.Handled = true; e.Handled = true;
} }
private void HanldeFilesDrop(Result targetResult, IDataObject dropObject)
{
List<string> files = ((string[])dropObject.GetData(DataFormats.FileDrop, false)).ToList();
context.API.ShowContextMenu(context.CurrentPluginMetadata, GetContextMenusForFileDrop(targetResult, files));
}
private static List<Result> GetContextMenusForFileDrop(Result targetResult, List<string> files)
{
List<Result> contextMenus = new List<Result>();
string folderPath = ((FolderLink) targetResult.ContextData).Path;
contextMenus.Add(new Result()
{
Title = "Copy to this folder",
IcoPath = "Images/copy.png",
Action = _ =>
{
MessageBox.Show("Copy");
return true;
}
});
return contextMenus;
}
private void ApiBackKeyDownEvent(WoxKeyDownEventArgs e) private void ApiBackKeyDownEvent(WoxKeyDownEventArgs e)
{ {
string query = e.Query; string query = e.Query;
@@ -84,7 +111,8 @@ namespace Wox.Plugin.Folder
} }
context.API.ChangeQuery(item.Path); context.API.ChangeQuery(item.Path);
return false; return false;
} },
ContextData = item
}).ToList(); }).ToList();
if (driverNames != null && !driverNames.Any(input.StartsWith)) if (driverNames != null && !driverNames.Any(input.StartsWith))
@@ -98,9 +126,7 @@ namespace Wox.Plugin.Folder
results.AddRange(QueryInternal_Directory_Exists(input)); results.AddRange(QueryInternal_Directory_Exists(input));
return results; return results;
} } private void InitialDriverList()
private void InitialDriverList()
{ {
if (driverNames == null) if (driverNames == null)
{ {

View File

@@ -13,11 +13,11 @@ namespace Wox.Plugin.Folder
/// </summary> /// </summary>
public partial class FileSystemSettings : UserControl public partial class FileSystemSettings : UserControl
{ {
PluginInitContext context; private IPublicAPI woxAPI;
public FileSystemSettings(PluginInitContext context) public FileSystemSettings(IPublicAPI woxAPI)
{ {
this.context = context; this.woxAPI = woxAPI;
InitializeComponent(); InitializeComponent();
lbxFolders.ItemsSource = FolderStorage.Instance.FolderLinks; lbxFolders.ItemsSource = FolderStorage.Instance.FolderLinks;
} }
@@ -27,7 +27,7 @@ namespace Wox.Plugin.Folder
var selectedFolder = lbxFolders.SelectedItem as FolderLink; var selectedFolder = lbxFolders.SelectedItem as FolderLink;
if (selectedFolder != null) if (selectedFolder != null)
{ {
string msg = string.Format(context.API.GetTranslation("wox_plugin_folder_delete_folder_link"), selectedFolder.Path); string msg = string.Format(woxAPI.GetTranslation("wox_plugin_folder_delete_folder_link"), selectedFolder.Path);
if (MessageBox.Show(msg, string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.Yes) if (MessageBox.Show(msg, string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{ {
@@ -37,7 +37,7 @@ namespace Wox.Plugin.Folder
} }
else else
{ {
string warning = context.API.GetTranslation("wox_plugin_folder_select_folder_link_warning"); string warning = woxAPI.GetTranslation("wox_plugin_folder_select_folder_link_warning");
MessageBox.Show(warning); MessageBox.Show(warning);
} }
} }
@@ -61,7 +61,7 @@ namespace Wox.Plugin.Folder
} }
else else
{ {
string warning = context.API.GetTranslation("wox_plugin_folder_select_folder_link_warning"); string warning = woxAPI.GetTranslation("wox_plugin_folder_select_folder_link_warning");
MessageBox.Show(warning); MessageBox.Show(warning);
} }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 898 B

View File

@@ -1,120 +1,123 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="12.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>{787B8AA6-CA93-4C84-96FE-DF31110AD1C4}</ProjectGuid> <ProjectGuid>{787B8AA6-CA93-4C84-96FE-DF31110AD1C4}</ProjectGuid>
<OutputType>Library</OutputType> <OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Wox.Plugin.Folder</RootNamespace> <RootNamespace>Wox.Plugin.Folder</RootNamespace>
<AssemblyName>Wox.Plugin.Folder</AssemblyName> <AssemblyName>Wox.Plugin.Folder</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion> <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
<RestorePackages>true</RestorePackages> <RestorePackages>true</RestorePackages>
<TargetFrameworkProfile /> <TargetFrameworkProfile />
</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.Folder\</OutputPath> <OutputPath>..\..\Output\Debug\Plugins\Wox.Plugin.Folder\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit> <Prefer32Bit>false</Prefer32Bit>
</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.Folder\</OutputPath> <OutputPath>..\..\Output\Release\Plugins\Wox.Plugin.Folder\</OutputPath>
<DefineConstants>TRACE</DefineConstants> <DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit> <Prefer32Bit>false</Prefer32Bit>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Newtonsoft.Json"> <Reference Include="Newtonsoft.Json">
<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>
<Private>True</Private> <Private>True</Private>
</Reference> </Reference>
<Reference Include="PresentationCore" /> <Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" /> <Reference Include="PresentationFramework" />
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Windows.Forms" /> <Reference Include="System.Windows.Forms" />
<Reference Include="System.Xaml" /> <Reference Include="System.Xaml" />
<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" />
<Reference Include="WindowsBase" /> <Reference Include="WindowsBase" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="FolderLink.cs" /> <Compile Include="FolderLink.cs" />
<Compile Include="FolderPlugin.cs" /> <Compile Include="FolderPlugin.cs" />
<Compile Include="FolderPluginSettings.xaml.cs"> <Compile Include="FolderPluginSettings.xaml.cs">
<DependentUpon>FolderPluginSettings.xaml</DependentUpon> <DependentUpon>FolderPluginSettings.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="FolderStorage.cs" /> <Compile Include="FolderStorage.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="packages.config" /> <None Include="packages.config" />
<None Include="plugin.json"> <None Include="plugin.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Page Include="FolderPluginSettings.xaml"> <Page Include="FolderPluginSettings.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType> <SubType>Designer</SubType>
</Page> </Page>
<Content Include="Languages\en.xaml"> <None Include="Images\copy.png">
<Generator>MSBuild:Compile</Generator> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<SubType>Designer</SubType> </None>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <Content Include="Languages\en.xaml">
</Content> <Generator>MSBuild:Compile</Generator>
<None Include="Languages\zh-cn.xaml"> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<SubType>Designer</SubType> </Content>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <None Include="Languages\zh-cn.xaml">
</None> <Generator>MSBuild:Compile</Generator>
<None Include="Languages\zh-tw.xaml"> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<SubType>Designer</SubType> </None>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <None Include="Languages\zh-tw.xaml">
</None> <Generator>MSBuild:Compile</Generator>
</ItemGroup> <SubType>Designer</SubType>
<ItemGroup> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<ProjectReference Include="..\..\Wox.Infrastructure\Wox.Infrastructure.csproj"> </None>
<Project>{4fd29318-a8ab-4d8f-aa47-60bc241b8da3}</Project> </ItemGroup>
<Name>Wox.Infrastructure</Name> <ItemGroup>
</ProjectReference> <ProjectReference Include="..\..\Wox.Infrastructure\Wox.Infrastructure.csproj">
<ProjectReference Include="..\..\Wox.Plugin\Wox.Plugin.csproj"> <Project>{4fd29318-a8ab-4d8f-aa47-60bc241b8da3}</Project>
<Project>{8451ecdd-2ea4-4966-bb0a-7bbc40138e80}</Project> <Name>Wox.Infrastructure</Name>
<Name>Wox.Plugin</Name> </ProjectReference>
</ProjectReference> <ProjectReference Include="..\..\Wox.Plugin\Wox.Plugin.csproj">
</ItemGroup> <Project>{8451ecdd-2ea4-4966-bb0a-7bbc40138e80}</Project>
<ItemGroup> <Name>Wox.Plugin</Name>
<None Include="Images\folder.png"> </ProjectReference>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </ItemGroup>
</None> <ItemGroup>
</ItemGroup> <None Include="Images\folder.png">
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" /> </None>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> </ItemGroup>
<PropertyGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。启用“NuGet 程序包还原”可下载这些程序包。有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText> <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
</PropertyGroup> <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" /> <PropertyGroup>
</Target> <ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。启用“NuGet 程序包还原”可下载这些程序包。有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. </PropertyGroup>
Other similar extension points exist, see Microsoft.Common.targets. <Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
<Target Name="BeforeBuild"> </Target>
</Target> <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
<Target Name="AfterBuild"> Other similar extension points exist, see Microsoft.Common.targets.
</Target> <Target Name="BeforeBuild">
--> </Target>
<Target Name="AfterBuild">
</Target>
-->
</Project> </Project>

View File

@@ -2,6 +2,7 @@
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Threading; using System.Threading;
using Wox.Infrastructure;
namespace Wox.Plugin.Program namespace Wox.Plugin.Program
{ {
@@ -15,7 +16,7 @@ namespace Wox.Plugin.Program
if (watchedPath.Contains(path)) return; if (watchedPath.Contains(path)) return;
if (!Directory.Exists(path)) if (!Directory.Exists(path))
{ {
Debug.WriteLine(string.Format("FileChangeWatcher: {0} doesn't exist", path),"WoxDebug"); DebugHelper.WriteLine(string.Format("FileChangeWatcher: {0} doesn't exist", path));
return; return;
} }

View File

@@ -108,16 +108,17 @@ namespace Wox.Plugin.Program
{ {
programs = ProgramCacheStorage.Instance.Programs; programs = ProgramCacheStorage.Instance.Programs;
} }
Debug.WriteLine(string.Format("Preload {0} programs from cache", programs.Count), "Wox"); DebugHelper.WriteLine(string.Format("Preload {0} programs from cache", programs.Count));
using (new Timeit("Program Index")) using (new Timeit("Program Index"))
{ {
IndexPrograms(); IndexPrograms();
} }
} }
void API_ResultItemDropEvent(Result result, IDataObject dropObject, DragEventArgs args) void API_ResultItemDropEvent(Result result, IDataObject dropObject, DragEventArgs e)
{ {
args.Handled = true;
e.Handled = true;
} }
public static void IndexPrograms() public static void IndexPrograms()

View File

@@ -1,153 +1,153 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="12.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>{FDB3555B-58EF-4AE6-B5F1-904719637AB4}</ProjectGuid> <ProjectGuid>{FDB3555B-58EF-4AE6-B5F1-904719637AB4}</ProjectGuid>
<OutputType>Library</OutputType> <OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Wox.Plugin.Program</RootNamespace> <RootNamespace>Wox.Plugin.Program</RootNamespace>
<AssemblyName>Wox.Plugin.Program</AssemblyName> <AssemblyName>Wox.Plugin.Program</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion> <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
<RestorePackages>true</RestorePackages> <RestorePackages>true</RestorePackages>
<TargetFrameworkProfile /> <TargetFrameworkProfile />
</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.Program\</OutputPath> <OutputPath>..\..\Output\Debug\Plugins\Wox.Plugin.Program\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit> <Prefer32Bit>false</Prefer32Bit>
</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.Program\</OutputPath> <OutputPath>..\..\Output\Release\Plugins\Wox.Plugin.Program\</OutputPath>
<DefineConstants>TRACE</DefineConstants> <DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit> <Prefer32Bit>false</Prefer32Bit>
</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="PresentationFramework" /> <Reference Include="PresentationFramework" />
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Windows.Forms" /> <Reference Include="System.Windows.Forms" />
<Reference Include="System.Xaml" /> <Reference Include="System.Xaml" />
<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" />
<Reference Include="WindowsBase" /> <Reference Include="WindowsBase" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="FileChangeWatcher.cs" /> <Compile Include="FileChangeWatcher.cs" />
<Compile Include="IProgramSource.cs" /> <Compile Include="IProgramSource.cs" />
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="ProgramCacheStorage.cs" /> <Compile Include="ProgramCacheStorage.cs" />
<Compile Include="Programs.cs" /> <Compile Include="Programs.cs" />
<Compile Include="ProgramSetting.xaml.cs"> <Compile Include="ProgramSetting.xaml.cs">
<DependentUpon>ProgramSetting.xaml</DependentUpon> <DependentUpon>ProgramSetting.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="ProgramSource.cs" /> <Compile Include="ProgramSource.cs" />
<Compile Include="ProgramSources\AppPathsProgramSource.cs" /> <Compile Include="ProgramSources\AppPathsProgramSource.cs" />
<Compile Include="ProgramSources\CommonStartMenuProgramSource.cs" /> <Compile Include="ProgramSources\CommonStartMenuProgramSource.cs" />
<Compile Include="ProgramSources\FileSystemProgramSource.cs" /> <Compile Include="ProgramSources\FileSystemProgramSource.cs" />
<Compile Include="ProgramSources\UserStartMenuProgramSource.cs" /> <Compile Include="ProgramSources\UserStartMenuProgramSource.cs" />
<Compile Include="ProgramStorage.cs" /> <Compile Include="ProgramStorage.cs" />
<Compile Include="ProgramSuffixes.xaml.cs"> <Compile Include="ProgramSuffixes.xaml.cs">
<DependentUpon>ProgramSuffixes.xaml</DependentUpon> <DependentUpon>ProgramSuffixes.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="StringEmptyConverter.cs" /> <Compile Include="StringEmptyConverter.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="packages.config" /> <None Include="packages.config" />
<None Include="plugin.json"> <None Include="plugin.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="Images\program.png"> <None Include="Images\program.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
<None Include="Images\cmd.png"> <None Include="Images\cmd.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
<None Include="Images\folder.png"> <None Include="Images\folder.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
<Content Include="Languages\en.xaml"> <Content Include="Languages\en.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType> <SubType>Designer</SubType>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="Languages\zh-cn.xaml"> <None Include="Languages\zh-cn.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType> <SubType>Designer</SubType>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
<None Include="Languages\zh-tw.xaml"> <None Include="Languages\zh-tw.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType> <SubType>Designer</SubType>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
<Page Include="ProgramSetting.xaml"> <Page Include="ProgramSetting.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType> <SubType>Designer</SubType>
</Page> </Page>
<Page Include="ProgramSuffixes.xaml"> <Page Include="ProgramSuffixes.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType> <SubType>Designer</SubType>
</Page> </Page>
</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>
<ItemGroup> <ItemGroup>
<COMReference Include="IWshRuntimeLibrary"> <COMReference Include="IWshRuntimeLibrary">
<Guid>{F935DC20-1CF0-11D0-ADB9-00C04FD58A0B}</Guid> <Guid>{F935DC20-1CF0-11D0-ADB9-00C04FD58A0B}</Guid>
<VersionMajor>1</VersionMajor> <VersionMajor>1</VersionMajor>
<VersionMinor>0</VersionMinor> <VersionMinor>0</VersionMinor>
<Lcid>0</Lcid> <Lcid>0</Lcid>
<WrapperTool>tlbimp</WrapperTool> <WrapperTool>tlbimp</WrapperTool>
<Isolated>False</Isolated> <Isolated>False</Isolated>
<EmbedInteropTypes>True</EmbedInteropTypes> <EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference> </COMReference>
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" /> <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup> <PropertyGroup>
<ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。启用“NuGet 程序包还原”可下载这些程序包。有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText> <ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。启用“NuGet 程序包还原”可下载这些程序包。有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
</PropertyGroup> </PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" /> <Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target> </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>

View File

@@ -21,7 +21,7 @@ namespace Wox.Core.Plugin
{ {
public const string ActionKeywordWildcardSign = "*"; public const string ActionKeywordWildcardSign = "*";
private static List<PluginMetadata> pluginMetadatas; private static List<PluginMetadata> pluginMetadatas;
private static List<IInstantSearch> instantSearches = new List<IInstantSearch>(); private static List<KeyValuePair<PluginMetadata,IInstantSearch>> instantSearches;
public static String DebuggerMode { get; private set; } public static String DebuggerMode { get; private set; }
@@ -98,7 +98,10 @@ namespace Wox.Core.Plugin
}); });
} }
LoadInstantSearches(); ThreadPool.QueueUserWorkItem(o =>
{
LoadInstantSearches();
});
} }
public static void InstallPlugin(string path) public static void InstallPlugin(string path)
@@ -146,12 +149,38 @@ namespace Wox.Core.Plugin
public static bool IsInstantSearch(string query) public static bool IsInstantSearch(string query)
{ {
return LoadInstantSearches().Any(o => o.IsInstantSearch(query)); return LoadInstantSearches().Any(o => o.Value.IsInstantSearch(query));
} }
private static List<IInstantSearch> LoadInstantSearches() public static bool IsInstantSearchPlugin(PluginMetadata pluginMetadata)
{ {
if (instantSearches.Count > 0) return instantSearches; //todo:to improve performance, any instant search plugin that takes long than 200ms will not consider a instant plugin anymore
return pluginMetadata.Language.ToUpper() == AllowedLanguage.CSharp &&
LoadInstantSearches().Any(o => o.Key.ID == pluginMetadata.ID);
}
internal static void ExecutePluginQuery(PluginPair pair, Query query)
{
try
{
List<Result> results = pair.Plugin.Query(query) ?? new List<Result>();
results.ForEach(o =>
{
o.PluginID = pair.Metadata.ID;
});
API.PushResults(query, pair.Metadata, results);
}
catch (System.Exception e)
{
throw new WoxPluginException(pair.Metadata.Name, e);
}
}
private static List<KeyValuePair<PluginMetadata,IInstantSearch>> LoadInstantSearches()
{
if (instantSearches != null) return instantSearches;
instantSearches = new List<KeyValuePair<PluginMetadata, IInstantSearch>>();
List<PluginMetadata> CSharpPluginMetadatas = pluginMetadatas.Where(o => o.Language.ToUpper() == AllowedLanguage.CSharp.ToUpper()).ToList(); List<PluginMetadata> CSharpPluginMetadatas = pluginMetadatas.Where(o => o.Language.ToUpper() == AllowedLanguage.CSharp.ToUpper()).ToList();
foreach (PluginMetadata metadata in CSharpPluginMetadatas) foreach (PluginMetadata metadata in CSharpPluginMetadatas)
@@ -167,7 +196,7 @@ namespace Wox.Core.Plugin
foreach (Type type in types) foreach (Type type in types)
{ {
instantSearches.Add(Activator.CreateInstance(type) as IInstantSearch); instantSearches.Add(new KeyValuePair<PluginMetadata, IInstantSearch>(metadata,Activator.CreateInstance(type) as IInstantSearch));
} }
} }
catch (System.Exception e) catch (System.Exception e)

View File

@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using Wox.Infrastructure;
using Wox.Plugin;
namespace Wox.Core.Plugin.QueryDispatcher
{
public abstract class BaseQueryDispatcher : IQueryDispatcher
{
protected abstract List<PluginPair> GetPlugins(Query query);
public void Dispatch(Query query)
{
foreach (PluginPair pair in GetPlugins(query))
{
PluginPair localPair = pair;
if (query.IsIntantQuery && PluginManager.IsInstantSearchPlugin(pair.Metadata))
{
DebugHelper.WriteLine(string.Format("Plugin {0} is executing instant search.", pair.Metadata.Name));
using (new Timeit(" => instant search took: "))
{
PluginManager.ExecutePluginQuery(localPair, query);
}
}
else
{
ThreadPool.QueueUserWorkItem(state =>
{
PluginManager.ExecutePluginQuery(localPair, query);
});
}
}
}
}
}

View File

@@ -8,34 +8,14 @@ using Wox.Plugin;
namespace Wox.Core.Plugin.QueryDispatcher namespace Wox.Core.Plugin.QueryDispatcher
{ {
public class SystemPluginQueryDispatcher : IQueryDispatcher public class SystemPluginQueryDispatcher : BaseQueryDispatcher
{ {
private IEnumerable<PluginPair> allSytemPlugins = PluginManager.AllPlugins.Where(o => PluginManager.IsSystemPlugin(o.Metadata)); private readonly List<PluginPair> allSytemPlugins =
PluginManager.AllPlugins.Where(o => PluginManager.IsSystemPlugin(o.Metadata)).ToList();
public void Dispatch(Query query) protected override List<PluginPair> GetPlugins(Query query)
{ {
var queryPlugins = allSytemPlugins; return allSytemPlugins;
foreach (PluginPair pair in queryPlugins)
{
PluginPair pair1 = pair;
ThreadPool.QueueUserWorkItem(state =>
{
try
{
List<Result> results = pair1.Plugin.Query(query);
results.ForEach(o =>
{
o.PluginID = pair1.Metadata.ID;
});
PluginManager.API.PushResults(query, pair1.Metadata, results);
}
catch (System.Exception e)
{
throw new WoxPluginException(pair1.Metadata.Name,e);
}
});
}
} }
} }
} }

View File

@@ -9,38 +9,29 @@ using Wox.Plugin;
namespace Wox.Core.Plugin.QueryDispatcher namespace Wox.Core.Plugin.QueryDispatcher
{ {
public class UserPluginQueryDispatcher : IQueryDispatcher public class UserPluginQueryDispatcher : BaseQueryDispatcher
{ {
public void Dispatch(Query query) protected override List<PluginPair> GetPlugins(Query query)
{ {
List<PluginPair> plugins = new List<PluginPair>();
//only first plugin that matches action keyword will get executed
PluginPair userPlugin = PluginManager.AllPlugins.FirstOrDefault(o => o.Metadata.ActionKeyword == query.GetActionKeyword()); PluginPair userPlugin = PluginManager.AllPlugins.FirstOrDefault(o => o.Metadata.ActionKeyword == query.GetActionKeyword());
if (userPlugin != null && !string.IsNullOrEmpty(userPlugin.Metadata.ActionKeyword)) if (userPlugin != null)
{ {
var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == userPlugin.Metadata.ID); var customizedPluginConfig = UserSettingStorage.Instance.
CustomizedPluginConfigs.FirstOrDefault(o => o.ID == userPlugin.Metadata.ID);
if (customizedPluginConfig != null && customizedPluginConfig.Disabled) if (customizedPluginConfig != null && customizedPluginConfig.Disabled)
{ {
//need to stop the loading animation //need to stop the loading animation
PluginManager.API.StopLoadingBar(); PluginManager.API.StopLoadingBar();
return;
} }
else
ThreadPool.QueueUserWorkItem(t =>
{ {
try plugins.Add(userPlugin);
{ }
List<Result> results = userPlugin.Plugin.Query(query) ?? new List<Result>();
results.ForEach(o =>
{
o.PluginID = userPlugin.Metadata.ID;
});
PluginManager.API.PushResults(query, userPlugin.Metadata, results);
}
catch (System.Exception e)
{
throw new WoxPluginException(userPlugin.Metadata.Name, e);
}
});
} }
return plugins;
} }
} }
} }

View File

@@ -69,6 +69,7 @@
<Compile Include="Exception\WoxI18nException.cs" /> <Compile Include="Exception\WoxI18nException.cs" />
<Compile Include="Exception\WoxJsonRPCException.cs" /> <Compile Include="Exception\WoxJsonRPCException.cs" />
<Compile Include="Exception\WoxPluginException.cs" /> <Compile Include="Exception\WoxPluginException.cs" />
<Compile Include="Plugin\QueryDispatcher\BaseQueryDispatcher.cs" />
<Compile Include="Updater\Release.cs" /> <Compile Include="Updater\Release.cs" />
<Compile Include="Updater\UpdaterManager.cs" /> <Compile Include="Updater\UpdaterManager.cs" />
<Compile Include="Updater\WoxUpdateSource.cs" /> <Compile Include="Updater\WoxUpdateSource.cs" />

View File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
namespace Wox.Infrastructure
{
public static class DebugHelper
{
public static void WriteLine(string msg)
{
Debug.WriteLine(msg);
}
}
}

View File

@@ -855,7 +855,7 @@
</xs:annotation> </xs:annotation>
</xs:attribute> </xs:attribute>
</xs:complexType> </xs:complexType>
<xs:complexType name="Debugger"> <xs:complexType name="DebugHelper">
<xs:complexContent> <xs:complexContent>
<xs:extension base="Target"> <xs:extension base="Target">
<xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:choice minOccurs="0" maxOccurs="unbounded">

View File

@@ -20,7 +20,7 @@ namespace Wox.Infrastructure
public void Dispose() public void Dispose()
{ {
stopwatch.Stop(); stopwatch.Stop();
Debug.WriteLine(name + ":" + stopwatch.ElapsedMilliseconds + "ms","Wox"); DebugHelper.WriteLine(name + ":" + stopwatch.ElapsedMilliseconds + "ms");
} }
} }
} }

View File

@@ -58,6 +58,7 @@
<Reference Include="WindowsBase" /> <Reference Include="WindowsBase" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="DebugHelper.cs" />
<Compile Include="Hotkey\InterceptKeys.cs" /> <Compile Include="Hotkey\InterceptKeys.cs" />
<Compile Include="Hotkey\KeyEvent.cs" /> <Compile Include="Hotkey\KeyEvent.cs" />
<Compile Include="Logger\Log.cs" /> <Compile Include="Logger\Log.cs" />

View File

@@ -15,7 +15,13 @@ namespace Wox.Plugin
/// <param name="query"></param> /// <param name="query"></param>
/// <param name="plugin"></param> /// <param name="plugin"></param>
/// <param name="results"></param> /// <param name="results"></param>
void PushResults(Query query,PluginMetadata plugin, List<Result> results); void PushResults(Query query, PluginMetadata plugin, List<Result> results);
/// <summary>
/// Show context menu with giving results
/// </summary>
/// <param name="results"></param>
void ShowContextMenu(PluginMetadata plugin, List<Result> results);
/// <summary> /// <summary>
/// Execute command /// Execute command
@@ -63,7 +69,7 @@ namespace Wox.Plugin
/// Open setting dialog /// Open setting dialog
/// </summary> /// </summary>
void OpenSettingDialog(); void OpenSettingDialog();
/// <summary> /// <summary>
/// Show loading animation /// Show loading animation
/// </summary> /// </summary>

View File

@@ -33,6 +33,8 @@ namespace Wox.Plugin
return string.Empty; return string.Empty;
} }
internal bool IsIntantQuery { get; set; }
/// <summary> /// <summary>
/// Return first search split by space if it has /// Return first search split by space if it has
/// </summary> /// </summary>

View File

@@ -73,6 +73,11 @@ namespace Wox.Plugin
/// </summary> /// </summary>
public List<Result> ContextMenu { get; set; } public List<Result> ContextMenu { get; set; }
/// <summary>
/// Additional data associate with this result
/// </summary>
public object ContextData { get; set; }
/// <summary> /// <summary>
/// Plugin ID that generate this result /// Plugin ID that generate this result
/// </summary> /// </summary>

View File

@@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.IO; using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@@ -79,42 +80,49 @@ namespace Wox.ImageLoader
public static ImageSource Load(string path, bool addToCache = true) public static ImageSource Load(string path, bool addToCache = true)
{ {
Stopwatch sw = new Stopwatch();
sw.Start();
if (string.IsNullOrEmpty(path)) return null; if (string.IsNullOrEmpty(path)) return null;
if (addToCache) if (addToCache)
{ {
ImageCacheStroage.Instance.Add(path); ImageCacheStroage.Instance.Add(path);
} }
ImageSource img = null;
if (imageCache.ContainsKey(path)) if (imageCache.ContainsKey(path))
{ {
return imageCache[path]; img = imageCache[path];
} }
else
ImageSource img = null;
string ext = Path.GetExtension(path).ToLower();
if (path.StartsWith("data:", StringComparison.OrdinalIgnoreCase))
{ {
img = new BitmapImage(new Uri(path)); string ext = Path.GetExtension(path).ToLower();
}
else if (selfExts.Contains(ext) && File.Exists(path))
{
img = GetIcon(path);
}
else if (!string.IsNullOrEmpty(path) && imageExts.Contains(ext) && File.Exists(path))
{
img = new BitmapImage(new Uri(path));
}
if (path.StartsWith("data:", StringComparison.OrdinalIgnoreCase))
if (img != null && addToCache)
{
if (!imageCache.ContainsKey(path))
{ {
imageCache.Add(path, img); img = new BitmapImage(new Uri(path));
}
else if (selfExts.Contains(ext) && File.Exists(path))
{
img = GetIcon(path);
}
else if (!string.IsNullOrEmpty(path) && imageExts.Contains(ext) && File.Exists(path))
{
img = new BitmapImage(new Uri(path));
}
if (img != null && addToCache)
{
if (!imageCache.ContainsKey(path))
{
imageCache.Add(path, img);
}
} }
} }
sw.Stop();
DebugHelper.WriteLine(string.Format("Loading image path: {0} - {1}ms",path,sw.ElapsedMilliseconds));
return img; return img;
} }

View File

@@ -157,6 +157,23 @@ namespace Wox
UpdateResultView(results); 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 #endregion
public MainWindow() public MainWindow()
@@ -226,7 +243,7 @@ namespace Wox
void pnlResult_RightMouseClickEvent(Result result) void pnlResult_RightMouseClickEvent(Result result)
{ {
ShowContextMenu(result); ShowContextMenuFromResult(result);
} }
void MainWindow_Closing(object sender, CancelEventArgs e) void MainWindow_Closing(object sender, CancelEventArgs e)
@@ -261,7 +278,7 @@ namespace Wox
private void CheckUpdate() private void CheckUpdate()
{ {
UpdaterManager.Instance.PrepareUpdateReady+=OnPrepareUpdateReady; UpdaterManager.Instance.PrepareUpdateReady += OnPrepareUpdateReady;
UpdaterManager.Instance.UpdateError += OnUpdateError; UpdaterManager.Instance.UpdateError += OnUpdateError;
UpdaterManager.Instance.CheckUpdate(); UpdaterManager.Instance.CheckUpdate();
} }
@@ -368,6 +385,8 @@ namespace Wox
lastQuery = tbQuery.Text; lastQuery = tbQuery.Text;
toolTip.IsOpen = false; toolTip.IsOpen = false;
pnlResult.Dirty = true; pnlResult.Dirty = true;
int searchDelay = GetSearchDelay(lastQuery);
Dispatcher.DelayInvoke("UpdateSearch", Dispatcher.DelayInvoke("UpdateSearch",
o => o =>
{ {
@@ -381,6 +400,7 @@ namespace Wox
}, TimeSpan.FromMilliseconds(100), null); }, TimeSpan.FromMilliseconds(100), null);
queryHasReturn = false; queryHasReturn = false;
Query query = new Query(lastQuery); Query query = new Query(lastQuery);
query.IsIntantQuery = searchDelay == 0;
FireBeforeWoxQueryEvent(query); FireBeforeWoxQueryEvent(query);
Query(query); Query(query);
Dispatcher.DelayInvoke("ShowProgressbar", originQuery => Dispatcher.DelayInvoke("ShowProgressbar", originQuery =>
@@ -391,15 +411,18 @@ namespace Wox
} }
}, TimeSpan.FromMilliseconds(150), tbQuery.Text); }, TimeSpan.FromMilliseconds(150), tbQuery.Text);
FireAfterWoxQueryEvent(query); FireAfterWoxQueryEvent(query);
}, TimeSpan.FromMilliseconds(GetSearchDelay(lastQuery))); }, TimeSpan.FromMilliseconds(searchDelay));
} }
private int GetSearchDelay(string query) private int GetSearchDelay(string query)
{ {
if (!string.IsNullOrEmpty(query) && PluginManager.IsInstantSearch(query)) if (!string.IsNullOrEmpty(query) && PluginManager.IsInstantSearch(query))
{ {
DebugHelper.WriteLine("execute query without delay");
return 0; return 0;
} }
DebugHelper.WriteLine("execute query with 200ms delay");
return 200; return 200;
} }
@@ -551,7 +574,7 @@ namespace Wox
} }
else else
{ {
ShowContextMenu(GetActiveResult()); ShowContextMenuFromResult(GetActiveResult());
} }
} }
break; break;
@@ -609,7 +632,7 @@ namespace Wox
Result activeResult = GetActiveResult(); Result activeResult = GetActiveResult();
if (GlobalHotkey.Instance.CheckModifiers().ShiftPressed) if (GlobalHotkey.Instance.CheckModifiers().ShiftPressed)
{ {
ShowContextMenu(activeResult); ShowContextMenuFromResult(activeResult);
} }
else else
{ {
@@ -740,7 +763,7 @@ namespace Wox
} }
} }
private void ShowContextMenu(Result result) private void ShowContextMenuFromResult(Result result)
{ {
if (result.ContextMenu != null && result.ContextMenu.Count > 0) if (result.ContextMenu != null && result.ContextMenu.Count > 0)
{ {