示例#1
0
        /// <summary>
        /// Removes a node from a list or block list.
        /// </summary>
        /// <param name="operation">Details of the operation performed.</param>
        public virtual void Remove(IWriteableRemoveNodeOperation operation)
        {
            Debug.Assert(operation != null);

            int RemoveIndex = operation.Index;

            Debug.Assert(RemoveIndex >= 0 && RemoveIndex < StateList.Count);

            IWriteablePlaceholderNodeState OldChildState = StateList[RemoveIndex];

            RemoveFromStateList(RemoveIndex);

            INode ParentNode = Owner.Node;

            NodeTreeHelperList.RemoveFromList(ParentNode, PropertyName, RemoveIndex);

            while (RemoveIndex < StateList.Count)
            {
                IWriteablePlaceholderNodeState State = StateList[RemoveIndex];

                IWriteableBrowsingListNodeIndex NodeIndex = State.ParentIndex as IWriteableBrowsingListNodeIndex;
                Debug.Assert(NodeIndex != null);
                Debug.Assert(NodeIndex.Index == RemoveIndex + 1);

                NodeIndex.MoveDown();

                RemoveIndex++;
            }

            operation.Update(OldChildState);
        }
示例#2
0
        private protected virtual void Remove(IWriteableRemoveBlockOperation blockOperation, IWriteableRemoveNodeOperation nodeOperation, int blockIndex, int index)
        {
            Debug.Assert(blockIndex >= 0 && blockIndex < BlockStateList.Count);

            IWriteableBlockState BlockState = BlockStateList[blockIndex];

            Debug.Assert(index >= 0 && index < BlockState.StateList.Count);

            IBlock ChildBlock = BlockState.ChildBlock;
            INode  ParentNode = Owner.Node;
            int    i;

            IWriteablePlaceholderNodeState OldChildState = BlockState.StateList[index];
            INode RemovedNode = OldChildState.Node;

            BlockState.Remove((IWriteableBrowsingBlockNodeIndex)OldChildState.ParentIndex, index);

            NodeTreeHelperBlockList.RemoveFromBlock(ParentNode, PropertyName, blockIndex, index, out bool IsBlockRemoved);

            if (IsBlockRemoved)
            {
                Debug.Assert(blockOperation != null);

                RemoveFromBlockStateList(blockIndex);

                blockOperation.Update(BlockState, OldChildState);

                for (i = blockIndex; i < BlockStateList.Count; i++)
                {
                    IWriteableBlockState NextBlockState = BlockStateList[i];

                    foreach (IWriteablePlaceholderNodeState State in NextBlockState.StateList)
                    {
                        IWriteableBrowsingExistingBlockNodeIndex NodeIndex = State.ParentIndex as IWriteableBrowsingExistingBlockNodeIndex;
                        Debug.Assert(NodeIndex != null);
                        Debug.Assert(NodeIndex.BlockIndex == i + 1);

                        NodeIndex.MoveBlockDown();
                    }
                }
            }
            else
            {
                Debug.Assert(nodeOperation != null);

                nodeOperation.Update(OldChildState);
            }

            i = index;
            while (i < BlockState.StateList.Count)
            {
                IWriteablePlaceholderNodeState State = BlockState.StateList[i];

                IWriteableBrowsingExistingBlockNodeIndex NodeIndex = State.ParentIndex as IWriteableBrowsingExistingBlockNodeIndex;
                Debug.Assert(NodeIndex != null);
                Debug.Assert(NodeIndex.BlockIndex == blockIndex);
                Debug.Assert(NodeIndex.Index == i + 1);

                NodeIndex.MoveDown();

                i++;
            }
        }