1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00
Robert 8fd18b9565 Node editor - Added preview mode
in this mode the editor is read-only and rescales itself to fit it's container
2022-04-01 00:48:56 +02:00

57 lines
1.5 KiB
C#

using Artemis.Core;
namespace Artemis.UI.Shared.Services.ProfileEditor.Commands;
/// <summary>
/// Represents a profile editor command that can be used to move a profile element.
/// </summary>
public class MoveProfileElement : IProfileEditorCommand
{
private readonly int _originalIndex;
private readonly ProfileElement? _originalParent;
private readonly ProfileElement _subject;
private readonly ProfileElement _target;
private readonly int _targetIndex;
/// <summary>
/// Creates a new instance of the <see cref="MoveProfileElement" /> class.
/// </summary>
public MoveProfileElement(ProfileElement target, ProfileElement subject, int targetIndex)
{
_target = target;
_subject = subject;
_targetIndex = targetIndex;
if (_subject.Parent != null)
{
_originalParent = _subject.Parent;
_originalIndex = _subject.Parent.Children.IndexOf(_subject);
}
if (subject is Folder)
DisplayName = "Move folder";
DisplayName = "Move layer";
}
#region Implementation of IProfileEditorCommand
/// <inheritdoc />
public string DisplayName { get; }
/// <inheritdoc />
public void Execute()
{
_subject.Parent?.RemoveChild(_subject);
_target.AddChild(_subject, _targetIndex);
}
/// <inheritdoc />
public void Undo()
{
_target.RemoveChild(_subject);
_originalParent?.AddChild(_subject, _originalIndex);
}
#endregion
}