From d9ec0c8c496c19bb8cc7001e0c46e759257d4d6c Mon Sep 17 00:00:00 2001 From: Brenden Harrell Date: Fri, 23 Jul 2021 21:58:51 -0500 Subject: [PATCH] Initial work on Auto Reference feature --- .../UI/Function-Libraries/ProtocolNode.js | 12 ++++++++++ .../ReferenceAttachDetach.js | 24 ++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/Projects/Foundations/UI/Function-Libraries/ProtocolNode.js b/Projects/Foundations/UI/Function-Libraries/ProtocolNode.js index 50696f57c..3ce61e541 100644 --- a/Projects/Foundations/UI/Function-Libraries/ProtocolNode.js +++ b/Projects/Foundations/UI/Function-Libraries/ProtocolNode.js @@ -259,13 +259,25 @@ function newFoundationsFunctionLibraryProtocolNode() { name: node.payload.referenceParent.name, id: node.payload.referenceParent.id } + // If the path has not been saved save it now + if (node.payload.referenceParentCombinedNodePath === undefined) { + let attachNodePath = UI.projects.foundations.utilities.hierarchy.getNodeNameTypePath(node.payload.referenceParent) + // Save path to reference parent for auto restore + savedPayload.referenceParentCombinedNodePath = { path: attachNodePath } + } else { + // Save path to reference parent for auto restore + savedPayload.referenceParentCombinedNodePath = { path: node.payload.referenceParentCombinedNodePath } + } } else { /* The referenceParent property can be inherited from the previous saved payload. */ if (node.savedPayload !== undefined) { savedPayload.referenceParent = node.savedPayload.referenceParent + // Save path to reference parent for auto restore + savedPayload.referenceParentCombinedNodePath = node.payload.referenceParentCombinedNodePath } } } + console.log("this is the saved payload", savedPayload) return savedPayload } } diff --git a/Projects/Foundations/UI/Function-Libraries/ReferenceAttachDetach.js b/Projects/Foundations/UI/Function-Libraries/ReferenceAttachDetach.js index eaeee4f98..aed3561dc 100644 --- a/Projects/Foundations/UI/Function-Libraries/ReferenceAttachDetach.js +++ b/Projects/Foundations/UI/Function-Libraries/ReferenceAttachDetach.js @@ -7,17 +7,39 @@ function newFoundationsFunctionLibraryAttachDetach() { return thisObject function referenceDetachNode(node) { - completeDetachment(node) + cleanAttachNodePath(node) + completeDetachment(node) + } function referenceAttachNode(node, attachToNode) { + storeAttachNodePath(node, attachToNode) completeAttachment(node, attachToNode) } + // Store the path to the reference parent to make restoring it possible if the reference partent is updated and given a new id + function storeAttachNodePath(node, attachToNode) { + let attachNodePath = UI.projects.foundations.utilities.hierarchy.getNodeNameTypePath(attachToNode) + // Save attach path to active payload + node.payload.referenceParentCombinedNodePath = { path: attachNodePath } + } + + // Clear the path to reference parent when the reference is cleared + function cleanAttachNodePath(node){ + if (node.payload !== undefined) { + node.payload.referenceParentCombinedNodePath = undefined + if (node.savedPayload !== undefined) { + node.savedPayload.referenceParentCombinedNodePath = undefined + } + } + } + + // Establish the reference between node and it's reference parent function completeAttachment(node, attachToNode) { node.payload.referenceParent = attachToNode } + // Detach the reference between node and it's reference parent function completeDetachment(node) { if (node.payload !== undefined) { if (node.payload.referenceParent !== undefined) {