Пример #1
0
        /// <summary>
        /// Update the operation with details.
        /// </summary>
        /// <param name="state">State changed.</param>
        /// <param name="oldValue">The old value.</param>
        public virtual void Update(IWriteableNodeState state, int oldValue)
        {
            Contract.RequireNotNull(state, out IWriteableNodeState State);

            this.State = State;
            OldValue   = oldValue;
        }
Пример #2
0
        bool IDictionary <IWriteableNodeState, IWriteableNodeStateView> .TryGetValue(IWriteableNodeState key, out IWriteableNodeStateView value)
        {
            bool Result = TryGetValue((IFocusNodeState)key, out IFocusNodeStateView Value);

            value = Value;
            return(Result);
        }
Пример #3
0
        /// <summary>
        /// Update the operation with details.
        /// </summary>
        /// <param name="state">State changed.</param>
        /// <param name="oldValue">The old value.</param>
        public virtual void Update(IWriteableNodeState state, int oldValue)
        {
            Debug.Assert(state != null);

            State    = state;
            OldValue = oldValue;
        }
Пример #4
0
        private protected virtual void PruneStateChildren(IWriteableNodeState state)
        {
            foreach (string Key in state.InnerTable.Keys)
            {
                IWriteableInner Value     = (IWriteableInner)state.InnerTable[Key];
                bool            IsHandled = false;

                if (Value is IWriteablePlaceholderInner <IWriteableBrowsingPlaceholderNodeIndex> AsPlaceholderInner)
                {
                    PrunePlaceholderInner(AsPlaceholderInner);
                    IsHandled = true;
                }
                else if (Value is IWriteableOptionalInner <IWriteableBrowsingOptionalNodeIndex> AsOptionalInner)
                {
                    PruneOptionalInner(AsOptionalInner);
                    IsHandled = true;
                }
                else if (Value is IWriteableListInner <IWriteableBrowsingListNodeIndex> AsListInner)
                {
                    PruneListInner(AsListInner);
                    IsHandled = true;
                }
                else if (Value is IWriteableBlockListInner <IWriteableBrowsingBlockNodeIndex> AsBlockListInner)
                {
                    PruneBlockListInner(AsBlockListInner);
                    IsHandled = true;
                }

                Debug.Assert(IsHandled);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="WriteableBrowseContext"/> class.
 /// </summary>
 /// <param name="state">The state that will be browsed.</param>
 public WriteableBrowseContext(IWriteableNodeState state)
     : base(state)
 {
     Debug.Assert(State == state);
     Debug.Assert(IndexCollectionList != null);
     Debug.Assert(IndexCollectionList.Count == 0);
 }
Пример #6
0
        /// <summary>
        /// Replaces a node.
        /// </summary>
        /// <param name="operation">Details of the operation performed.</param>
        public virtual void Replace(IWriteableReplaceOperation operation)
        {
            Debug.Assert(operation != null);

            int Index = operation.Index;

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

            INode ParentNode = Owner.Node;

            IWriteableNodeState OldChildState = StateList[Index];
            INode OldNode = OldChildState.Node;
            IWriteableBrowsingListNodeIndex OldBrowsingIndex = (IWriteableBrowsingListNodeIndex)OldChildState.ParentIndex;

            RemoveFromStateList(Index);

            NodeTreeHelperList.ReplaceNode(ParentNode, PropertyName, Index, operation.NewNode);

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

            InsertInStateList(Index, NewChildState);

            operation.Update(OldBrowsingIndex, NewBrowsingIndex, OldNode, NewChildState);
        }
        /// <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);
        }
Пример #8
0
        /// <summary>
        /// Replace an existing node with a new one.
        /// </summary>
        /// <param name="inner">The inner where the node is replaced.</param>
        /// <param name="replaceIndex">Index for the replace operation.</param>
        /// <param name="nodeIndex">Index of the replacing node upon return.</param>
        public void Replace(IWriteableInner inner, IWriteableInsertionChildIndex replaceIndex, out IWriteableBrowsingChildIndex nodeIndex)
        {
            Contract.RequireNotNull(inner, out IWriteableInner Inner);
            Contract.RequireNotNull(replaceIndex, out IWriteableInsertionChildIndex ReplaceIndex);
            IWriteableNodeState Owner       = Inner.Owner;
            IWriteableIndex     ParentIndex = Owner.ParentIndex;

            Debug.Assert(Contains(ParentIndex));
            Debug.Assert(IndexToState(ParentIndex) == Owner);
            WriteableInnerReadOnlyDictionary <string> InnerTable = Owner.InnerTable;

            Debug.Assert(InnerTable.ContainsKey(Inner.PropertyName));
            Debug.Assert(InnerTable[Inner.PropertyName] == Inner);

            IndexToPositionAndNode(ReplaceIndex, out int BlockIndex, out int Index, out bool ClearNode, out Node NewNode);

            Action <IWriteableOperation> HandlerRedo = (IWriteableOperation operation) => RedoReplace(operation);
            Action <IWriteableOperation> HandlerUndo = (IWriteableOperation operation) => UndoReplace(operation);
            IWriteableReplaceOperation   Operation   = CreateReplaceOperation(Inner.Owner.Node, Inner.PropertyName, BlockIndex, Index, ClearNode, NewNode, HandlerRedo, HandlerUndo, isNested: false);

            Operation.Redo();
            SetLastOperation(Operation);
            CheckInvariant();

            nodeIndex = Operation.NewBrowsingIndex;
        }
Пример #9
0
        /// <summary>
        /// Handler called every time a comment is changed in the controller.
        /// </summary>
        /// <param name="operation">Details of the operation performed.</param>
        private protected virtual void OnCommentChanged(WriteableChangeCommentOperation operation)
        {
            IWriteableNodeState State = operation.State;

            Debug.Assert(State != null);
            Debug.Assert(StateViewTable.ContainsKey(State));
        }
Пример #10
0
        /// <summary>
        /// Reduces the block list.
        /// </summary>
        private protected virtual void ReduceBlockList(IWriteableBlockListInner <IWriteableBrowsingBlockNodeIndex> blockListInner, WriteableOperationList operationList, bool isNested)
        {
            if (!blockListInner.IsSingle)
            {
                return;
            }

            if (NodeHelper.IsCollectionNeverEmpty(blockListInner.Owner.Node, blockListInner.PropertyName))
            {
                return;
            }

            if (!NodeHelper.IsCollectionWithExpand(blockListInner.Owner.Node, blockListInner.PropertyName))
            {
                return;
            }

            Debug.Assert(blockListInner.BlockStateList.Count == 1);
            Debug.Assert(blockListInner.BlockStateList[0].StateList.Count == 1);
            IWriteableNodeState FirstState = (IWriteableNodeState)blockListInner.BlockStateList[0].StateList[0];

            if (!NodeHelper.IsDefaultNode(FirstState.Node))
            {
                return;
            }

            Action <IWriteableOperation>   HandlerRedo = (IWriteableOperation operation) => RedoRemoveBlock(operation);
            Action <IWriteableOperation>   HandlerUndo = (IWriteableOperation operation) => UndoRemoveBlock(operation);
            IWriteableRemoveBlockOperation Operation   = CreateRemoveBlockOperation(blockListInner.Owner.Node, blockListInner.PropertyName, 0, HandlerRedo, HandlerUndo, isNested);

            Operation.Redo();

            operationList.Add(Operation);
        }
Пример #11
0
        /// <summary>
        /// Update the operation with details.
        /// </summary>
        /// <param name="state">State changed.</param>
        /// <param name="oldText">The old comment.</param>
        public virtual void Update(IWriteableNodeState state, string oldText)
        {
            Contract.RequireNotNull(state, out IWriteableNodeState State);

            this.State = State;
            OldText    = oldText;
        }
Пример #12
0
        /// <summary>
        /// Inserts a new node in a list or block list.
        /// </summary>
        /// <param name="inner">The inner for the list or block list where the node is inserted.</param>
        /// <param name="insertedIndex">Index for the insertion operation.</param>
        /// <param name="nodeIndex">Index of the inserted node upon return.</param>
        public virtual void Insert(IWriteableCollectionInner inner, IWriteableInsertionCollectionNodeIndex insertedIndex, out IWriteableBrowsingCollectionNodeIndex nodeIndex)
        {
            Contract.RequireNotNull(inner, out IWriteableCollectionInner Inner);
            Contract.RequireNotNull(insertedIndex, out IWriteableInsertionCollectionNodeIndex InsertedIndex);
            IWriteableNodeState Owner       = Inner.Owner;
            IWriteableIndex     ParentIndex = Owner.ParentIndex;

            Debug.Assert(Contains(ParentIndex));
            Debug.Assert(IndexToState(ParentIndex) == Owner);
            WriteableInnerReadOnlyDictionary <string> InnerTable = Owner.InnerTable;

            Debug.Assert(InnerTable.ContainsKey(Inner.PropertyName));
            Debug.Assert(InnerTable[Inner.PropertyName] == Inner);

            bool IsHandled = false;

            nodeIndex = null;

            if (Inner is IWriteableBlockListInner <IWriteableBrowsingBlockNodeIndex> AsBlockListInner && InsertedIndex is IWriteableInsertionNewBlockNodeIndex AsNewBlockIndex)
            {
                InsertNewBlock(AsBlockListInner, AsNewBlockIndex, out nodeIndex);
                IsHandled = true;
            }
            else if (Inner is IWriteableCollectionInner <IWriteableBrowsingCollectionNodeIndex> AsCollectionInner && InsertedIndex is IWriteableInsertionCollectionNodeIndex AsCollectionIndex)
            {
                InsertNewNode(AsCollectionInner, AsCollectionIndex, out nodeIndex);
                IsHandled = true;
            }

            Debug.Assert(IsHandled);
        }
        /// <summary>
        /// Update the operation with details.
        /// </summary>
        /// <param name="state">State changed.</param>
        /// <param name="oldText">The old comment.</param>
        public virtual void Update(IWriteableNodeState state, string oldText)
        {
            Debug.Assert(state != null);

            State   = state;
            OldText = oldText;
        }
Пример #14
0
        /// <summary>
        /// Handler called to refresh views.
        /// </summary>
        /// <param name="operation">Details of the operation performed.</param>
        private protected virtual void OnGenericRefresh(WriteableGenericRefreshOperation operation)
        {
            Debug.Assert(!operation.IsNested);

            IWriteableNodeState RefreshState = operation.RefreshState;

            Debug.Assert(RefreshState != null);
            Debug.Assert(StateViewTable.ContainsKey(RefreshState));
        }
        /// <summary>
        /// Handler called every time a string is changed in the controller.
        /// </summary>
        /// <param name="operation">Details of the operation performed.</param>
        private protected virtual void OnTextChanged(IWriteableChangeTextOperation operation)
        {
            Debug.Assert(operation != null);

            IWriteableNodeState State = operation.State;

            Debug.Assert(State != null);
            Debug.Assert(StateViewTable.ContainsKey(State));
        }
Пример #16
0
        /// <summary>
        /// Update the operation with details.
        /// </summary>
        /// <param name="blockState">Block state removed.</param>
        /// <param name="removedState">The state removed.</param>
        public virtual void Update(IWriteableBlockState blockState, IWriteableNodeState removedState)
        {
            Debug.Assert(blockState != null);
            Debug.Assert(blockState.StateList.Count == 0);

            BlockState   = blockState;
            Block        = blockState.ChildBlock;
            RemovedState = removedState;
            Node         = removedState.Node;
        }
Пример #17
0
        private protected virtual void Canonicalize(IWriteableNodeState state, WriteableOperationList operationList)
        {
            IWriteableNodeIndex NodeIndex = state.ParentIndex as IWriteableNodeIndex;

            Debug.Assert(NodeIndex != null);

            CanonicalizeChildren(state, operationList);

            Reduce(NodeIndex, operationList, isNested: state != RootState);
        }
        /// <summary>
        /// Update the operation with details.
        /// </summary>
        /// <param name="blockState">Block state removed.</param>
        /// <param name="removedState">The state removed.</param>
        public virtual void Update(IWriteableBlockState blockState, IWriteableNodeState removedState)
        {
            Contract.RequireNotNull(blockState, out IWriteableBlockState BlockState);
            Debug.Assert(BlockState.StateList.Count == 0);

            this.BlockState = BlockState;
            Block           = BlockState.ChildBlock;
            RemovedState    = removedState;
            Node            = removedState.Node;
        }
        /// <summary>
        /// Split an identifier with replace and insert indexes.
        /// </summary>
        /// <param name="inner">The inner where the node is replaced.</param>
        /// <param name="replaceIndex">Index for the replace operation.</param>
        /// <param name="insertIndex">Index for the insert operation.</param>
        /// <param name="firstIndex">Index of the replacing node upon return.</param>
        /// <param name="secondIndex">Index of the inserted node upon return.</param>
        public virtual void SplitIdentifier(IWriteableListInner inner, IWriteableInsertionListNodeIndex replaceIndex, IWriteableInsertionListNodeIndex insertIndex, out IWriteableBrowsingListNodeIndex firstIndex, out IWriteableBrowsingListNodeIndex secondIndex)
        {
            Contract.RequireNotNull(inner, out IWriteableListInner Inner);
            Contract.RequireNotNull(replaceIndex, out IWriteableInsertionListNodeIndex ReplaceIndex);
            Contract.RequireNotNull(insertIndex, out IWriteableInsertionListNodeIndex InsertIndex);
            IWriteableNodeState Owner       = Inner.Owner;
            IWriteableIndex     ParentIndex = Owner.ParentIndex;

            Debug.Assert(Contains(ParentIndex));
            Debug.Assert(IndexToState(ParentIndex) == Owner);
            WriteableInnerReadOnlyDictionary <string> InnerTable = Owner.InnerTable;

            Debug.Assert(InnerTable.ContainsKey(Inner.PropertyName));
            Debug.Assert(InnerTable[Inner.PropertyName] == Inner);

            int Index = ReplaceIndex.Index;

            Debug.Assert(InsertIndex.Index == Index + 1);
            Node ReplacingNode = ReplaceIndex.Node;
            Node InsertedNode  = InsertIndex.Node;

            Action <IWriteableOperation> HandlerRedoReplace = (IWriteableOperation operation) => RedoReplace(operation);
            Action <IWriteableOperation> HandlerUndoReplace = (IWriteableOperation operation) => UndoReplace(operation);
            IWriteableReplaceOperation   ReplaceOperation   = CreateReplaceOperation(Inner.Owner.Node, Inner.PropertyName, -1, Index, clearNode: false, ReplacingNode, HandlerRedoReplace, HandlerUndoReplace, isNested: true);

            Action <IWriteableOperation> HandlerRedoInsert = (IWriteableOperation operation) => RedoInsertNewNode(operation);
            Action <IWriteableOperation> HandlerUndoInsert = (IWriteableOperation operation) => UndoInsertNewNode(operation);
            WriteableInsertNodeOperation InsertOperation   = CreateInsertNodeOperation(Inner.Owner.Node, Inner.PropertyName, -1, Index + 1, InsertedNode, HandlerRedoInsert, HandlerUndoInsert, isNested: true);

            ReplaceOperation.Redo();
            InsertOperation.Redo();

            Action <IWriteableOperation>     HandlerRedoRefresh = (IWriteableOperation operation) => RedoRefresh(operation);
            Action <IWriteableOperation>     HandlerUndoRefresh = (IWriteableOperation operation) => throw new NotImplementedException(); // Undo is not possible.
            WriteableGenericRefreshOperation RefreshOperation   = CreateGenericRefreshOperation(RootState, HandlerRedoRefresh, HandlerUndoRefresh, isNested: false);

            RefreshOperation.Redo();

            WriteableOperationList OperationList = CreateOperationList();

            OperationList.Add(ReplaceOperation);
            OperationList.Add(InsertOperation);
            WriteableOperationReadOnlyList OperationReadOnlyList = OperationList.ToReadOnly();
            WriteableOperationGroup        OperationGroup        = CreateOperationGroup(OperationReadOnlyList, RefreshOperation);

            SetLastOperation(OperationGroup);

            CheckInvariant();

            firstIndex = ReplaceOperation.NewBrowsingIndex as IWriteableBrowsingListNodeIndex;
            Debug.Assert(firstIndex != null);

            secondIndex = InsertOperation.BrowsingIndex as IWriteableBrowsingListNodeIndex;
            Debug.Assert(secondIndex != null);
        }
Пример #20
0
        /// <summary>
        /// Update the operation with details.
        /// </summary>
        /// <param name="oldBrowsingIndex">Index of the state before it's replaced.</param>
        /// <param name="newBrowsingIndex">Index of the state after it's replaced.</param>
        /// <param name="oldNode">The old node. Can be null if optional and replaced.</param>
        /// <param name="newChildState">The new state.</param>
        public virtual void Update(IWriteableBrowsingChildIndex oldBrowsingIndex, IWriteableBrowsingChildIndex newBrowsingIndex, Node oldNode, IWriteableNodeState newChildState)
        {
            Contract.RequireNotNull(oldBrowsingIndex, out IWriteableBrowsingChildIndex OldBrowsingIndex);
            Contract.RequireNotNull(newBrowsingIndex, out IWriteableBrowsingChildIndex NewBrowsingIndex);
            Contract.RequireNotNull(newChildState, out IWriteableNodeState NewChildState);

            this.OldBrowsingIndex = OldBrowsingIndex;
            this.NewBrowsingIndex = NewBrowsingIndex;
            OldNode            = oldNode;
            this.NewChildState = NewChildState;
        }
        /// <summary>
        /// Update the operation with details.
        /// </summary>
        /// <param name="oldBrowsingIndex">Index of the state before it's replaced.</param>
        /// <param name="newBrowsingIndex">Index of the state after it's replaced.</param>
        /// <param name="oldNode">The old node. Can be null if optional and replaced.</param>
        /// <param name="newChildState">The new state.</param>
        public virtual void Update(IWriteableBrowsingChildIndex oldBrowsingIndex, IWriteableBrowsingChildIndex newBrowsingIndex, INode oldNode, IWriteableNodeState newChildState)
        {
            Debug.Assert(oldBrowsingIndex != null);
            Debug.Assert(newBrowsingIndex != null);
            Debug.Assert(newChildState != null);

            OldBrowsingIndex = oldBrowsingIndex;
            NewBrowsingIndex = newBrowsingIndex;
            OldNode          = oldNode;
            NewChildState    = newChildState;
        }
Пример #22
0
        /// <summary>
        /// Handler called every time a state is inserted in the controller.
        /// </summary>
        /// <param name="operation">Details of the operation performed.</param>
        private protected virtual void OnStateInserted(WriteableInsertNodeOperation operation)
        {
            IWriteableNodeState ChildState = operation.ChildState;

            Debug.Assert(ChildState != null);
            Debug.Assert(StateViewTable.ContainsKey(ChildState));

            IWriteableBrowsingCollectionNodeIndex BrowsingIndex = operation.BrowsingIndex;

            Debug.Assert(ChildState.ParentIndex == BrowsingIndex);
        }
Пример #23
0
        private protected virtual void ReplaceState(IWriteableReplaceOperation operation, IWriteableInner <IWriteableBrowsingChildIndex> inner)
        {
            Contract.RequireNotNull(inner, out IWriteableInner <IWriteableBrowsingChildIndex> Inner);
            IWriteableNodeState Owner       = Inner.Owner;
            IWriteableIndex     ParentIndex = Owner.ParentIndex;

            Debug.Assert(Contains(ParentIndex));
            Debug.Assert(IndexToState(ParentIndex) == Owner);
            WriteableInnerReadOnlyDictionary <string> InnerTable = Owner.InnerTable;

            Debug.Assert(InnerTable.ContainsKey(Inner.PropertyName));
            Debug.Assert(InnerTable[Inner.PropertyName] == Inner);

            IWriteableOptionalInner <IWriteableBrowsingOptionalNodeIndex> AsOptionalInner = Inner as IWriteableOptionalInner <IWriteableBrowsingOptionalNodeIndex>;

            if (AsOptionalInner != null)
            {
                IWriteableNodeState OldState = AsOptionalInner.ChildState;
                PruneStateChildren(OldState);

                if (AsOptionalInner.IsAssigned)
                {
                    Stats.AssignedOptionalNodeCount--;
                }
            }

            Inner.Replace(operation);

            IWriteableBrowsingChildIndex OldBrowsingIndex = operation.OldBrowsingIndex;
            IWriteableBrowsingChildIndex NewBrowsingIndex = operation.NewBrowsingIndex;
            IWriteableNodeState          ChildState       = operation.NewChildState;

            if (AsOptionalInner != null)
            {
                if (AsOptionalInner.IsAssigned)
                {
                    Stats.AssignedOptionalNodeCount++;
                }
            }
            else
            {
                Debug.Assert(Contains(OldBrowsingIndex));
                IWriteableNodeState OldState = (IWriteableNodeState)StateTable[OldBrowsingIndex];

                PruneStateChildren(OldState);
            }

            RemoveState(OldBrowsingIndex);
            AddState(NewBrowsingIndex, ChildState);

            BuildStateTable(Inner, null, NewBrowsingIndex, ChildState);
        }
Пример #24
0
        /// <summary>
        /// Checks whether a node can be moved in a list.
        /// </summary>
        /// <param name="inner">The inner where the node is.</param>
        /// <param name="nodeIndex">Index of the node that would be moved.</param>
        /// <param name="direction">Direction of the move, relative to the current position of the item.</param>
        public virtual bool IsMoveable(IWriteableCollectionInner inner, IWriteableBrowsingCollectionNodeIndex nodeIndex, int direction)
        {
            Contract.RequireNotNull(inner, out IWriteableCollectionInner Inner);
            Contract.RequireNotNull(nodeIndex, out IWriteableBrowsingCollectionNodeIndex NodeIndex);

            IWriteableNodeState State = (IWriteableNodeState)StateTable[NodeIndex];

            Debug.Assert(State != null);

            bool Result = Inner.IsMoveable(NodeIndex, direction);

            return(Result);
        }
        private protected virtual void ExecuteRemoveNode(WriteableRemoveNodeOperation operation)
        {
            Node   ParentNode   = operation.ParentNode;
            string PropertyName = operation.PropertyName;
            IWriteableCollectionInner <IWriteableBrowsingCollectionNodeIndex> Inner = GetInner(ParentNode, PropertyName) as IWriteableCollectionInner <IWriteableBrowsingCollectionNodeIndex>;

            Inner.Remove(operation);

            IWriteableNodeState RemovedState = operation.RemovedState;

            PruneState(RemovedState);
            Stats.PlaceholderNodeCount--;

            NotifyStateRemoved(operation);
        }
Пример #26
0
        /// <summary>
        /// Changes the value of an enum or boolean.
        /// If the value exceeds allowed values, it is rounded to fit.
        /// </summary>
        /// <param name="nodeIndex">Index of the state with the enum to change.</param>
        /// <param name="propertyName">Name of the property to change.</param>
        /// <param name="value">The new value.</param>
        public virtual void ChangeDiscreteValue(IWriteableIndex nodeIndex, string propertyName, int value)
        {
            Contract.RequireNotNull(nodeIndex, out IWriteableIndex NodeIndex);
            Debug.Assert(StateTable.ContainsKey(NodeIndex));
            Debug.Assert(value >= 0);

            System.Action <IWriteableOperation> HandlerRedo = (IWriteableOperation operation) => RedoChangeDiscreteValue(operation);
            System.Action <IWriteableOperation> HandlerUndo = (IWriteableOperation operation) => UndoChangeDiscreteValue(operation);
            IWriteableNodeState State = (IWriteableNodeState)StateTable[NodeIndex];
            WriteableChangeDiscreteValueOperation Operation = CreateChangeDiscreteValueOperation(State.Node, propertyName, value, HandlerRedo, HandlerUndo, isNested: false);

            Operation.Redo();
            SetLastOperation(Operation);
            CheckInvariant();
        }
Пример #27
0
        /// <summary>
        /// Changes the value of a text.
        /// </summary>
        /// <param name="nodeIndex">Index of the state with the comment to change.</param>
        /// <param name="text">The new comment.</param>
        public virtual void ChangeComment(IWriteableIndex nodeIndex, string text)
        {
            Contract.RequireNotNull(nodeIndex, out IWriteableIndex NodeIndex);
            Debug.Assert(StateTable.ContainsKey(NodeIndex));
            Contract.RequireNotNull(text, out string Text);

            System.Action <IWriteableOperation> HandlerRedo = (IWriteableOperation operation) => RedoChangeComment(operation);
            System.Action <IWriteableOperation> HandlerUndo = (IWriteableOperation operation) => UndoChangeComment(operation);
            IWriteableNodeState             State           = (IWriteableNodeState)StateTable[NodeIndex];
            WriteableChangeCommentOperation Operation       = CreateChangeCommentOperation(State.Node, Text, HandlerRedo, HandlerUndo, isNested: false);

            Operation.Redo();
            SetLastOperation(Operation);
            CheckInvariant();
        }
Пример #28
0
        /// <summary>
        /// Handler called every time a block state is removed from the controller.
        /// </summary>
        /// <param name="operation">Details of the operation performed.</param>
        private protected virtual void OnBlockStateRemoved(IWriteableRemoveBlockOperation operation)
        {
            IWriteableBlockState BlockState = operation.BlockState;

            Debug.Assert(BlockState != null);
            Debug.Assert(!BlockStateViewTable.ContainsKey(BlockState));

            Debug.Assert(!StateViewTable.ContainsKey(BlockState.PatternState));
            Debug.Assert(!StateViewTable.ContainsKey(BlockState.SourceState));

            IWriteableNodeState RemovedState = operation.RemovedState;

            Debug.Assert(!StateViewTable.ContainsKey(RemovedState));

            Debug.Assert(BlockState.StateList.Count == 0);
        }
Пример #29
0
        /// <summary>
        /// Handler called every time a state is replaced in the controller.
        /// </summary>
        /// <param name="operation">Details of the operation performed.</param>
        private protected virtual void OnStateReplaced(IWriteableReplaceOperation operation)
        {
            IWriteableNodeState NewChildState = operation.NewChildState;

            Debug.Assert(NewChildState != null);
            Debug.Assert(StateViewTable.ContainsKey(NewChildState));

            IWriteableBrowsingChildIndex OldBrowsingIndex = operation.OldBrowsingIndex;

            Debug.Assert(OldBrowsingIndex != null);
            Debug.Assert(NewChildState.ParentIndex != OldBrowsingIndex);

            IWriteableBrowsingChildIndex NewBrowsingIndex = operation.NewBrowsingIndex;

            Debug.Assert(NewBrowsingIndex != null);
            Debug.Assert(NewChildState.ParentIndex == NewBrowsingIndex);
        }
Пример #30
0
        private protected virtual void CanonicalizeChildren(IWriteableNodeState state, WriteableOperationList operationList)
        {
            List <IWriteableNodeState> ChildStateList = new List <IWriteableNodeState>();

            foreach (string Key in state.InnerTable.Keys)
            {
                IWriteableInner Value = (IWriteableInner)state.InnerTable[Key];

                switch (Value)
                {
                case IWriteablePlaceholderInner <IWriteableBrowsingPlaceholderNodeIndex> AsPlaceholderInner:
                    ChildStateList.Add(AsPlaceholderInner.ChildState);
                    break;

                case IWriteableOptionalInner <IWriteableBrowsingOptionalNodeIndex> AsOptionalInner:
                    if (AsOptionalInner.IsAssigned)
                    {
                        CanonicalizeChildren(AsOptionalInner.ChildState, operationList);
                    }
                    break;

                case IWriteableListInner <IWriteableBrowsingListNodeIndex> AsListlInner:
                    foreach (IWriteablePlaceholderNodeState ChildState in AsListlInner.StateList)
                    {
                        ChildStateList.Add(ChildState);
                    }
                    break;

                case IWriteableBlockListInner <IWriteableBrowsingBlockNodeIndex> AsBlockListlInner:
                    foreach (IWriteableBlockState BlockState in AsBlockListlInner.BlockStateList)
                    {
                        foreach (IWriteablePlaceholderNodeState ChildState in BlockState.StateList)
                        {
                            ChildStateList.Add(ChildState);
                        }
                    }
                    break;
                }
            }

            foreach (IWriteableNodeState ChildState in ChildStateList)
            {
                Canonicalize(ChildState, operationList);
            }
        }