mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 10:46:33 +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:
@@ -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