|
@@ -1,4 +1,6 @@
|
|
-using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
|
|
|
|
|
|
+using PixiEditor.ChangeableDocument.Changeables.Graph.Interfaces;
|
|
|
|
+using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
|
|
|
|
+using PixiEditor.ChangeableDocument.ChangeInfos.NodeGraph;
|
|
using PixiEditor.ChangeableDocument.ChangeInfos.Structure;
|
|
using PixiEditor.ChangeableDocument.ChangeInfos.Structure;
|
|
|
|
|
|
namespace PixiEditor.ChangeableDocument.Changes.Structure;
|
|
namespace PixiEditor.ChangeableDocument.Changes.Structure;
|
|
@@ -6,8 +8,9 @@ namespace PixiEditor.ChangeableDocument.Changes.Structure;
|
|
internal class DeleteStructureMember_Change : Change
|
|
internal class DeleteStructureMember_Change : Change
|
|
{
|
|
{
|
|
private Guid memberGuid;
|
|
private Guid memberGuid;
|
|
- private Guid parentGuid;
|
|
|
|
private int originalIndex;
|
|
private int originalIndex;
|
|
|
|
+ private List<IInputProperty> originalOutputConnections = new();
|
|
|
|
+ private List<(IInputProperty, IOutputProperty?)> originalInputConnections = new();
|
|
private StructureNode? savedCopy;
|
|
private StructureNode? savedCopy;
|
|
|
|
|
|
[GenerateMakeChangeAction]
|
|
[GenerateMakeChangeAction]
|
|
@@ -18,42 +21,89 @@ internal class DeleteStructureMember_Change : Change
|
|
|
|
|
|
public override bool InitializeAndValidate(Document document)
|
|
public override bool InitializeAndValidate(Document document)
|
|
{
|
|
{
|
|
- var (member, parent) = document.FindChildAndParent(memberGuid);
|
|
|
|
- if (member is null || parent is null)
|
|
|
|
|
|
+ var member = document.FindMember(memberGuid);
|
|
|
|
+ if (member is null)
|
|
return false;
|
|
return false;
|
|
|
|
|
|
- //originalIndex = parent.Children.IndexOf(member);
|
|
|
|
- parentGuid = parent.Id;
|
|
|
|
|
|
+ originalOutputConnections = member.Output.Connections.ToList();
|
|
|
|
+ originalInputConnections = member.InputProperties.Select(x => ((IInputProperty)x, x.Connection)).ToList();
|
|
savedCopy = (StructureNode)member.Clone();
|
|
savedCopy = (StructureNode)member.Clone();
|
|
|
|
+ savedCopy.Id = memberGuid;
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
- public override OneOf<None, IChangeInfo, List<IChangeInfo>> Apply(Document document, bool firstApply, out bool ignoreInUndo)
|
|
|
|
|
|
+ public override OneOf<None, IChangeInfo, List<IChangeInfo>> Apply(Document document, bool firstApply,
|
|
|
|
+ out bool ignoreInUndo)
|
|
{
|
|
{
|
|
- /*var (member, parent) = document.FindChildAndParentOrThrow(memberGuid);
|
|
|
|
- parent.Children = parent.Children.Remove(member);
|
|
|
|
- member.Dispose();
|
|
|
|
- ignoreInUndo = false;
|
|
|
|
- return new DeleteStructureMember_ChangeInfo(memberGuid, parentGuid);*/
|
|
|
|
-
|
|
|
|
|
|
+ StructureNode node = document.FindMember(memberGuid);
|
|
|
|
+
|
|
|
|
+ var bgConnection = node.Background.Connection;
|
|
|
|
+ var outputConnections = node.Output.Connections.ToArray();
|
|
|
|
+
|
|
|
|
+ document.NodeGraph.RemoveNode(node);
|
|
|
|
+
|
|
|
|
+ List<IChangeInfo> changes = new();
|
|
|
|
+
|
|
|
|
+ if (outputConnections != null && bgConnection != null)
|
|
|
|
+ {
|
|
|
|
+ foreach (var connection in outputConnections)
|
|
|
|
+ {
|
|
|
|
+ bgConnection.ConnectTo(connection);
|
|
|
|
+ changes.Add(new ConnectProperty_ChangeInfo(bgConnection.Node.Id, connection.Node.Id,
|
|
|
|
+ bgConnection.InternalPropertyName, connection.InternalPropertyName));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ node.Dispose();
|
|
ignoreInUndo = false;
|
|
ignoreInUndo = false;
|
|
- return new None();
|
|
|
|
|
|
+
|
|
|
|
+ changes.Add(new DeleteStructureMember_ChangeInfo(memberGuid));
|
|
|
|
+ return changes;
|
|
}
|
|
}
|
|
|
|
|
|
public override OneOf<None, IChangeInfo, List<IChangeInfo>> Revert(Document doc)
|
|
public override OneOf<None, IChangeInfo, List<IChangeInfo>> Revert(Document doc)
|
|
{
|
|
{
|
|
- /*var parent = doc.FindMemberOrThrow<FolderNode>(parentGuid);
|
|
|
|
|
|
+ var copy = (StructureNode)savedCopy!.Clone();
|
|
|
|
+ copy.Id = memberGuid;
|
|
|
|
|
|
- var copy = savedCopy!.Clone();
|
|
|
|
- parent.Children = parent.Children.Insert(originalIndex, copy);
|
|
|
|
- return copy switch
|
|
|
|
|
|
+ doc.NodeGraph.AddNode(copy);
|
|
|
|
+
|
|
|
|
+ List<IChangeInfo> changes = new();
|
|
|
|
+
|
|
|
|
+ IChangeInfo createChange = copy switch
|
|
{
|
|
{
|
|
- LayerNode => CreateLayer_ChangeInfo.FromLayer(parentGuid, originalIndex, (LayerNode)copy),
|
|
|
|
- FolderNode => CreateFolder_ChangeInfo.FromFolder(parentGuid, originalIndex, (FolderNode)copy),
|
|
|
|
|
|
+ LayerNode => CreateLayer_ChangeInfo.FromLayer(memberGuid, (LayerNode)copy),
|
|
|
|
+ FolderNode => CreateFolder_ChangeInfo.FromFolder(memberGuid, (FolderNode)copy),
|
|
_ => throw new NotSupportedException(),
|
|
_ => throw new NotSupportedException(),
|
|
- };*/
|
|
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ changes.Add(createChange);
|
|
|
|
+
|
|
|
|
+ foreach (var connection in originalOutputConnections)
|
|
|
|
+ {
|
|
|
|
+ copy.Output.ConnectTo(connection);
|
|
|
|
+ changes.Add(new ConnectProperty_ChangeInfo(copy.Id, connection.Node.Id, copy.Output.InternalPropertyName,
|
|
|
|
+ connection.InternalPropertyName));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ foreach (var connection in originalInputConnections)
|
|
|
|
+ {
|
|
|
|
+ if (connection.Item2 is null)
|
|
|
|
+ continue;
|
|
|
|
+
|
|
|
|
+ IInputProperty? input =
|
|
|
|
+ copy.InputProperties.FirstOrDefault(x => x.InternalPropertyName == connection.Item1.InternalPropertyName);
|
|
|
|
+
|
|
|
|
+ if (input != null)
|
|
|
|
+ {
|
|
|
|
+ connection.Item2.ConnectTo(input);
|
|
|
|
+ changes.Add(new ConnectProperty_ChangeInfo(connection.Item2.Node.Id, copy.Id,
|
|
|
|
+ connection.Item2.InternalPropertyName,
|
|
|
|
+ input.InternalPropertyName));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- return new None();
|
|
|
|
|
|
+ return changes;
|
|
}
|
|
}
|
|
|
|
|
|
public override void Dispose()
|
|
public override void Dispose()
|