mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 02:36:19 +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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user