Skip to content

Commit

Permalink
[PT Run] System plugin: Setting for separate "Empty Recycle Bin" resu…
Browse files Browse the repository at this point in the history
…lt (#24057)

* Split results and setting

* smalöl fixes

* fixes
  • Loading branch information
htcfreek committed Feb 22, 2023
1 parent 320cc56 commit 12ce7e7
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 12 deletions.
Expand Up @@ -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
{
Expand All @@ -37,11 +33,13 @@ internal static class Commands
/// 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[]
Expand Down Expand Up @@ -106,7 +104,39 @@ internal static List<Result> GetSystemCommands(bool isUefi, string iconTheme, Cu
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),
Expand All @@ -116,8 +146,8 @@ internal static List<Result> GetSystemCommands(bool isUefi, string iconTheme, Cu
{
return Helper.OpenInShell("explorer.exe", "shell:RecycleBinFolder");
},
},
});
});
}

// UEFI command/result. It is only available on systems booted in UEFI mode.
if (isUefi)
Expand Down
Expand Up @@ -7,7 +7,6 @@
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;
Expand Down
Expand Up @@ -26,6 +26,7 @@ public class Main : IPlugin, IPluginI18n, ISettingProvider, IContextMenu, IDelay
private bool _showSuccessOnEmptyRB;
private bool _localizeSystemCommands;
private bool _reduceNetworkResultScore;
private bool _separateEmptyRB;

public string Name => Resources.Microsoft_plugin_sys_plugin_name;

Expand Down Expand Up @@ -56,6 +57,12 @@ public class Main : IPlugin, IPluginI18n, ISettingProvider, IContextMenu, IDelay
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,
Expand Down Expand Up @@ -90,7 +97,7 @@ public List<Result> Query(Query query)
}

// 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);
Expand Down Expand Up @@ -209,6 +216,7 @@ public void UpdateSettings(PowerLauncherPluginSettings settings)
var showSuccessOnEmptyRB = false;
var localizeSystemCommands = true;
var reduceNetworkResultScore = true;
var separateEmptyRB = false;

if (settings != null && settings.AdditionalOptions != null)
{
Expand All @@ -223,12 +231,16 @@ public void UpdateSettings(PowerLauncherPluginSettings settings)

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;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down

0 comments on commit 12ce7e7

Please sign in to comment.