mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 18:26:39 +02:00
[PTRun]Add history plugin (#19569)
* Progress! * Progress... * POC level. * Added ability to delete from history using IPublicAPI * Some sorting, works in some cases. * Rename "Run History" back to just "History". * Updated item from review. * Slight change to PowerLauncher ref, set Copy Local = False * Fixed missing history items if added to history without search term. * Added placeholder unit test project * Updates for new History plugin. * Update Product.wxs, removed useless Unit Test project * Removed actual files for "Microsoft.PowerToys.Run.Plugin.History.UnitTests" * Added history.md, updated ESRPSigning_core.json * Changes for review * Removed now global CodeAnalysis/stylecop
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Wox.Plugin;
|
||||
using Wox.Plugin.Logger;
|
||||
|
||||
namespace Microsoft.PowerToys.Run.Plugin.History
|
||||
{
|
||||
internal static class ErrorHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Method to handles errors
|
||||
/// </summary>
|
||||
/// <param name="icon">Path to result icon.</param>
|
||||
/// <param name="isGlobalQuery">Bool to indicate if it is a global query.</param>
|
||||
/// <param name="queryInput">User input as string including the action keyword.</param>
|
||||
/// <param name="errorMessage">Error message if applicable.</param>
|
||||
/// <param name="exception">Exception if applicable.</param>
|
||||
/// <returns>List of results to show. Either an error message or an empty list.</returns>
|
||||
/// <exception cref="ArgumentException">Thrown if <paramref name="errorMessage"/> and <paramref name="exception"/> are both filled with their default values.</exception>
|
||||
internal static List<Result> OnError(string icon, bool isGlobalQuery, string queryInput, string errorMessage, Exception exception = default)
|
||||
{
|
||||
string userMessage;
|
||||
|
||||
if (errorMessage != default)
|
||||
{
|
||||
Log.Error($"Failed to handle history item <{queryInput}>: {errorMessage}", typeof(History.Main));
|
||||
userMessage = errorMessage;
|
||||
}
|
||||
else if (exception != default)
|
||||
{
|
||||
Log.Exception($"Exception when query for <{queryInput}>", exception, exception.GetType());
|
||||
userMessage = exception.Message;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException("The arguments error and exception have default values. One of them has to be filled with valid error data (error message/exception)!");
|
||||
}
|
||||
|
||||
return isGlobalQuery ? new List<Result>() : new List<Result> { CreateErrorResult(userMessage, icon) };
|
||||
}
|
||||
|
||||
private static Result CreateErrorResult(string errorMessage, string iconPath)
|
||||
{
|
||||
return new Result
|
||||
{
|
||||
Title = Properties.Resources.wox_plugin_history_processing_failed,
|
||||
SubTitle = errorMessage,
|
||||
IcoPath = iconPath,
|
||||
Score = 300,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.1 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.0 KiB |
@@ -0,0 +1,251 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ManagedCommon;
|
||||
using Microsoft.PowerToys.Run.Plugin.History.Properties;
|
||||
using PowerLauncher.Plugin;
|
||||
using Wox.Plugin;
|
||||
|
||||
namespace Microsoft.PowerToys.Run.Plugin.History
|
||||
{
|
||||
public class Main : IPlugin, IContextMenu, IPluginI18n, IDisposable
|
||||
{
|
||||
private PluginInitContext Context { get; set; }
|
||||
|
||||
private string IconPath { get; set; }
|
||||
|
||||
public string Name => Resources.wox_plugin_history_plugin_name;
|
||||
|
||||
public string Description => Resources.wox_plugin_history_plugin_description;
|
||||
|
||||
private bool _disposed;
|
||||
|
||||
public List<Result> Query(Query query)
|
||||
{
|
||||
var results = new List<Result>();
|
||||
try
|
||||
{
|
||||
if (query.SelectedItems != null)
|
||||
{
|
||||
var scoreCounter = 1000;
|
||||
|
||||
// System.Diagnostics.Debugger.Launch();
|
||||
foreach (var historyItem in query.SelectedItems.Values.OrderByDescending(sel => sel.LastSelected))
|
||||
{
|
||||
if (historyItem.PluginID == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var plugin = PluginManager.AllPlugins.FirstOrDefault(p => p.Metadata.ID == historyItem.PluginID);
|
||||
|
||||
if (query.Search != string.Empty && !IsRelevant(query, historyItem))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var result = BuildResult(historyItem);
|
||||
|
||||
if (result != null)
|
||||
{
|
||||
// very special case for Calculator
|
||||
if (plugin.Metadata.Name == "Calculator")
|
||||
{
|
||||
result.HistoryTitle = result.Title;
|
||||
result.Title = $"{historyItem.Search} = {historyItem.Title}";
|
||||
}
|
||||
|
||||
if (query.RawQuery.StartsWith(query.ActionKeyword, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
// this is just the history view, update the scores.
|
||||
result.Score = scoreCounter--;
|
||||
}
|
||||
|
||||
results.Add(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine("Skipping " + historyItem.Title);
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// System.Diagnostics.Debugger.Launch();
|
||||
bool isGlobalQuery = string.IsNullOrEmpty(query.ActionKeyword);
|
||||
return ErrorHandler.OnError(IconPath, isGlobalQuery, query.RawQuery, default, e);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
private bool IsRelevant(Query query, UserSelectedRecord.UserSelectedRecordItem genericSelectedItem)
|
||||
{
|
||||
if (genericSelectedItem.Title != null && genericSelectedItem.Title.Contains(query.Search, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (genericSelectedItem.SubTitle != null && genericSelectedItem.SubTitle.Contains(query.Search, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (genericSelectedItem.Search != null && genericSelectedItem.Search.Contains(query.Search, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private Result BuildResult(UserSelectedRecord.UserSelectedRecordItem historyItem)
|
||||
{
|
||||
Result result = null;
|
||||
|
||||
var plugin = PluginManager.AllPlugins.FirstOrDefault(x => x.Metadata.ID == historyItem.PluginID);
|
||||
|
||||
var searchTerm = historyItem.Search;
|
||||
if (string.IsNullOrEmpty(searchTerm))
|
||||
{
|
||||
searchTerm = historyItem.Title;
|
||||
}
|
||||
|
||||
var tempResults = PluginManager.QueryForPlugin(plugin, new Query(searchTerm), false);
|
||||
|
||||
if (tempResults != null)
|
||||
{
|
||||
result = tempResults.FirstOrDefault(r => r.Title == historyItem.Title && r.SubTitle == historyItem.SubTitle);
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
// do less exact match, some plugins (like shell), have a dynamic SubTitle
|
||||
result = tempResults.FirstOrDefault(r => r.Title == historyItem.Title);
|
||||
}
|
||||
}
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
tempResults = PluginManager.QueryForPlugin(plugin, new Query(searchTerm), true);
|
||||
if (tempResults != null)
|
||||
{
|
||||
result = tempResults.FirstOrDefault(r => r.Title == historyItem.Title && r.SubTitle == historyItem.SubTitle);
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
// do less exact match, some plugins (like shell), have a dynamic SubTitle
|
||||
result = tempResults.FirstOrDefault(r => r.Title == historyItem.Title);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (result != null)
|
||||
{
|
||||
result.FromHistory = true;
|
||||
result.HistoryPluginID = historyItem.PluginID;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void Init(PluginInitContext context)
|
||||
{
|
||||
Context = context ?? throw new ArgumentNullException(paramName: nameof(context));
|
||||
|
||||
Context.API.ThemeChanged += OnThemeChanged;
|
||||
UpdateIconPath(Context.API.GetCurrentTheme());
|
||||
}
|
||||
|
||||
private void UpdateIconPath(Theme theme)
|
||||
{
|
||||
if (theme == Theme.Light || theme == Theme.HighContrastWhite)
|
||||
{
|
||||
IconPath = "Images/history.light.png";
|
||||
}
|
||||
else
|
||||
{
|
||||
IconPath = "Images/history.dark.png";
|
||||
}
|
||||
}
|
||||
|
||||
private void OnThemeChanged(Theme currentTheme, Theme newTheme)
|
||||
{
|
||||
UpdateIconPath(newTheme);
|
||||
}
|
||||
|
||||
public string GetTranslatedPluginTitle()
|
||||
{
|
||||
return Resources.wox_plugin_history_plugin_name;
|
||||
}
|
||||
|
||||
public string GetTranslatedPluginDescription()
|
||||
{
|
||||
return Resources.wox_plugin_history_plugin_description;
|
||||
}
|
||||
|
||||
public List<ContextMenuResult> LoadContextMenus(Result selectedResult)
|
||||
{
|
||||
var pluginPair = PluginManager.AllPlugins.FirstOrDefault(x => x.Metadata.ID == selectedResult.HistoryPluginID);
|
||||
if (pluginPair != null)
|
||||
{
|
||||
List<ContextMenuResult> menuItems = new List<ContextMenuResult>();
|
||||
if (pluginPair.Plugin.GetType().GetInterface(nameof(IContextMenu)) != null)
|
||||
{
|
||||
var plugin = (IContextMenu)pluginPair.Plugin;
|
||||
menuItems = plugin.LoadContextMenus(selectedResult);
|
||||
}
|
||||
|
||||
menuItems.Add(new ContextMenuResult
|
||||
{
|
||||
// https://docs.microsoft.com/en-us/windows/apps/design/style/segoe-ui-symbol-font
|
||||
FontFamily = "Segoe MDL2 Assets",
|
||||
Glyph = "\xF739", // ECC9 => Symbol: RemoveFrom, or F739 => SetHistoryStatus2
|
||||
Title = $"Remove this from history",
|
||||
Action = _ =>
|
||||
{
|
||||
// very special case for Calculator
|
||||
if (pluginPair.Plugin.Name == "Calculator")
|
||||
{
|
||||
selectedResult.Title = selectedResult.HistoryTitle;
|
||||
}
|
||||
|
||||
PluginManager.API.RemoveUserSelectedItem(selectedResult);
|
||||
|
||||
return true;
|
||||
},
|
||||
});
|
||||
|
||||
return menuItems;
|
||||
}
|
||||
|
||||
return new List<ContextMenuResult>();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!_disposed)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
if (Context != null && Context.API != null)
|
||||
{
|
||||
Context.API.ThemeChanged -= OnThemeChanged;
|
||||
}
|
||||
|
||||
_disposed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Import Project="..\..\..\..\Version.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0-windows10.0.19041.0</TargetFramework>
|
||||
<ProjectGuid>{212AD910-8488-4036-BE20-326931B75FB2}</ProjectGuid>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Microsoft.PowerToys.Run.Plugin.History</RootNamespace>
|
||||
<AssemblyName>Microsoft.PowerToys.Run.Plugin.History</AssemblyName>
|
||||
<Version>$(Version).0</Version>
|
||||
<useWPF>true</useWPF>
|
||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
|
||||
<GenerateSatelliteAssembliesForCore>true</GenerateSatelliteAssembliesForCore>
|
||||
<OutputPath>$(SolutionDir)\$(Platform)\$(Configuration)\modules\launcher\Plugins\History\</OutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Release'">
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="plugin.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\PowerLauncher\PowerLauncher.csproj">
|
||||
<Private>False</Private>
|
||||
<CopyLocalSatelliteAssemblies>False</CopyLocalSatelliteAssemblies>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\Wox.Infrastructure\Wox.Infrastructure.csproj">
|
||||
<Private>false</Private>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\Wox.Plugin\Wox.Plugin.csproj">
|
||||
<Private>false</Private>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="JetBrains.Annotations" Version="2021.3.0" />
|
||||
<PackageReference Include="Mages" Version="2.0.1" />
|
||||
<PackageReference Include="System.Runtime" Version="4.3.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="Images\history.dark.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Images\history.light.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Properties\Resources.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Update="Properties\Resources.resx">
|
||||
<Generator>PublicResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
90
src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.History/Properties/Resources.Designer.cs
generated
Normal file
90
src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.History/Properties/Resources.Designer.cs
generated
Normal file
@@ -0,0 +1,90 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.42000
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Microsoft.PowerToys.Run.Plugin.History.Properties {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A strongly-typed resource class, for looking up localized strings, etc.
|
||||
/// </summary>
|
||||
// This class was auto-generated by the StronglyTypedResourceBuilder
|
||||
// class via a tool like ResGen or Visual Studio.
|
||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||
// with the /str option, or rebuild your VS project.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
public class Resources {
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Resources() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the cached ResourceManager instance used by this class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
public static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.PowerToys.Run.Plugin.History.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overrides the current thread's CurrentUICulture property for all
|
||||
/// resource lookups using this strongly typed resource class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
public static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Quick access to previously selected results..
|
||||
/// </summary>
|
||||
public static string wox_plugin_history_plugin_description {
|
||||
get {
|
||||
return ResourceManager.GetString("wox_plugin_history_plugin_description", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to History.
|
||||
/// </summary>
|
||||
public static string wox_plugin_history_plugin_name {
|
||||
get {
|
||||
return ResourceManager.GetString("wox_plugin_history_plugin_name", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Failed to process the input.
|
||||
/// </summary>
|
||||
public static string wox_plugin_history_processing_failed {
|
||||
get {
|
||||
return ResourceManager.GetString("wox_plugin_history_processing_failed", resourceCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="wox_plugin_history_plugin_name" xml:space="preserve">
|
||||
<value>History</value>
|
||||
</data>
|
||||
<data name="wox_plugin_history_plugin_description" xml:space="preserve">
|
||||
<value>Quick access to previously selected results.</value>
|
||||
</data>
|
||||
<data name="wox_plugin_history_processing_failed" xml:space="preserve">
|
||||
<value>Failed to process the input</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"ID": "C88512156BB74580AADF7252E130BA8D",
|
||||
"ActionKeyword": "!!",
|
||||
"IsGlobal": false,
|
||||
"Name": "History",
|
||||
"Author": "jefflord",
|
||||
"Version": "1.0.0",
|
||||
"Language": "csharp",
|
||||
"Website": "https://aka.ms/powertoys",
|
||||
"ExecuteFileName": "Microsoft.PowerToys.Run.Plugin.History.dll",
|
||||
"IcoPathDark": "Images\\history.dark.png",
|
||||
"IcoPathLight": "Images\\history.light.png"
|
||||
}
|
||||
@@ -38,6 +38,12 @@ namespace Wox
|
||||
};
|
||||
}
|
||||
|
||||
public void RemoveUserSelectedItem(Result result)
|
||||
{
|
||||
_mainVM.RemoveUserSelectedRecord(result);
|
||||
_mainVM.ChangeQueryText(_mainVM.QueryText, true);
|
||||
}
|
||||
|
||||
public void ChangeQuery(string query, bool requery = false)
|
||||
{
|
||||
_mainVM.ChangeQueryText(query, requery);
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json.Serialization;
|
||||
using Wox.Plugin;
|
||||
|
||||
namespace PowerLauncher.Storage
|
||||
{
|
||||
public class UserSelectedRecord
|
||||
{
|
||||
public class UserSelectedRecordItem
|
||||
{
|
||||
public int SelectedCount { get; set; }
|
||||
|
||||
public DateTime LastSelected { get; set; }
|
||||
}
|
||||
|
||||
[JsonInclude]
|
||||
public Dictionary<string, UserSelectedRecordItem> Records { get; private set; } = new Dictionary<string, UserSelectedRecordItem>();
|
||||
|
||||
public void Add(Result result)
|
||||
{
|
||||
if (result == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(result));
|
||||
}
|
||||
|
||||
var key = result.ToString();
|
||||
if (Records.TryGetValue(key, out var value))
|
||||
{
|
||||
Records[key].SelectedCount = Records[key].SelectedCount + 1;
|
||||
Records[key].LastSelected = DateTime.UtcNow;
|
||||
}
|
||||
else
|
||||
{
|
||||
Records.Add(key, new UserSelectedRecordItem { SelectedCount = 1, LastSelected = DateTime.UtcNow });
|
||||
}
|
||||
}
|
||||
|
||||
public UserSelectedRecordItem GetSelectedData(Result result)
|
||||
{
|
||||
if (result == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(result));
|
||||
}
|
||||
|
||||
if (result != null && Records.TryGetValue(result.ToString(), out var value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
return new UserSelectedRecordItem { SelectedCount = 0, LastSelected = DateTime.MinValue };
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -82,6 +82,11 @@ namespace PowerLauncher.ViewModel
|
||||
RegisterResultsUpdatedEvent();
|
||||
}
|
||||
|
||||
public void RemoveUserSelectedRecord(Result result)
|
||||
{
|
||||
_userSelectedRecord.Remove(result);
|
||||
}
|
||||
|
||||
public void RegisterHotkey(IntPtr hwnd)
|
||||
{
|
||||
Log.Info("RegisterHotkey()", GetType());
|
||||
@@ -566,6 +571,7 @@ namespace PowerLauncher.ViewModel
|
||||
{
|
||||
var plugin = pluginQueryItem.Key;
|
||||
var query = pluginQueryItem.Value;
|
||||
query.SelectedItems = _userSelectedRecord.GetGenericHistory();
|
||||
var results = PluginManager.QueryForPlugin(plugin, query);
|
||||
resultPluginPair[plugin.Metadata] = results;
|
||||
currentCancellationToken.ThrowIfCancellationRequested();
|
||||
@@ -586,6 +592,7 @@ namespace PowerLauncher.ViewModel
|
||||
{
|
||||
var plugin = pluginQueryItem.Key;
|
||||
var query = pluginQueryItem.Value;
|
||||
query.SelectedItems = _userSelectedRecord.GetGenericHistory();
|
||||
var results = PluginManager.QueryForPlugin(plugin, query);
|
||||
resultPluginPair[plugin.Metadata] = results;
|
||||
currentCancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
@@ -151,11 +151,10 @@ namespace PowerLauncher.ViewModel
|
||||
{
|
||||
bool hideWindow =
|
||||
r.Action != null &&
|
||||
r.Action(
|
||||
new ActionContext
|
||||
{
|
||||
SpecialKeyState = KeyboardHelper.CheckModifiers(),
|
||||
});
|
||||
r.Action(new ActionContext
|
||||
{
|
||||
SpecialKeyState = KeyboardHelper.CheckModifiers(),
|
||||
});
|
||||
|
||||
if (hideWindow)
|
||||
{
|
||||
|
||||
@@ -266,6 +266,16 @@ namespace PowerLauncher.ViewModel
|
||||
sorted = Results.OrderByDescending(x => (x.Result.Metadata.WeightBoost + x.Result.Score + (x.Result.SelectedCount * 5))).ToList();
|
||||
}
|
||||
|
||||
// remove history items in they are in the list as non-history items
|
||||
foreach (var nonHistoryResult in sorted.Where(x => x.Result.Metadata.Name != "History").ToList())
|
||||
{
|
||||
var historyToRemove = sorted.FirstOrDefault(x => x.Result.Metadata.Name == "History" && x.Result.Title == nonHistoryResult.Result.Title && x.Result.SubTitle == nonHistoryResult.Result.SubTitle);
|
||||
if (historyToRemove != null)
|
||||
{
|
||||
sorted.Remove(historyToRemove);
|
||||
}
|
||||
}
|
||||
|
||||
Clear();
|
||||
Results.AddRange(sorted);
|
||||
}
|
||||
|
||||
@@ -28,6 +28,11 @@ namespace Wox.Plugin
|
||||
/// </summary>
|
||||
void RestartApp();
|
||||
|
||||
/// <summary>
|
||||
/// Remove user selected history item and refresh/requery
|
||||
/// </summary>
|
||||
void RemoveUserSelectedItem(Result result);
|
||||
|
||||
/// <summary>
|
||||
/// Get current theme
|
||||
/// </summary>
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Mono.Collections.Generic;
|
||||
|
||||
@@ -149,6 +150,8 @@ namespace Wox.Plugin
|
||||
|
||||
public override string ToString() => RawQuery;
|
||||
|
||||
public Dictionary<string, UserSelectedRecord.UserSelectedRecordItem> SelectedItems { get; set; }
|
||||
|
||||
[Obsolete("Use Search instead, this method will be removed in v1.3.0")]
|
||||
public string GetAllRemainingParameter() => Search;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO.Abstractions;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
|
||||
@@ -42,6 +43,12 @@ namespace Wox.Plugin
|
||||
}
|
||||
}
|
||||
|
||||
public bool FromHistory { get; set; }
|
||||
|
||||
public string HistoryPluginID { get; set; }
|
||||
|
||||
public string HistoryTitle { get; set; }
|
||||
|
||||
public string SubTitle { get; set; }
|
||||
|
||||
public string Glyph { get; set; }
|
||||
@@ -98,6 +105,7 @@ namespace Wox.Plugin
|
||||
/// <summary>
|
||||
/// Gets or sets return true to hide wox after select result
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public Func<ActionContext, bool> Action { get; set; }
|
||||
|
||||
public int Score { get; set; }
|
||||
|
||||
134
src/modules/launcher/Wox.Plugin/UserSelectedRecord.cs
Normal file
134
src/modules/launcher/Wox.Plugin/UserSelectedRecord.cs
Normal file
@@ -0,0 +1,134 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Wox.Plugin
|
||||
{
|
||||
public class UserSelectedRecord
|
||||
{
|
||||
public class UserSelectedRecordItem
|
||||
{
|
||||
public int SelectedCount { get; set; }
|
||||
|
||||
public DateTime LastSelected { get; set; }
|
||||
|
||||
public string IconPath { get; set; }
|
||||
|
||||
public string Title { get; set; }
|
||||
|
||||
public string Search { get; set; }
|
||||
|
||||
public int Score { get; set; }
|
||||
|
||||
public string SubTitle { get; set; }
|
||||
|
||||
public string PluginID { get; set; }
|
||||
}
|
||||
|
||||
[JsonInclude]
|
||||
public Dictionary<string, UserSelectedRecordItem> Records { get; private set; } = new Dictionary<string, UserSelectedRecordItem>();
|
||||
|
||||
public void Remove(Result result)
|
||||
{
|
||||
if (result == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(result));
|
||||
}
|
||||
|
||||
var key = result.ToString();
|
||||
if (Records.ContainsKey(result.ToString()))
|
||||
{
|
||||
Records.Remove(result.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public void Add(Result result)
|
||||
{
|
||||
if (result == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(result));
|
||||
}
|
||||
|
||||
var key = result.ToString();
|
||||
if (Records.TryGetValue(key, out var value))
|
||||
{
|
||||
Records[key].SelectedCount = Records[key].SelectedCount + 1;
|
||||
Records[key].LastSelected = DateTime.UtcNow;
|
||||
Records[key].IconPath = result.IcoPath;
|
||||
Records[key].Title = result.Title;
|
||||
Records[key].SubTitle = result.SubTitle;
|
||||
Records[key].Search = (result.OriginQuery.Search.Length > 0) ? result.OriginQuery.Search : Records[key].Search;
|
||||
|
||||
if (Records[key].PluginID == null)
|
||||
{
|
||||
Records[key].PluginID = result.PluginID;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Records.Add(key, new UserSelectedRecordItem
|
||||
{
|
||||
SelectedCount = 1,
|
||||
LastSelected = DateTime.UtcNow,
|
||||
Title = result.Title,
|
||||
SubTitle = result.SubTitle,
|
||||
IconPath = result.IcoPath,
|
||||
PluginID = result.PluginID,
|
||||
Search = result.OriginQuery.Search,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public UserSelectedRecordItem GetSelectedData(Result result)
|
||||
{
|
||||
if (result == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(result));
|
||||
}
|
||||
|
||||
if (result != null && Records.TryGetValue(result.ToString(), out var value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
return new UserSelectedRecordItem { SelectedCount = 0, LastSelected = DateTime.MinValue };
|
||||
}
|
||||
|
||||
public Dictionary<string, UserSelectedRecordItem> GetGenericHistory()
|
||||
{
|
||||
/*
|
||||
var history = new List<UserSelectedRecord.UserSelectedRecordItem>();
|
||||
|
||||
foreach (var record in Records)
|
||||
{
|
||||
if (record.Value.PluginID == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
history.Add(new UserSelectedRecordItem
|
||||
{
|
||||
SelectedCount = record.Value.SelectedCount,
|
||||
LastSelected = record.Value.LastSelected,
|
||||
IconPath = record.Value.IconPath,
|
||||
Title = record.Value.Title,
|
||||
Score = record.Value.Score,
|
||||
SubTitle = record.Value.SubTitle,
|
||||
PluginID = record.Value.PluginID,
|
||||
Search = record.Value.Search,
|
||||
});
|
||||
}
|
||||
|
||||
return history;
|
||||
*/
|
||||
|
||||
return Records;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user