|
@@ -1,49 +1,80 @@
|
|
-using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
|
|
|
|
|
|
+using PixiEditor.ChangeableDocument.Changeables.Graph;
|
|
|
|
+using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
|
|
|
|
+using PixiEditor.ChangeableDocument.ChangeInfos.NodeGraph;
|
|
using PixiEditor.ChangeableDocument.ChangeInfos.Structure;
|
|
using PixiEditor.ChangeableDocument.ChangeInfos.Structure;
|
|
|
|
+using PixiEditor.ChangeableDocument.Changes.NodeGraph;
|
|
|
|
+using PixiEditor.DrawingApi.Core;
|
|
|
|
|
|
namespace PixiEditor.ChangeableDocument.Changes.Structure;
|
|
namespace PixiEditor.ChangeableDocument.Changes.Structure;
|
|
|
|
+
|
|
internal class DuplicateLayer_Change : Change
|
|
internal class DuplicateLayer_Change : Change
|
|
{
|
|
{
|
|
private readonly Guid layerGuid;
|
|
private readonly Guid layerGuid;
|
|
private Guid duplicateGuid;
|
|
private Guid duplicateGuid;
|
|
|
|
+
|
|
|
|
+ private ConnectionsData? connectionsData;
|
|
|
|
|
|
[GenerateMakeChangeAction]
|
|
[GenerateMakeChangeAction]
|
|
public DuplicateLayer_Change(Guid layerGuid)
|
|
public DuplicateLayer_Change(Guid layerGuid)
|
|
{
|
|
{
|
|
this.layerGuid = layerGuid;
|
|
this.layerGuid = layerGuid;
|
|
}
|
|
}
|
|
|
|
+
|
|
public override bool InitializeAndValidate(Document target)
|
|
public override bool InitializeAndValidate(Document target)
|
|
{
|
|
{
|
|
if (!target.TryFindMember<LayerNode>(layerGuid, out LayerNode? layer))
|
|
if (!target.TryFindMember<LayerNode>(layerGuid, out LayerNode? layer))
|
|
return false;
|
|
return false;
|
|
duplicateGuid = Guid.NewGuid();
|
|
duplicateGuid = Guid.NewGuid();
|
|
|
|
+
|
|
|
|
+ connectionsData = NodeOperations.CreateConnectionsData(layer);
|
|
|
|
+
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
- public override OneOf<None, IChangeInfo, List<IChangeInfo>> Apply(Document target, bool firstApply, out bool ignoreInUndo)
|
|
|
|
|
|
+ public override OneOf<None, IChangeInfo, List<IChangeInfo>> Apply(Document target, bool firstApply,
|
|
|
|
+ out bool ignoreInUndo)
|
|
{
|
|
{
|
|
- (LayerNode existingLayer, FolderNode parent) = ((LayerNode, FolderNode))target.FindChildAndParentOrThrow(layerGuid);
|
|
|
|
|
|
+ (LayerNode existingLayer, Node parent) = ((LayerNode, Node))target.FindChildAndParentOrThrow(layerGuid);
|
|
|
|
+
|
|
|
|
|
|
LayerNode clone = (LayerNode)existingLayer.Clone();
|
|
LayerNode clone = (LayerNode)existingLayer.Clone();
|
|
clone.Id = duplicateGuid;
|
|
clone.Id = duplicateGuid;
|
|
|
|
|
|
- /*int index = parent.Children.IndexOf(existingLayerNode);
|
|
|
|
- parent.Children = parent.Children.Insert(index, clone);
|
|
|
|
|
|
+ InputProperty<Surface?> targetInput = parent.InputProperties.FirstOrDefault(x =>
|
|
|
|
+ x.ValueType == typeof(Surface) &&
|
|
|
|
+ x.Connection.Node is StructureNode) as InputProperty<Surface?>;
|
|
|
|
+
|
|
|
|
+ List<IChangeInfo> operations = new();
|
|
|
|
+
|
|
|
|
+ target.NodeGraph.AddNode(clone);
|
|
|
|
+
|
|
|
|
+ operations.Add(CreateLayer_ChangeInfo.FromLayer(clone));
|
|
|
|
+
|
|
|
|
+ operations.AddRange(NodeOperations.AppendMember(targetInput, clone.Output, clone.Background, clone.Id));
|
|
|
|
|
|
ignoreInUndo = false;
|
|
ignoreInUndo = false;
|
|
- return CreateLayer_ChangeInfo.FromLayer(parent.Id, index, clone);*/
|
|
|
|
-//TODO: Implement
|
|
|
|
- ignoreInUndo = false;
|
|
|
|
- return new None();
|
|
|
|
|
|
+
|
|
|
|
+ return operations;
|
|
}
|
|
}
|
|
|
|
|
|
public override OneOf<None, IChangeInfo, List<IChangeInfo>> Revert(Document target)
|
|
public override OneOf<None, IChangeInfo, List<IChangeInfo>> Revert(Document target)
|
|
{
|
|
{
|
|
- /*var (member, parent) = target.FindChildAndParentOrThrow(duplicateGuid);
|
|
|
|
- parent.Children = parent.Children.Remove(member);
|
|
|
|
|
|
+ var (member, parent) = target.FindChildAndParentOrThrow(duplicateGuid);
|
|
|
|
+
|
|
|
|
+ target.NodeGraph.RemoveNode(member);
|
|
member.Dispose();
|
|
member.Dispose();
|
|
- return new DeleteStructureMember_ChangeInfo(duplicateGuid, parent.Id);*/
|
|
|
|
|
|
|
|
- return new None();
|
|
|
|
|
|
+ List<IChangeInfo> changes = new();
|
|
|
|
+
|
|
|
|
+ changes.AddRange(NodeOperations.DetachStructureNode(member));
|
|
|
|
+ changes.Add(new DeleteStructureMember_ChangeInfo(member.Id));
|
|
|
|
+
|
|
|
|
+ if (connectionsData is not null)
|
|
|
|
+ {
|
|
|
|
+ Node originalNode = target.FindNodeOrThrow<Node>(layerGuid);
|
|
|
|
+ changes.AddRange(NodeOperations.ConnectStructureNodeProperties(connectionsData, originalNode, target.NodeGraph));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return changes;
|
|
}
|
|
}
|
|
}
|
|
}
|