mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 19:26:39 +02:00
Add query history plugin & upgrade all third-party packages
This commit is contained in:
53
Plugins/Wox.Plugin.QueryHistory/HistoryItem.cs
Normal file
53
Plugins/Wox.Plugin.QueryHistory/HistoryItem.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Wox.Plugin.QueryHistory
|
||||
{
|
||||
public class HistoryItem
|
||||
{
|
||||
public string Query { get; set; }
|
||||
public DateTime ExecutedDateTime { get; set; }
|
||||
|
||||
public string GetTimeAgo()
|
||||
{
|
||||
return DateTimeAgo(ExecutedDateTime);
|
||||
}
|
||||
|
||||
private string DateTimeAgo(DateTime dt)
|
||||
{
|
||||
TimeSpan span = DateTime.Now - dt;
|
||||
if (span.Days > 365)
|
||||
{
|
||||
int years = (span.Days / 365);
|
||||
if (span.Days % 365 != 0)
|
||||
years += 1;
|
||||
return String.Format("about {0} {1} ago",
|
||||
years, years == 1 ? "year" : "years");
|
||||
}
|
||||
if (span.Days > 30)
|
||||
{
|
||||
int months = (span.Days / 30);
|
||||
if (span.Days % 31 != 0)
|
||||
months += 1;
|
||||
return String.Format("about {0} {1} ago",
|
||||
months, months == 1 ? "month" : "months");
|
||||
}
|
||||
if (span.Days > 0)
|
||||
return String.Format("about {0} {1} ago",
|
||||
span.Days, span.Days == 1 ? "day" : "days");
|
||||
if (span.Hours > 0)
|
||||
return String.Format("about {0} {1} ago",
|
||||
span.Hours, span.Hours == 1 ? "hour" : "hours");
|
||||
if (span.Minutes > 0)
|
||||
return String.Format("about {0} {1} ago",
|
||||
span.Minutes, span.Minutes == 1 ? "minute" : "minutes");
|
||||
if (span.Seconds > 5)
|
||||
return String.Format("about {0} seconds ago", span.Seconds);
|
||||
if (span.Seconds <= 5)
|
||||
return "just now";
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
Plugins/Wox.Plugin.QueryHistory/Images/history.png
Normal file
BIN
Plugins/Wox.Plugin.QueryHistory/Images/history.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.1 KiB |
36
Plugins/Wox.Plugin.QueryHistory/Properties/AssemblyInfo.cs
Normal file
36
Plugins/Wox.Plugin.QueryHistory/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// 有关程序集的常规信息通过以下
|
||||
// 特性集控制。更改这些特性值可修改
|
||||
// 与程序集关联的信息。
|
||||
[assembly: AssemblyTitle("Wox.Plugin.QueryHistory")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Wox.Plugin.QueryHistory")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2015")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// 将 ComVisible 设置为 false 使此程序集中的类型
|
||||
// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
|
||||
// 则将该类型上的 ComVisible 特性设置为 true。
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
|
||||
[assembly: Guid("25ab1bbc-f625-4bf5-a2d0-73313abdaae5")]
|
||||
|
||||
// 程序集的版本信息由下面四个值组成:
|
||||
//
|
||||
// 主版本
|
||||
// 次版本
|
||||
// 生成号
|
||||
// 修订号
|
||||
//
|
||||
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
|
||||
// 方法是按如下所示使用“*”:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
51
Plugins/Wox.Plugin.QueryHistory/QueryHistory.cs
Normal file
51
Plugins/Wox.Plugin.QueryHistory/QueryHistory.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace Wox.Plugin.QueryHistory
|
||||
{
|
||||
public class QueryHistory : IPlugin
|
||||
{
|
||||
private PluginInitContext context;
|
||||
|
||||
public List<Result> Query(Query query)
|
||||
{
|
||||
var histories = QueryHistoryStorage.Instance.GetHistory();
|
||||
string filter = query.GetAllRemainingParameter();
|
||||
if (!string.IsNullOrEmpty(filter))
|
||||
{
|
||||
histories = histories.Where(o => o.Query.Contains(filter)).ToList();
|
||||
}
|
||||
return histories.Select(history => new Result()
|
||||
{
|
||||
Title = history.Query,
|
||||
SubTitle = history.GetTimeAgo(),
|
||||
IcoPath = "Images\\history.png",
|
||||
Action = _ =>
|
||||
{
|
||||
context.API.ChangeQuery(history.Query);
|
||||
return false;
|
||||
}
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
public void Init(PluginInitContext context)
|
||||
{
|
||||
this.context = context;
|
||||
context.API.AfterWoxQueryEvent += API_AfterWoxQueryEvent;
|
||||
context.API.BeforeWoxQueryEvent += API_BeforeWoxQueryEvent;
|
||||
}
|
||||
|
||||
void API_BeforeWoxQueryEvent(WoxQueryEventArgs e)
|
||||
{
|
||||
Thread.Sleep(5000);
|
||||
}
|
||||
|
||||
private void API_AfterWoxQueryEvent(WoxQueryEventArgs e)
|
||||
{
|
||||
QueryHistoryStorage.Instance.Add(e.Query.RawQuery);
|
||||
}
|
||||
}
|
||||
}
|
||||
83
Plugins/Wox.Plugin.QueryHistory/QueryHistoryStorage.cs
Normal file
83
Plugins/Wox.Plugin.QueryHistory/QueryHistoryStorage.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Newtonsoft.Json;
|
||||
using Wox.Core.Exception;
|
||||
using Wox.Infrastructure.Storage;
|
||||
|
||||
namespace Wox.Plugin.QueryHistory
|
||||
{
|
||||
public class QueryHistoryStorage : JsonStrorage<QueryHistoryStorage>
|
||||
{
|
||||
[JsonProperty]
|
||||
private List<HistoryItem> History = new List<HistoryItem>();
|
||||
|
||||
private int MaxHistory = 300;
|
||||
private int cursor = 0;
|
||||
|
||||
protected override string ConfigFolder
|
||||
{
|
||||
get { return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); }
|
||||
}
|
||||
|
||||
protected override string ConfigName
|
||||
{
|
||||
get { return "QueryHistory"; }
|
||||
}
|
||||
|
||||
public HistoryItem Pop()
|
||||
{
|
||||
if (History.Count == 0) return null;
|
||||
|
||||
if (cursor > History.Count - 1)
|
||||
{
|
||||
cursor = History.Count - 1;
|
||||
}
|
||||
if (cursor < 0)
|
||||
{
|
||||
cursor = 0;
|
||||
}
|
||||
|
||||
return History[cursor--];
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
cursor = History.Count - 1;
|
||||
}
|
||||
|
||||
public void Add(string query)
|
||||
{
|
||||
if (string.IsNullOrEmpty(query)) return;
|
||||
if (History.Count > MaxHistory)
|
||||
{
|
||||
History.RemoveAt(0);
|
||||
}
|
||||
|
||||
if (History.Count > 0 && History.Last().Query == query)
|
||||
{
|
||||
History.Last().ExecutedDateTime = DateTime.Now;
|
||||
}
|
||||
else
|
||||
{
|
||||
History.Add(new HistoryItem()
|
||||
{
|
||||
Query = query,
|
||||
ExecutedDateTime = DateTime.Now
|
||||
});
|
||||
}
|
||||
|
||||
if (History.Count % 5 == 0)
|
||||
{
|
||||
Save();
|
||||
}
|
||||
}
|
||||
|
||||
public List<HistoryItem> GetHistory()
|
||||
{
|
||||
return History.OrderByDescending(o => o.ExecutedDateTime).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<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')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{B552DCB6-692E-4B1D-9E0B-9096A2A7E6B0}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Wox.Plugin.QueryHistory</RootNamespace>
|
||||
<AssemblyName>Wox.Plugin.QueryHistory</AssemblyName>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
|
||||
<RestorePackages>true</RestorePackages>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>..\..\Output\Debug\Plugins\Wox.Plugin.QueryHistory\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>..\..\Output\Release\Plugins\Wox.Plugin.Program\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\packages\Newtonsoft.Json.6.0.8\lib\net35\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="HistoryItem.cs" />
|
||||
<Compile Include="QueryHistory.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="QueryHistoryStorage.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Wox.Core\Wox.Core.csproj">
|
||||
<Project>{B749F0DB-8E75-47DB-9E5E-265D16D0C0D2}</Project>
|
||||
<Name>Wox.Core</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\Wox.Infrastructure\Wox.Infrastructure.csproj">
|
||||
<Project>{4fd29318-a8ab-4d8f-aa47-60bc241b8da3}</Project>
|
||||
<Name>Wox.Infrastructure</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\Wox.Plugin\Wox.Plugin.csproj">
|
||||
<Project>{8451ecdd-2ea4-4966-bb0a-7bbc40138e80}</Project>
|
||||
<Name>Wox.Plugin</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
<None Include="plugin.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Images\history.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<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.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
4
Plugins/Wox.Plugin.QueryHistory/packages.config
Normal file
4
Plugins/Wox.Plugin.QueryHistory/packages.config
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net35" />
|
||||
</packages>
|
||||
12
Plugins/Wox.Plugin.QueryHistory/plugin.json
Normal file
12
Plugins/Wox.Plugin.QueryHistory/plugin.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"ID":"54F327C503414B9489CDD331EE9472EF",
|
||||
"ActionKeyword":"history",
|
||||
"Name":"Query History",
|
||||
"Description":"Remember Wox query history",
|
||||
"Author":"qianlifeng",
|
||||
"Version":"1.0.0",
|
||||
"Language":"csharp",
|
||||
"Website":"http://www.getwox.com/plugin",
|
||||
"ExecuteFileName":"Wox.Plugin.QueryHistory.dll",
|
||||
"IcoPath":"Images\\history.png"
|
||||
}
|
||||
Reference in New Issue
Block a user