Example #1
0
        /// <summary>
        /// Expands an existing node. In the node:
        /// * All optional children are assigned if they aren't
        /// * If the node is a feature call, with no arguments, an empty argument is inserted.
        /// </summary>
        /// <param name="expandedIndex">Index of the expanded node.</param>
        /// <param name="isChanged">True upon return if the node was changed. False if the node was already expanded.</param>
        public virtual void Expand(IWriteableNodeIndex expandedIndex, out bool isChanged)
        {
            Contract.RequireNotNull(expandedIndex, out IWriteableNodeIndex ExpandedIndex);
            Debug.Assert(StateTable.ContainsKey(ExpandedIndex));
            Debug.Assert(StateTable[ExpandedIndex] is IWriteablePlaceholderNodeState);

            WriteableOperationList OperationList = CreateOperationList();

            DebugObjects.AddReference(OperationList);

            Expand(ExpandedIndex, OperationList);

            if (OperationList.Count > 0)
            {
                WriteableOperationReadOnlyList OperationReadOnlyList = OperationList.ToReadOnly();
                WriteableOperationGroup        OperationGroup        = CreateOperationGroup(OperationReadOnlyList, null);

                SetLastOperation(OperationGroup);
                CheckInvariant();

                isChanged = true;
            }
            else
            {
                isChanged = false;
            }
        }
Example #2
0
        /// <summary>
        /// Unassign the optional node.
        /// </summary>
        /// <param name="nodeIndex">Index of the optional node.</param>
        /// <param name="isChanged">True upon return if the node was changed. False if the node was already not assigned.</param>
        public virtual void Unassign(IWriteableBrowsingOptionalNodeIndex nodeIndex, out bool isChanged)
        {
            Contract.RequireNotNull(nodeIndex, out IWriteableBrowsingOptionalNodeIndex NodeIndex);
            Debug.Assert(StateTable.ContainsKey(NodeIndex));

            IWriteableOptionalNodeState State = StateTable[NodeIndex] as IWriteableOptionalNodeState;

            Debug.Assert(State != null);

            IWriteableOptionalInner <IWriteableBrowsingOptionalNodeIndex> Inner = State.ParentInner as IWriteableOptionalInner <IWriteableBrowsingOptionalNodeIndex>;

            Debug.Assert(Inner != null);

            if (Inner.IsAssigned)
            {
                Action <IWriteableOperation> HandlerRedo = (IWriteableOperation operation) => RedoUnassign(operation);
                Action <IWriteableOperation> HandlerUndo = (IWriteableOperation operation) => UndoUnassign(operation);
                WriteableAssignmentOperation Operation   = CreateAssignmentOperation(Inner.Owner.Node, Inner.PropertyName, HandlerRedo, HandlerUndo, isNested: false);

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

                isChanged = true;
            }
            else
            {
                isChanged = false;
            }
        }
Example #3
0
        public static void SetValue(string key, string value)
        {
            if (StateTable == null)
            {
                LoadPersistentState();
            }

            if (StateTable.ContainsKey(key))
            {
                if (DebugTrace)
                {
                    Debug.WriteLine($"SetValue(\"{key}\") -> {value}");
                }

                StateTable[key] = value;
            }
            else
            {
                if (DebugTrace)
                {
                    Debug.WriteLine($"[{key}, {value}] added");
                }

                StateTable.Add(key, value);
            }

            Commit();
        }
Example #4
0
        /// <summary>
        /// Reduces an existing node. Opposite of Expand.
        /// </summary>
        /// <param name="reducedIndex">Index of the reduced node.</param>
        /// <param name="isChanged">True upon return if the node was changed. False if the node was already reduced.</param>
        public virtual void Reduce(IWriteableNodeIndex reducedIndex, out bool isChanged)
        {
            Contract.RequireNotNull(reducedIndex, out IWriteableNodeIndex ReducedIndex);
            Debug.Assert(StateTable.ContainsKey(ReducedIndex));
            Debug.Assert(StateTable[ReducedIndex] is IWriteablePlaceholderNodeState);

            WriteableOperationList OperationList = CreateOperationList();

            Reduce(ReducedIndex, OperationList, isNested: false);

            if (OperationList.Count > 0)
            {
                WriteableOperationReadOnlyList OperationReadOnlyList = OperationList.ToReadOnly();
                WriteableOperationGroup        OperationGroup        = CreateOperationGroup(OperationReadOnlyList, null);

                SetLastOperation(OperationGroup);
                CheckInvariant();

                isChanged = true;
            }
            else
            {
                isChanged = false;
            }
        }
Example #5
0
        public static string GetValue(string key, string defaultValue)
        {
            if (StateTable == null)
            {
                LoadPersistentState();
            }

            string Result;

            if (StateTable.ContainsKey(key) && !string.IsNullOrEmpty(StateTable[key]))
            {
                Result = StateTable[key];
            }
            else
            {
                Result = defaultValue;
            }

            if (DebugTrace)
            {
                Debug.WriteLine($"GetValue(\"{key}\") <- {Result}");
            }

            return(Result);
        }
