/// <summary>
        /// Moves a block around in a block list.
        /// </summary>
        /// <param name="operation">Details of the operation performed.</param>
        public virtual void MoveBlock(WriteableMoveBlockOperation operation)
        {
            int BlockIndex = operation.BlockIndex;
            int Direction  = operation.Direction;

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

            int MoveIndex = BlockIndex;
            IWriteableBlockState BlockState = (IWriteableBlockState)BlockStateList[MoveIndex];

            MoveInBlockStateList(MoveIndex, Direction);
            NodeTreeHelperBlockList.MoveBlock(Owner.Node, PropertyName, MoveIndex, Direction);

            if (Direction > 0)
            {
                for (int i = MoveIndex; i < MoveIndex + Direction; i++)
                {
                    for (int j = 0; j < BlockStateList[i].StateList.Count; j++)
                    {
                        IWriteableBrowsingExistingBlockNodeIndex ChildNodeIndex = BlockStateList[i].StateList[j].ParentIndex as IWriteableBrowsingExistingBlockNodeIndex;
                        Debug.Assert(ChildNodeIndex != null);

                        ChildNodeIndex.MoveBlockDown();
                    }

                    for (int j = 0; j < BlockState.StateList.Count; j++)
                    {
                        IWriteableBrowsingExistingBlockNodeIndex ChildNodeIndex = BlockState.StateList[j].ParentIndex as IWriteableBrowsingExistingBlockNodeIndex;
                        Debug.Assert(ChildNodeIndex != null);

                        ChildNodeIndex.MoveBlockUp();
                    }
                }
            }
            else if (Direction < 0)
            {
                for (int i = MoveIndex; i > MoveIndex + Direction; i--)
                {
                    for (int j = 0; j < BlockStateList[i].StateList.Count; j++)
                    {
                        IWriteableBrowsingExistingBlockNodeIndex ChildNodeIndex = BlockStateList[i].StateList[j].ParentIndex as IWriteableBrowsingExistingBlockNodeIndex;
                        Debug.Assert(ChildNodeIndex != null);

                        ChildNodeIndex.MoveBlockUp();
                    }

                    for (int j = 0; j < BlockState.StateList.Count; j++)
                    {
                        IWriteableBrowsingExistingBlockNodeIndex ChildNodeIndex = BlockState.StateList[j].ParentIndex as IWriteableBrowsingExistingBlockNodeIndex;
                        Debug.Assert(ChildNodeIndex != null);

                        ChildNodeIndex.MoveBlockDown();
                    }
                }
            }

            operation.Update(BlockState);
        }
示例#2
0
        private protected virtual void UndoMoveBlock(IWriteableOperation operation)
        {
            WriteableMoveBlockOperation MoveBlockOperation = (WriteableMoveBlockOperation)operation;

            MoveBlockOperation = MoveBlockOperation.ToInverseMoveBlock();

            ExecuteMoveBlock(MoveBlockOperation);
        }
示例#3
0
        /// <summary>
        /// Handler called every time a block state is moved in the controller.
        /// </summary>
        /// <param name="operation">Details of the operation performed.</param>
        private protected virtual void OnBlockStateMoved(WriteableMoveBlockOperation operation)
        {
            Debug.Assert(!operation.IsNested);

            IWriteableBlockState BlockState = operation.BlockState;

            Debug.Assert(BlockState != null);
            Debug.Assert(BlockStateViewTable.ContainsKey(BlockState));
        }
示例#4
0
        /// <summary>
        /// Moves a block around in a block list.
        /// </summary>
        /// <param name="inner">The inner where the block is moved.</param>
        /// <param name="blockIndex">Index of the block to move.</param>
        /// <param name="direction">The change in position, relative to the current block position.</param>
        public virtual void MoveBlock(IWriteableBlockListInner inner, int blockIndex, int direction)
        {
            Contract.RequireNotNull(inner, out IWriteableBlockListInner Inner);

            Action <IWriteableOperation> HandlerRedo = (IWriteableOperation operation) => RedoMoveBlock(operation);
            Action <IWriteableOperation> HandlerUndo = (IWriteableOperation operation) => UndoMoveBlock(operation);
            WriteableMoveBlockOperation  Operation   = CreateMoveBlockOperation(Inner.Owner.Node, Inner.PropertyName, blockIndex, direction, HandlerRedo, HandlerUndo, isNested: false);

            Operation.Redo();
            SetLastOperation(Operation);
            CheckInvariant();
        }
示例#5
0
        private protected virtual void ExecuteMoveBlock(WriteableMoveBlockOperation operation)
        {
            Node   ParentNode   = operation.ParentNode;
            string PropertyName = operation.PropertyName;
            IWriteableBlockListInner <IWriteableBrowsingBlockNodeIndex> Inner = GetInner(ParentNode, PropertyName) as IWriteableBlockListInner <IWriteableBrowsingBlockNodeIndex>;

            IWriteableBlockState BlockState = (IWriteableBlockState)Inner.BlockStateList[operation.BlockIndex];

            Debug.Assert(BlockState != null);
            Debug.Assert(BlockState.StateList.Count > 0);

            IWriteableNodeState State = (IWriteableNodeState)BlockState.StateList[0];

            Debug.Assert(State != null);

            IWriteableBrowsingExistingBlockNodeIndex NodeIndex = State.ParentIndex as IWriteableBrowsingExistingBlockNodeIndex;

            Debug.Assert(NodeIndex != null);

            Inner.MoveBlock(operation);

            NotifyBlockStateMoved(operation);
        }
示例#6
0
        private protected virtual void RedoMoveBlock(IWriteableOperation operation)
        {
            WriteableMoveBlockOperation MoveBlockOperation = (WriteableMoveBlockOperation)operation;

            ExecuteMoveBlock(MoveBlockOperation);
        }
示例#7
0
 private protected virtual void NotifyBlockStateMoved(WriteableMoveBlockOperation operation)
 {
     BlockStateMovedHandler?.Invoke(operation);
 }