From 66cf8cb1b3b7277fd1edeb3fbbac8dabdd24dc32 Mon Sep 17 00:00:00 2001 From: Aireil <33433913+Aireil@users.noreply.github.com> Date: Thu, 5 Oct 2023 00:06:34 +0200 Subject: [PATCH] fix: delete plugin button behavior --- .../PluginInstaller/PluginInstallerWindow.cs | 92 +++++++++---------- 1 file changed, 45 insertions(+), 47 deletions(-) diff --git a/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs b/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs index 036959233..34a242106 100644 --- a/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs +++ b/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs @@ -2832,68 +2832,66 @@ private void DrawDeletePluginButton(LocalPlugin plugin) var pluginManager = Service.Get(); - var devNotDeletable = plugin.IsDev && plugin.State != PluginState.Unloaded && plugin.State != PluginState.DependencyResolutionFailed; + var isRemovable = !plugin.HasEverStartedLoad || plugin.State is PluginState.Unloaded or PluginState.DependencyResolutionFailed; + var isDevNotRemovable = plugin.IsDev && !isRemovable; + var isButtonDisabled = plugin.State == PluginState.Loaded || isDevNotRemovable; ImGui.SameLine(); - if (plugin.State == PluginState.Loaded || devNotDeletable) + if (isButtonDisabled) { - ImGui.PushFont(InterfaceManager.IconFont); - ImGuiComponents.DisabledButton(FontAwesomeIcon.TrashAlt.ToIconString()); - ImGui.PopFont(); - - if (ImGui.IsItemHovered()) - { - ImGui.SetTooltip(plugin.State == PluginState.Loaded - ? Locs.PluginButtonToolTip_DeletePluginLoaded - : Locs.PluginButtonToolTip_DeletePluginRestricted); - } + ImGuiComponents.DisabledButton(FontAwesomeIcon.TrashAlt); } - else + else if (ImGuiComponents.IconButton(FontAwesomeIcon.TrashAlt)) { - if (ImGuiComponents.IconButton(FontAwesomeIcon.TrashAlt)) + try { - try + if (plugin.IsDev) { - if (plugin.IsDev) - { - plugin.DllFile.Delete(); - } - else - { - plugin.ScheduleDeletion(!plugin.Manifest.ScheduledForDeletion); - } - - if (plugin.State is PluginState.Unloaded or PluginState.DependencyResolutionFailed) - { - pluginManager.RemovePlugin(plugin); - } + plugin.DllFile.Delete(); } - catch (Exception ex) + else { - Log.Error(ex, $"Plugin installer threw an error during removal of {plugin.Name}"); - - this.ShowErrorModal(Locs.ErrorModal_DeleteFail(plugin.Name)); + plugin.ScheduleDeletion(!plugin.Manifest.ScheduledForDeletion); } - } - if (ImGui.IsItemHovered()) - { - string tooltipMessage; - if (plugin.Manifest.ScheduledForDeletion) + if (isRemovable) { - tooltipMessage = Locs.PluginButtonToolTip_DeletePluginScheduledCancel; - } - else if (plugin.State is PluginState.Unloaded or PluginState.DependencyResolutionFailed) - { - tooltipMessage = Locs.PluginButtonToolTip_DeletePlugin; - } - else - { - tooltipMessage = Locs.PluginButtonToolTip_DeletePluginScheduled; + pluginManager.RemovePlugin(plugin); } + } + catch (Exception ex) + { + Log.Error(ex, $"Plugin installer threw an error during removal of {plugin.Name}"); + + this.ShowErrorModal(Locs.ErrorModal_DeleteFail(plugin.Name)); + } + } - ImGui.SetTooltip(tooltipMessage); + if (ImGui.IsItemHovered()) + { + string tooltipMessage; + if (plugin.State == PluginState.Loaded) + { + tooltipMessage = Locs.PluginButtonToolTip_DeletePluginLoaded; + } + else if (isDevNotRemovable) + { + tooltipMessage = Locs.PluginButtonToolTip_DeletePluginRestricted; + } + else if (plugin.Manifest.ScheduledForDeletion) + { + tooltipMessage = Locs.PluginButtonToolTip_DeletePluginScheduledCancel; } + else if (!isRemovable) + { + tooltipMessage = Locs.PluginButtonToolTip_DeletePluginScheduled; + } + else + { + tooltipMessage = Locs.PluginButtonToolTip_DeletePlugin; + } + + ImGui.SetTooltip(tooltipMessage); } }