/// <summary>
        /// Replaces a node.
        /// </summary>
        /// <param name="operation">Details of the operation performed.</param>
        public virtual void Replace(IWriteableReplaceOperation operation)
        {
            int BlockIndex = operation.BlockIndex;

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

            IWriteableBlockState BlockState = (IWriteableBlockState)BlockStateList[BlockIndex];

            int Index = operation.Index;

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

            IBlock ChildBlock = BlockState.ChildBlock;
            Node   ParentNode = Owner.Node;

            IWriteableNodeState OldChildState = (IWriteableNodeState)BlockState.StateList[Index];
            Node OldNode = OldChildState.Node;
            IWriteableBrowsingBlockNodeIndex OldBrowsingIndex = (IWriteableBrowsingBlockNodeIndex)OldChildState.ParentIndex;

            BlockState.Remove(OldBrowsingIndex, Index);

            NodeTreeHelperBlockList.ReplaceInBlock(ChildBlock, Index, operation.NewNode);

            IWriteableBrowsingExistingBlockNodeIndex NewBrowsingIndex = CreateBrowsingNodeIndex(operation.NewNode, BlockIndex, Index);
            IWriteablePlaceholderNodeState           NewChildState    = (IWriteablePlaceholderNodeState)CreateNodeState(NewBrowsingIndex);

            BlockState.Insert(NewBrowsingIndex, Index, NewChildState);

            operation.Update(OldBrowsingIndex, NewBrowsingIndex, OldNode, NewChildState);
        }
        /// <summary>
        /// Removes a node from a block.
        /// </summary>
        /// <param name="nodeIndex">Index of the node to remove.</param>
        /// <param name="index">Position of the removed node in the block.</param>
        public virtual void Remove(IWriteableBrowsingBlockNodeIndex nodeIndex, int index)
        {
            Debug.Assert(nodeIndex != null);
            Debug.Assert(index >= 0 && index < StateList.Count);

            RemoveState(index);
        }
        /// <summary>
        /// Inserts a new node in a block.
        /// </summary>
        /// <param name="nodeIndex">Index of the node to insert.</param>
        /// <param name="index">Position of the inserted node in the block.</param>
        /// <param name="childState">Node state.</param>
        public virtual void Insert(IWriteableBrowsingBlockNodeIndex nodeIndex, int index, IReadOnlyPlaceholderNodeState childState)
        {
            Debug.Assert(nodeIndex != null);
            Debug.Assert(index >= 0 && index <= StateList.Count);

            InsertState(index, childState);
        }
Beispiel #4
0
        /// <summary>
        /// Inserts a new node in a block list.
        /// </summary>
        /// <param name="operation">Details of the operation performed.</param>
        public virtual void Insert(IWriteableInsertNodeOperation operation)
        {
            Debug.Assert(operation != null);

            int BlockIndex = operation.BlockIndex;

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

            IWriteableBlockState BlockState = BlockStateList[BlockIndex];

            int Index = operation.Index;

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

            INode  ParentNode = Owner.Node;
            IBlock ChildBlock = BlockState.ChildBlock;
            INode  Node       = operation.Node;

            NodeTreeHelperBlockList.InsertIntoBlock(ChildBlock, Index, Node);

            IWriteableBrowsingBlockNodeIndex BrowsingBlockIndex = CreateBrowsingNodeIndex(Node, BlockIndex, Index);
            IWriteablePlaceholderNodeState   ChildState         = (IWriteablePlaceholderNodeState)CreateNodeState(BrowsingBlockIndex);

            BlockState.Insert(BrowsingBlockIndex, Index, ChildState);

            operation.Update(BrowsingBlockIndex, ChildState);

            while (++Index < BlockState.StateList.Count)
            {
                IWriteablePlaceholderNodeState State = BlockState.StateList[Index];

                IWriteableBrowsingExistingBlockNodeIndex NodeIndex = State.ParentIndex as IWriteableBrowsingExistingBlockNodeIndex;
                Debug.Assert(NodeIndex != null);
                Debug.Assert(NodeIndex.BlockIndex == BrowsingBlockIndex.BlockIndex);
                Debug.Assert(NodeIndex.Index == Index - 1);

                NodeIndex.MoveUp();
            }
        }
 void IList <IWriteableBrowsingBlockNodeIndex> .Insert(int index, IWriteableBrowsingBlockNodeIndex item)
 {
     Insert(index, (IFocusBrowsingBlockNodeIndex)item);
 }
 int IList <IWriteableBrowsingBlockNodeIndex> .IndexOf(IWriteableBrowsingBlockNodeIndex value)
 {
     return(IndexOf((IFocusBrowsingBlockNodeIndex)value));
 }
 bool ICollection <IWriteableBrowsingBlockNodeIndex> .Remove(IWriteableBrowsingBlockNodeIndex item)
 {
     return(Remove((IFocusBrowsingBlockNodeIndex)item));
 }
 bool ICollection <IWriteableBrowsingBlockNodeIndex> .Contains(IWriteableBrowsingBlockNodeIndex value)
 {
     return(Contains((IFocusBrowsingBlockNodeIndex)value));
 }
 void ICollection <IWriteableBrowsingBlockNodeIndex> .Add(IWriteableBrowsingBlockNodeIndex item)
 {
     Add((IFocusBrowsingBlockNodeIndex)item);
 }