/// <summary>
        /// Handler called every time a block split in the controller.
        /// </summary>
        /// <param name="operation">Details of the operation performed.</param>
        private protected virtual void OnBlockSplit(IWriteableSplitBlockOperation operation)
        {
            Debug.Assert(operation != null);
            Debug.Assert(!operation.IsNested);

            IWriteableBlockState BlockState = operation.BlockState;

            Debug.Assert(BlockState != null);
            Debug.Assert(BlockStateViewTable.ContainsKey(BlockState));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Splits a block in two at the given index.
        /// </summary>
        /// <param name="operation">Details of the operation performed.</param>
        public virtual void SplitBlock(IWriteableSplitBlockOperation operation)
        {
            Debug.Assert(operation != null);

            int SplitBlockIndex = operation.BlockIndex;

            Debug.Assert(SplitBlockIndex >= 0 && SplitBlockIndex < BlockStateList.Count);

            int SplitIndex = operation.Index;

            Debug.Assert(SplitIndex > 0);

            IWriteableBlockState BlockState = 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 INode 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          = 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          = 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();
                }
            }
        }