From 874fca37af7ec2597fae60f75e4323a645facf26 Mon Sep 17 00:00:00 2001 From: Etienne Baudoux Date: Sun, 27 Oct 2024 20:12:35 -0700 Subject: [PATCH] Added an option to disable recent tools (#1433) --- .../Settings/Settings.Designer.cs | 18 +++++++++++ .../BuiltInTools/Settings/Settings.resx | 6 ++++ .../BuiltInTools/Settings/SettingsGuiTool.cs | 8 +++++ .../Settings/PredefinedSettings.cs | 8 +++++ .../dev/DevToys.Core/Tools/GuiToolProvider.cs | 31 ++++++++++--------- 5 files changed, 57 insertions(+), 14 deletions(-) diff --git a/src/app/dev/DevToys.Blazor/BuiltInTools/Settings/Settings.Designer.cs b/src/app/dev/DevToys.Blazor/BuiltInTools/Settings/Settings.Designer.cs index 400a510a4e..d6d769d9e2 100644 --- a/src/app/dev/DevToys.Blazor/BuiltInTools/Settings/Settings.Designer.cs +++ b/src/app/dev/DevToys.Blazor/BuiltInTools/Settings/Settings.Designer.cs @@ -375,6 +375,24 @@ internal static string PasteClearsTextStateDescriptionWhenOn { } } + /// + /// Looks up a localized string similar to Show most recent used tools. + /// + internal static string RecentTools { + get { + return ResourceManager.GetString("RecentTools", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Display the last 3 used tools in the menu. The change will take effect after restarting the app.. + /// + internal static string RecentToolsDescription { + get { + return ResourceManager.GetString("RecentToolsDescription", resourceCulture); + } + } + /// /// Looks up a localized string similar to Render white space. /// diff --git a/src/app/dev/DevToys.Blazor/BuiltInTools/Settings/Settings.resx b/src/app/dev/DevToys.Blazor/BuiltInTools/Settings/Settings.resx index c82ac6f0ba..170c7e3d85 100644 --- a/src/app/dev/DevToys.Blazor/BuiltInTools/Settings/Settings.resx +++ b/src/app/dev/DevToys.Blazor/BuiltInTools/Settings/Settings.resx @@ -224,6 +224,12 @@ Replace text when pasting + + Show most recent used tools + + + Display the last 3 used tools in the menu. The change will take effect after restarting the app. + Render white space diff --git a/src/app/dev/DevToys.Blazor/BuiltInTools/Settings/SettingsGuiTool.cs b/src/app/dev/DevToys.Blazor/BuiltInTools/Settings/SettingsGuiTool.cs index 75ea7b1124..ae6f4ff3c2 100644 --- a/src/app/dev/DevToys.Blazor/BuiltInTools/Settings/SettingsGuiTool.cs +++ b/src/app/dev/DevToys.Blazor/BuiltInTools/Settings/SettingsGuiTool.cs @@ -129,6 +129,14 @@ public UIToolView View _settingsProvider, PredefinedSettings.CheckForUpdate), + Setting("recenttools-setting") + .Icon("FluentSystemIcons", '\uED83') + .Title(Settings.RecentTools) + .Description(Settings.RecentToolsDescription) + .Handle( + _settingsProvider, + PredefinedSettings.ShowMostRecentTools), + SettingGroup("smart-detection-settings") .Icon("FluentSystemIcons", '\uF4D5') .Title(Settings.SmartDetection) diff --git a/src/app/dev/DevToys.Core/Settings/PredefinedSettings.cs b/src/app/dev/DevToys.Core/Settings/PredefinedSettings.cs index 8ca1f7e8be..7b97db4df0 100644 --- a/src/app/dev/DevToys.Core/Settings/PredefinedSettings.cs +++ b/src/app/dev/DevToys.Core/Settings/PredefinedSettings.cs @@ -94,6 +94,14 @@ public static readonly SettingDefinition RecentTool3 name: nameof(RecentTool3), defaultValue: string.Empty); + /// + /// Whether the most recent tools should be displayed. + /// + public static readonly SettingDefinition ShowMostRecentTools + = new( + name: nameof(ShowMostRecentTools), + defaultValue: true); + /// /// Whether the app should automatically check for updates. /// diff --git a/src/app/dev/DevToys.Core/Tools/GuiToolProvider.cs b/src/app/dev/DevToys.Core/Tools/GuiToolProvider.cs index aee75ad7d5..4494fa5dfb 100644 --- a/src/app/dev/DevToys.Core/Tools/GuiToolProvider.cs +++ b/src/app/dev/DevToys.Core/Tools/GuiToolProvider.cs @@ -158,23 +158,26 @@ public void SetMostRecentUsedTool(GuiToolInstance guiToolInstance) /// public IEnumerable GetMostRecentUsedTools() { - GuiToolInstance? recentTool1 = GetToolFromInternalName(_settingsProvider.GetSetting(PredefinedSettings.RecentTool1)); - GuiToolInstance? recentTool2 = GetToolFromInternalName(_settingsProvider.GetSetting(PredefinedSettings.RecentTool2)); - GuiToolInstance? recentTool3 = GetToolFromInternalName(_settingsProvider.GetSetting(PredefinedSettings.RecentTool3)); - - if (recentTool1 is not null) + if (_settingsProvider.GetSetting(PredefinedSettings.ShowMostRecentTools)) { - yield return recentTool1; - } + GuiToolInstance? recentTool1 = GetToolFromInternalName(_settingsProvider.GetSetting(PredefinedSettings.RecentTool1)); + GuiToolInstance? recentTool2 = GetToolFromInternalName(_settingsProvider.GetSetting(PredefinedSettings.RecentTool2)); + GuiToolInstance? recentTool3 = GetToolFromInternalName(_settingsProvider.GetSetting(PredefinedSettings.RecentTool3)); - if (recentTool2 is not null) - { - yield return recentTool2; - } + if (recentTool1 is not null) + { + yield return recentTool1; + } - if (recentTool3 is not null) - { - yield return recentTool3; + if (recentTool2 is not null) + { + yield return recentTool2; + } + + if (recentTool3 is not null) + { + yield return recentTool3; + } } }