From 70e0eef5ce254b36e0d26d46cf6bd886a5dc5a63 Mon Sep 17 00:00:00 2001 From: goaaats Date: Thu, 28 Mar 2024 14:09:24 +0100 Subject: [PATCH] normalize command names for profile management --- .../PluginInstaller/ProfileManagerWidget.cs | 6 +-- .../Profiles/ProfileCommandHandler.cs | 40 ++++++++++++++++--- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs b/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs index 9f3196928..6bee26755 100644 --- a/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs +++ b/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs @@ -651,13 +651,13 @@ internal class ProfileManagerWidget Loc.Localize("ProfileManagerTutorialCommands", "You can use the following commands in chat or in macros to manage active collections:"); public static string TutorialCommandsEnable => - Loc.Localize("ProfileManagerTutorialCommandsEnable", "/xlenableprofile \"Collection Name\" - Enable a collection"); + Loc.Localize("ProfileManagerTutorialCommandsEnable", "{0} \"Collection Name\" - Enable a collection").Format(ProfileCommandHandler.CommandEnable); public static string TutorialCommandsDisable => - Loc.Localize("ProfileManagerTutorialCommandsDisable", "/xldisableprofile \"Collection Name\" - Disable a collection"); + Loc.Localize("ProfileManagerTutorialCommandsDisable", "{0} \"Collection Name\" - Disable a collection").Format(ProfileCommandHandler.CommandDisable); public static string TutorialCommandsToggle => - Loc.Localize("ProfileManagerTutorialCommandsToggle", "/xltoggleprofile \"Collection Name\" - Toggle a collection's state"); + Loc.Localize("ProfileManagerTutorialCommandsToggle", "{0} \"Collection Name\" - Toggle a collection's state").Format(ProfileCommandHandler.CommandToggle); public static string TutorialCommandsEnd => Loc.Localize("ProfileManagerTutorialCommandsEnd", "If you run multiple of these commands, they will be executed in order."); diff --git a/Dalamud/Plugin/Internal/Profiles/ProfileCommandHandler.cs b/Dalamud/Plugin/Internal/Profiles/ProfileCommandHandler.cs index eebb87aaa..7b7b4cfd0 100644 --- a/Dalamud/Plugin/Internal/Profiles/ProfileCommandHandler.cs +++ b/Dalamud/Plugin/Internal/Profiles/ProfileCommandHandler.cs @@ -18,6 +18,16 @@ namespace Dalamud.Plugin.Internal.Profiles; [ServiceManager.EarlyLoadedService] internal class ProfileCommandHandler : IInternalDisposableService { +#pragma warning disable SA1600 + public const string CommandEnable = "/xlenablecollection"; + public const string CommandDisable = "/xldisablecollection"; + public const string CommandToggle = "/xltogglecollection"; +#pragma warning restore SA1600 + + private static readonly string LegacyCommandEnable = CommandEnable.Replace("collection", "profile"); + private static readonly string LegacyCommandDisable = CommandDisable.Replace("collection", "profile"); + private static readonly string LegacyCommandToggle = CommandToggle.Replace("collection", "profile"); + private readonly CommandManager cmd; private readonly ProfileManager profileManager; private readonly ChatGui chat; @@ -40,23 +50,38 @@ internal class ProfileCommandHandler : IInternalDisposableService this.chat = chat; this.framework = framework; - this.cmd.AddHandler("/xlenableprofile", new CommandInfo(this.OnEnableProfile) + this.cmd.AddHandler(CommandEnable, new CommandInfo(this.OnEnableProfile) { HelpMessage = Loc.Localize("ProfileCommandsEnableHint", "Enable a collection. Usage: /xlenablecollection \"Collection Name\""), ShowInHelp = true, }); - this.cmd.AddHandler("/xldisableprofile", new CommandInfo(this.OnDisableProfile) + this.cmd.AddHandler(CommandDisable, new CommandInfo(this.OnDisableProfile) { HelpMessage = Loc.Localize("ProfileCommandsDisableHint", "Disable a collection. Usage: /xldisablecollection \"Collection Name\""), ShowInHelp = true, }); - this.cmd.AddHandler("/xltoggleprofile", new CommandInfo(this.OnToggleProfile) + this.cmd.AddHandler(CommandToggle, new CommandInfo(this.OnToggleProfile) { HelpMessage = Loc.Localize("ProfileCommandsToggleHint", "Toggle a collection. Usage: /xltogglecollection \"Collection Name\""), ShowInHelp = true, }); + + this.cmd.AddHandler(LegacyCommandEnable, new CommandInfo(this.OnEnableProfile) + { + ShowInHelp = false, + }); + + this.cmd.AddHandler(LegacyCommandDisable, new CommandInfo(this.OnDisableProfile) + { + ShowInHelp = true, + }); + + this.cmd.AddHandler(LegacyCommandToggle, new CommandInfo(this.OnToggleProfile) + { + ShowInHelp = true, + }); this.framework.Update += this.FrameworkOnUpdate; } @@ -71,9 +96,12 @@ internal class ProfileCommandHandler : IInternalDisposableService /// void IInternalDisposableService.DisposeService() { - this.cmd.RemoveHandler("/xlenablecollection"); - this.cmd.RemoveHandler("/xldisablecollection"); - this.cmd.RemoveHandler("/xltogglecollection"); + this.cmd.RemoveHandler(CommandEnable); + this.cmd.RemoveHandler(CommandDisable); + this.cmd.RemoveHandler(CommandToggle); + this.cmd.RemoveHandler(LegacyCommandEnable); + this.cmd.RemoveHandler(LegacyCommandDisable); + this.cmd.RemoveHandler(LegacyCommandToggle); this.framework.Update += this.FrameworkOnUpdate; }