mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Script editor - Added auto-arrange button
This commit is contained in:
1 parent
3ecf0bed5a
commit
65b8b377ec
5 files changed
+89
-7
No files matched your search
@@ -0,0 +1,43 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Artemis.Core;
|
||||
|
||||
namespace Artemis.UI.Shared.Services.NodeEditor.Commands;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a node editor command that can be used to organize a script
|
||||
/// </summary>
|
||||
public class OrganizeScript : INodeEditorCommand
|
||||
{
|
||||
private readonly NodeScript _script;
|
||||
private readonly List<(INode node, double x, double y)> _originalPositions;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="OrganizeScript"/> class.
|
||||
/// </summary>
|
||||
/// <param name="script">The script to organize.</param>
|
||||
public OrganizeScript(NodeScript script)
|
||||
{
|
||||
_script = script;
|
||||
_originalPositions = script.Nodes.Select(n => (n, n.X, n.Y)).ToList();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public string DisplayName => "Organize script";
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Execute()
|
||||
{
|
||||
_script.Organize();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Undo()
|
||||
{
|
||||
foreach ((INode? node, double x, double y) in _originalPositions)
|
||||
{
|
||||
node.X = x;
|
||||
node.Y = y;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user