/// <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> /// Initializes a new instance of the <see cref="WriteableBlockState{IInner}"/> class. /// </summary> /// <param name="parentInner">Inner containing the block state.</param> /// <param name="newBlockIndex">Index that was used to create the block state.</param> /// <param name="childBlock">The block.</param> public WriteableBlockState(IWriteableBlockListInner parentInner, IWriteableBrowsingNewBlockNodeIndex newBlockIndex, IBlock childBlock) : base(parentInner, newBlockIndex, childBlock) { }
/// <summary> /// Splits a block in two at the given index. /// </summary> /// <param name="operation">Details of the operation performed.</param> public virtual void SplitBlock(WriteableSplitBlockOperation operation) { int SplitBlockIndex = operation.BlockIndex; Debug.Assert(SplitBlockIndex >= 0 && SplitBlockIndex < BlockStateList.Count); int SplitIndex = operation.Index; Debug.Assert(SplitIndex > 0); IWriteableBlockState BlockState = (IWriteableBlockState)BlockStateList[SplitBlockIndex]; Debug.Assert(SplitIndex < BlockState.StateList.Count); IBlock NewBlock = operation.NewBlock; Debug.Assert(NewBlock != null); NodeTreeHelperBlockList.SplitBlock(Owner.Node, PropertyName, SplitBlockIndex, SplitIndex, NewBlock); NodeTreeHelperBlockList.GetChildNode(NewBlock, 0, out Node NewBlockFirstNode); IWriteableBrowsingNewBlockNodeIndex NewBlockIndex = CreateNewBlockNodeIndex(NewBlockFirstNode, SplitBlockIndex); IWriteableBlockState NewBlockState = (IWriteableBlockState)CreateBlockState(NewBlockIndex, NewBlock); ((IWriteableBlockState <IWriteableInner <IWriteableBrowsingChildIndex> >)NewBlockState).InitBlockState(); InsertInBlockStateList(NewBlockIndex.BlockIndex, NewBlockState); for (int i = 0; i < SplitIndex; i++) { IWriteablePlaceholderNodeState State = (IWriteablePlaceholderNodeState)BlockState.StateList[0]; IWriteableBrowsingExistingBlockNodeIndex ChildNodeIndex = State.ParentIndex as IWriteableBrowsingExistingBlockNodeIndex; Debug.Assert(ChildNodeIndex != null); BlockState.Remove(ChildNodeIndex, 0); NewBlockState.Insert(ChildNodeIndex, i, State); } operation.Update(NewBlockState); for (int i = 0; i < BlockState.StateList.Count; i++) { IWriteablePlaceholderNodeState State = (IWriteablePlaceholderNodeState)BlockState.StateList[i]; IWriteableBrowsingExistingBlockNodeIndex ChildNodeIndex = State.ParentIndex as IWriteableBrowsingExistingBlockNodeIndex; Debug.Assert(ChildNodeIndex != null); ChildNodeIndex.MoveBlockUp(); for (int j = 0; j < SplitIndex; j++) { ChildNodeIndex.MoveDown(); } } for (int i = SplitBlockIndex + 2; i < BlockStateList.Count; i++) { foreach (IWriteablePlaceholderNodeState State in BlockStateList[i].StateList) { IWriteableBrowsingExistingBlockNodeIndex ChildNodeIndex = State.ParentIndex as IWriteableBrowsingExistingBlockNodeIndex; Debug.Assert(ChildNodeIndex != null); ChildNodeIndex.MoveBlockUp(); } } }