Example #6
0
        /// <summary>
        /// Changes the value of a comment.
        /// </summary>
        /// <param name="nodeIndex">Index of the state with the comment to change.</param>
        /// <param name="text">The new text.</param>
        /// <param name="oldCaretPosition">The old caret position.</param>
        /// <param name="newCaretPosition">The new caret position.</param>
        /// <param name="changeCaretBeforeText">True if the caret should be changed before the text, to preserve the caret invariant.</param>
        public virtual void ChangeCommentAndCaretPosition(IFocusIndex nodeIndex, string text, int oldCaretPosition, int newCaretPosition, bool changeCaretBeforeText)
        {
            Contract.RequireNotNull(nodeIndex, out IFocusIndex NodeIndex);
            Contract.RequireNotNull(text, out string Text);
            Debug.Assert(StateTable.ContainsKey(NodeIndex));

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

            Operation.Redo();
            SetLastOperation(Operation);
            CheckInvariant();
        }
Example #7
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();
        }
Example #8
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();
        }
Example #9
0
        /// <summary>
        /// Changes the value of a comment.
        /// </summary>
        /// <param name="nodeIndex">Index of the state with the comment to change.</param>
        /// <param name="text">The new text.</param>
        /// <param name="oldCaretPosition">The old caret position.</param>
        /// <param name="newCaretPosition">The new caret position.</param>
        /// <param name="changeCaretBeforeText">True if the caret should be changed before the text, to preserve the caret invariant.</param>
        public virtual void ChangeCommentAndCaretPosition(IFocusIndex nodeIndex, string text, int oldCaretPosition, int newCaretPosition, bool changeCaretBeforeText)
        {
            Debug.Assert(nodeIndex != null);
            Debug.Assert(StateTable.ContainsKey(nodeIndex));
            Debug.Assert(text != null);

            Action <IWriteableOperation> HandlerRedo = (IWriteableOperation operation) => RedoChangeComment(operation);
            Action <IWriteableOperation> HandlerUndo = (IWriteableOperation operation) => UndoChangeComment(operation);
            IFocusNodeState State = StateTable[nodeIndex];
            IFocusChangeCommentOperation Operation = CreateChangeCommentOperation(State.Node, text, oldCaretPosition, newCaretPosition, changeCaretBeforeText, HandlerRedo, HandlerUndo, isNested: false);

            Operation.Redo();
            SetLastOperation(Operation);
            CheckInvariant();
        }
Example #10
0
        private protected virtual void ExecuteRemoveBlockView(WriteableRemoveBlockViewOperation operation)
        {
            Node   ParentNode   = operation.ParentNode;
            string PropertyName = operation.PropertyName;
            IWriteableBlockListInner <IWriteableBrowsingBlockNodeIndex> Inner = GetInner(ParentNode, PropertyName) as IWriteableBlockListInner <IWriteableBrowsingBlockNodeIndex>;
            IWriteableBlockState RemovedBlockState = (IWriteableBlockState)Inner.BlockStateList[operation.BlockIndex];

            for (int Index = 0; Index < RemovedBlockState.StateList.Count; Index++)
            {
                IWriteableNodeState State = (IWriteableNodeState)RemovedBlockState.StateList[Index];

                PruneState(State);
                Stats.PlaceholderNodeCount--;
            }

            IWriteableBrowsingPatternIndex PatternIndex = RemovedBlockState.PatternIndex;
            IWriteableBrowsingSourceIndex  SourceIndex  = RemovedBlockState.SourceIndex;

            Debug.Assert(PatternIndex != null);
            Debug.Assert(StateTable.ContainsKey(PatternIndex));
            Debug.Assert(SourceIndex != null);
            Debug.Assert(StateTable.ContainsKey(SourceIndex));

            RemoveState(PatternIndex);
            Stats.PlaceholderNodeCount--;

            RemoveState(SourceIndex);
            Stats.PlaceholderNodeCount--;

            Inner.NotifyBlockStateRemoved(RemovedBlockState);

            Stats.BlockCount--;

            operation.Update(RemovedBlockState);

            NotifyBlockViewRemoved(operation);
        }
        private protected virtual void ExecuteRemoveBlock(IWriteableRemoveBlockOperation operation)
        {
            Node   ParentNode   = operation.ParentNode;
            string PropertyName = operation.PropertyName;
            IWriteableBlockListInner <IWriteableBrowsingBlockNodeIndex> Inner = GetInner(ParentNode, PropertyName) as IWriteableBlockListInner <IWriteableBrowsingBlockNodeIndex>;

            Inner.RemoveWithBlock(operation);

            IWriteableBlockState RemovedBlockState = operation.BlockState;

            Debug.Assert(RemovedBlockState != null);

            IWriteableBrowsingPatternIndex PatternIndex = RemovedBlockState.PatternIndex;
            IWriteableBrowsingSourceIndex  SourceIndex  = RemovedBlockState.SourceIndex;

            Debug.Assert(PatternIndex != null);
            Debug.Assert(StateTable.ContainsKey(PatternIndex));
            Debug.Assert(SourceIndex != null);
            Debug.Assert(StateTable.ContainsKey(SourceIndex));

            Stats.BlockCount--;

            RemoveState(PatternIndex);
            Stats.PlaceholderNodeCount--;

            RemoveState(SourceIndex);
            Stats.PlaceholderNodeCount--;

            IWriteableNodeState RemovedState = operation.RemovedState;

            Debug.Assert(RemovedState != null);

            PruneState(RemovedState);
            Stats.PlaceholderNodeCount--;

            NotifyBlockStateRemoved(operation);
        }