[PT Run] System plugin: Setting for separate "Empty Recycle Bin" result (#24057)

* Split results and setting

* smalöl fixes

* fixes
This commit is contained in:
Heiko 2023-02-22 16:40:02 +01:00 committed by GitHub
parent 320cc56b7e
commit 12ce7e7674
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 104 additions and 12 deletions

View File

@ -5,14 +5,10 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Runtime;
using System.Windows;
using System.Windows.Interop;
using Microsoft.PowerToys.Run.Plugin.System.Properties;
using Wox.Infrastructure;
using Wox.Plugin;
using Wox.Plugin.Common.Win32;
using Wox.Plugin.Logger;
namespace Microsoft.PowerToys.Run.Plugin.System.Components
{
@ -37,11 +33,13 @@ namespace Microsoft.PowerToys.Run.Plugin.System.Components
/// Returns a list with all system command results
/// </summary>
/// <param name="isUefi">Value indicating if the system is booted in uefi mode</param>
/// <param name="splitRecycleBinResults">Value indicating if we should show two results for Recycle Bin.</param>
/// <param name="confirmCommands">A value indicating if the user should confirm the system commands</param>
/// <param name="emptyRBSuccessMessage">Show a success message after empty Recycle Bin.</param>
/// <param name="iconTheme">The current theme to use for the icons</param>
/// <param name="culture">The culture to use for the result's title and sub title</param>
/// <param name="confirmCommands">A value indicating if the user should confirm the system commands</param>
/// <returns>A list of all results</returns>
internal static List<Result> GetSystemCommands(bool isUefi, string iconTheme, CultureInfo culture, bool confirmCommands)
internal static List<Result> GetSystemCommands(bool isUefi, bool splitRecycleBinResults, bool confirmCommands, bool emptyRBSuccessMessage, string iconTheme, CultureInfo culture)
{
var results = new List<Result>();
results.AddRange(new[]
@ -106,7 +104,39 @@ namespace Microsoft.PowerToys.Run.Plugin.System.Components
return ResultHelper.ExecuteCommand(confirmCommands, Resources.Microsoft_plugin_sys_hibernate_confirmation, () => NativeMethods.SetSuspendState(true, true, true));
},
},
new Result
});
// Show Recycle Bin results based on setting.
if (splitRecycleBinResults)
{
results.AddRange(new[]
{
new Result
{
Title = Resources.ResourceManager.GetString("Microsoft_plugin_sys_RecycleBinOpen", culture),
SubTitle = Resources.ResourceManager.GetString("Microsoft_plugin_sys_RecycleBin_description", culture),
IcoPath = $"Images\\recyclebin.{iconTheme}.png",
Action = c =>
{
return Helper.OpenInShell("explorer.exe", "shell:RecycleBinFolder");
},
},
new Result
{
Title = Resources.ResourceManager.GetString("Microsoft_plugin_sys_RecycleBinEmptyResult", culture),
SubTitle = Resources.ResourceManager.GetString("Microsoft_plugin_sys_RecycleBinEmpty_description", culture),
IcoPath = $"Images\\recyclebin.{iconTheme}.png",
Action = c =>
{
ResultHelper.EmptyRecycleBinAsync(emptyRBSuccessMessage);
return true;
},
},
});
}
else
{
results.Add(new Result
{
Title = Resources.ResourceManager.GetString("Microsoft_plugin_sys_RecycleBin", culture),
SubTitle = Resources.ResourceManager.GetString("Microsoft_plugin_sys_RecycleBin_description", culture),
@ -116,8 +146,8 @@ namespace Microsoft.PowerToys.Run.Plugin.System.Components
{
return Helper.OpenInShell("explorer.exe", "shell:RecycleBinFolder");
},
},
});
});
}
// UEFI command/result. It is only available on systems booted in UEFI mode.
if (isUefi)

View File

@ -7,7 +7,6 @@ using System.Collections.Generic;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Navigation;
using Microsoft.PowerToys.Run.Plugin.System.Properties;
using Wox.Plugin;
using Wox.Plugin.Common.Win32;

View File

