using System; using Artemis.Core; namespace Artemis.UI.Shared.Services.ProfileEditor.Commands; /// /// Represents a profile editor command that can be used to change the display condition of a profile element. /// public class ChangeElementDisplayCondition : IProfileEditorCommand, IDisposable { private readonly ICondition _condition; private readonly ICondition _oldCondition; private readonly RenderProfileElement _profileElement; private bool _executed; /// /// Creates a new instance of the class. /// /// The render profile element whose display condition to change. /// The new display condition. public ChangeElementDisplayCondition(RenderProfileElement profileElement, ICondition condition) { _profileElement = profileElement; _condition = condition; _oldCondition = profileElement.DisplayCondition; } /// public void Dispose() { if (_executed) _oldCondition?.Dispose(); else _condition?.Dispose(); } /// public string DisplayName => "Change display condition mode"; /// public void Execute() { _profileElement.DisplayCondition = _condition; _executed = true; } /// public void Undo() { _profileElement.DisplayCondition = _oldCondition; _executed = false; } }