/// <summary> /// Inserts a new block with one node in a block list. /// </summary> /// <param name="operation">Details of the operation performed.</param> public virtual void InsertNewBlock(IWriteableInsertBlockOperation operation) { Debug.Assert(operation != null); int BlockIndex = operation.BlockIndex; Debug.Assert(BlockIndex >= 0 && BlockIndex <= BlockStateList.Count); IBlock NewBlock = operation.Block; Debug.Assert(NewBlock != null); INode NewNode = operation.Node; Debug.Assert(NewBlock != null); INode ParentNode = Owner.Node; NodeTreeHelperBlockList.InsertIntoBlockList(ParentNode, PropertyName, BlockIndex, NewBlock); NodeTreeHelperBlockList.InsertIntoBlock(NewBlock, 0, NewNode); IWriteableBrowsingNewBlockNodeIndex BrowsingNewBlockIndex = CreateNewBlockNodeIndex(NewNode, BlockIndex); IWriteableBrowsingExistingBlockNodeIndex BrowsingExistingBlockIndex = (IWriteableBrowsingExistingBlockNodeIndex)BrowsingNewBlockIndex.ToExistingBlockIndex(); IWriteableBlockState BlockState = (IWriteableBlockState)CreateBlockState(BrowsingNewBlockIndex, NewBlock); InsertInBlockStateList(BlockIndex, BlockState); IWriteablePlaceholderNodeState ChildState = (IWriteablePlaceholderNodeState)CreateNodeState(BrowsingExistingBlockIndex); BlockState.Insert(BrowsingExistingBlockIndex, 0, ChildState); operation.Update(BrowsingExistingBlockIndex, BlockState, ChildState); while (++BlockIndex < BlockStateList.Count) { IWriteableBlockState NextBlockState = BlockStateList[BlockIndex]; foreach (IWriteablePlaceholderNodeState State in NextBlockState.StateList) { IWriteableBrowsingExistingBlockNodeIndex NodeIndex = State.ParentIndex as IWriteableBrowsingExistingBlockNodeIndex; Debug.Assert(NodeIndex != null); Debug.Assert(NodeIndex.BlockIndex == BlockIndex - 1); NodeIndex.MoveBlockUp(); } } }
/// <summary> /// Creates a clone of the block and assigns it in the provided parent. /// </summary> /// <param name="parentNode">The node that will contains a reference to the cloned block upon return.</param> /// <param name="blockIndex">Position where to insert the block in <paramref name="parentNode"/>.</param> public virtual void CloneBlock(Node parentNode, int blockIndex) { Pattern PatternClone = ClonePattern(); Debug.Assert(PatternClone != null); Identifier SourceClone = CloneSource(); Debug.Assert(SourceClone != null); IBlock NewBlock = NodeTreeHelperBlockList.CreateBlock(parentNode, ParentInner.PropertyName, ChildBlock.Replication, PatternClone, SourceClone); NodeTreeHelperBlockList.InsertIntoBlockList(parentNode, ParentInner.PropertyName, blockIndex, NewBlock); NodeTreeHelper.CopyDocumentation(ChildBlock, NewBlock, cloneCommentGuid: true); // Clone children recursively. CloneChildren(parentNode, NewBlock); }