//------------------------------------------------- public bool VisitNode(GenericNode <T> Node_in) { // Create a new node. GenericNode <T> node = new GenericNode <T>(); node.Key = Node_in.Key; node.Value = Node_in.Value; // Position the new node. node.SetIndent(Node_in.Indent - this.SourceRoot.Indent); // Append the new node. this._LastNode.SetNextNode(node); node.SetPrevNode(this._LastNode); this._LastNode = node; // Return, OK return(true); }
//------------------------------------------------- public GenericNode <T> AddChild(GenericNode <T> Node_in, int Index_in, bool Silent_in) { // Validate. if ((Node_in == null)) { return(null); } // Notify Before Operation if (!Silent_in) { this.Notify(new NodeAddChildNotification(NodeNotification.NotificationStatus.Pending, this, Node_in, Index_in)); } // Adjust index. int nodeIndex = Index_in; // Get the insertion point. GenericNode <T> nodeInsertAfter = null; GenericNode <T> nodeInsertBefore = this.ChildNode(nodeIndex); if ((nodeInsertBefore == null)) { // Append the node. nodeInsertAfter = this.LastDescNode; if ((nodeInsertAfter == null)) { nodeInsertAfter = this; } nodeInsertBefore = nodeInsertAfter.NextNode; } else { // Insert the node. nodeInsertAfter = nodeInsertBefore.PrevNode; } // Get node range. GenericNode <T> nodeFirst = Node_in; GenericNode <T> nodeLast = nodeFirst.LastDescNode; if ((nodeLast == null)) { nodeLast = nodeFirst; } // Unlink nodes from source. if ((nodeFirst.PrevNode != null)) { nodeFirst.PrevNode.SetNextNode(nodeLast.NextNode); } if ((nodeLast.NextNode != null)) { nodeLast.NextNode.SetPrevNode(nodeFirst.PrevNode); } // Fix node indents. int nodeIndentDelta = ((this.Indent - Node_in.Indent) + 1); GenericNode <T> nodeNext = nodeFirst; while ((nodeNext != null)) { nodeNext.SetIndent(nodeNext.Indent + nodeIndentDelta); nodeNext = nodeNext.NextNode; } // Link nodes to target. nodeInsertAfter.SetNextNode(nodeFirst); nodeFirst.SetPrevNode(nodeInsertAfter); if ((nodeInsertBefore != null)) { nodeInsertBefore.SetPrevNode(nodeLast); nodeLast.SetNextNode(nodeInsertBefore); } // Notify After Operation if (!Silent_in) { this.Notify(new NodeAddChildNotification(NodeNotification.NotificationStatus.Completed, this, Node_in, Index_in)); } // Return nodes. return(Node_in); }