@ -26,6 +26,7 @@ namespace Microsoft.PowerToys.Run.Plugin.System
private bool _showSuccessOnEmptyRB;
private bool _localizeSystemCommands;
private bool _reduceNetworkResultScore;
private bool _separateEmptyRB;
public string Name => Resources.Microsoft_plugin_sys_plugin_name;
@ -56,6 +57,12 @@ namespace Microsoft.PowerToys.Run.Plugin.System
Value = true,
},
new PluginAdditionalOption()
{
Key = "SeparateResultEmptyRB",
DisplayLabel = Resources.Microsoft_plugin_sys_RecycleBin_ShowEmptySeparate,
Value = false,
},
new PluginAdditionalOption()
{
Key = "ReduceNetworkResultScore",
DisplayLabel = Resources.Reduce_Network_Result_Score,
@ -90,7 +97,7 @@ namespace Microsoft.PowerToys.Run.Plugin.System
}
// normal system commands are fast and can be returned immediately
var systemCommands = Commands.GetSystemCommands(IsBootedInUefiMode, IconTheme, culture, _confirmSystemCommands);
var systemCommands = Commands.GetSystemCommands(IsBootedInUefiMode, _separateEmptyRB, _confirmSystemCommands, _showSuccessOnEmptyRB, IconTheme, culture);
foreach (var c in systemCommands)
{
var resultMatch = StringMatcher.FuzzySearch(query.Search, c.Title);
@ -209,6 +216,7 @@ namespace Microsoft.PowerToys.Run.Plugin.System
var showSuccessOnEmptyRB = false;
var localizeSystemCommands = true;
var reduceNetworkResultScore = true;
var separateEmptyRB = false;
if (settings != null && settings.AdditionalOptions != null)
{
@ -223,12 +231,16 @@ namespace Microsoft.PowerToys.Run.Plugin.System
var optionNetworkScore = settings.AdditionalOptions.FirstOrDefault(x => x.Key == "ReduceNetworkResultScore");
reduceNetworkResultScore = optionNetworkScore?.Value ?? reduceNetworkResultScore;
var optionSeparateEmptyRB = settings.AdditionalOptions.FirstOrDefault(x => x.Key == "SeparateResultEmptyRB");
separateEmptyRB = optionSeparateEmptyRB?.Value ?? separateEmptyRB;
}
_confirmSystemCommands = confirmSystemCommands;
_showSuccessOnEmptyRB = showSuccessOnEmptyRB;
_localizeSystemCommands = localizeSystemCommands;
_reduceNetworkResultScore = reduceNetworkResultScore;
_separateEmptyRB = separateEmptyRB;
}
}
}

View File

@ -457,7 +457,16 @@ namespace Microsoft.PowerToys.Run.Plugin.System.Properties {
}
/// <summary>
/// Looks up a localized string similar to Show a success message after empty the Recycle Bin.
/// Looks up a localized string similar to Show separate result for Empty Recycle Bin command.
/// </summary>
internal static string Microsoft_plugin_sys_RecycleBin_ShowEmptySeparate {
get {
return ResourceManager.GetString("Microsoft_plugin_sys_RecycleBin_ShowEmptySeparate", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Show a success message after emptying the Recycle Bin.
/// </summary>
internal static string Microsoft_plugin_sys_RecycleBin_ShowEmptySuccessMessage {
get {
@ -465,6 +474,33 @@ namespace Microsoft.PowerToys.Run.Plugin.System.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Empty Recycle Bin.
/// </summary>
internal static string Microsoft_plugin_sys_RecycleBinEmpty_description {
get {
return ResourceManager.GetString("Microsoft_plugin_sys_RecycleBinEmpty_description", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Empty Recycle Bin.
/// </summary>
internal static string Microsoft_plugin_sys_RecycleBinEmptyResult {
get {
return ResourceManager.GetString("Microsoft_plugin_sys_RecycleBinEmptyResult", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Open Recycle Bin.
/// </summary>
internal static string Microsoft_plugin_sys_RecycleBinOpen {
get {
return ResourceManager.GetString("Microsoft_plugin_sys_RecycleBinOpen", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Restart.
/// </summary>

View File

@ -244,6 +244,18 @@
<value>Recycle Bin</value>
<comment>Means the recycle bin folder in Explorer.</comment>
</data>
<data name="Microsoft_plugin_sys_RecycleBinEmptyResult" xml:space="preserve">
<value>Empty Recycle Bin</value>
<comment>This should align to the action in Windows of emptying the recycle bin on your computer.</comment>
</data>
<data name="Microsoft_plugin_sys_RecycleBinEmpty_description" xml:space="preserve">
<value>Empty Recycle Bin</value>
<comment>This should align to the action in Windows of emptying the recycle bin on your computer.</comment>
</data>
<data name="Microsoft_plugin_sys_RecycleBinOpen" xml:space="preserve">
<value>Open Recycle Bin</value>
<comment>Means the recycle bin folder in Explorer.</comment>
</data>
<data name="Microsoft_plugin_sys_RecycleBin_contextMenu" xml:space="preserve">
<value>Empty Recycle Bin (Shift+Delete)</value>
<comment>This should align to the action in Windows of emptying the recycle bin on your computer.</comment>
@ -271,6 +283,9 @@
<value>Empty Recycle Bin</value>
<comment>This should align to the action in Windows of emptying the recycle bin on your computer.</comment>
</data>
<data name="Microsoft_plugin_sys_RecycleBin_ShowEmptySeparate" xml:space="preserve">
<value>Show separate result for Empty Recycle Bin command</value>
</data>
<data name="Microsoft_plugin_sys_RecycleBin_ShowEmptySuccessMessage" xml:space="preserve">
<value>Show a success message after emptying the Recycle Bin</value>
<comment>Means the recycle bin folder in Explorer and "emptying" refers to "Empty Recycle Bin" command.</comment>