Example #1
0
        private void ProduceHistoryNodes(List <ITransition> transitions)
        {
            var newNode = new HistoryTreeNode
            {
                Label       = GetLabelForNode(transitions),
                Parent      = _currentNode,
                Transitions = transitions
            };

            _currentNode.Children.Add(newNode);
            _currentNode = newNode;
        }
Example #2
0
        public void Init()
        {
            if (_initialized)
            {
                throw new InvalidOperationException("Already initialized.");
            }

            CreateNewCurrentTransaction();

            _rootNode = new HistoryTreeNode {
                Label = "Initial state"
            };
            _currentNode = _rootNode;

            _initialized = true;
        }
Example #3
0
        public void Redo(int historyIndex)
        {
            if (!CanRedo())
            {
                throw new InvalidOperationException("Cannot redo!");
            }

            var curTran = _currentTransaction;

            _currentTransaction = null;             // no transaction at moment of redo
            DestroyTransaction(curTran);

            var nextNode = _currentNode.Children[historyIndex];

            foreach (var oneTransition in nextNode.Transitions)
            {
                oneTransition.ExecuteForward();
            }

            _currentNode = nextNode;

            CreateNewCurrentTransaction();
        }
Example #4
0
        public void Undo()
        {
            if (!CanUndo())
            {
                throw new InvalidOperationException("Cannot undo!");
            }

            var curTran = _currentTransaction;

            _currentTransaction = null;             // no transaction at moment of undo
            DestroyTransaction(curTran);

            var transitions = _currentNode.Transitions;

            for (int i = transitions.Count - 1; i >= 0; i--)
            {
                var oneTransition = transitions[i];
                oneTransition.ExecuteBackward();
            }

            _currentNode = _currentNode.Parent;

            CreateNewCurrentTransaction();
        }