Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        public void Undo()
        {
            _undoServiceValidator.ValidateUndo();

            var lastServiceIndex = _undoStack.Pop();

            _isInternallySettingState = true;
            try
            {
                _subUndoServices[lastServiceIndex].Undo();
            }
            catch
            {
                var resourceManager = new ResourceManager(typeof(StateManagement.Resources));
                throw new InvalidOperationException(resourceManager.GetString("SubServiceUndoFailure"));
            }
            _isInternallySettingState = false;

            _redoStack.Push(lastServiceIndex);

            //Check if the next SubUndoService has become empty. If it has, then empty all undo stacks.
            if (_undoStack.Count > 0)
            {
                var nextService = _undoStack.Peek();
                if (!_subUndoServices[nextService].CanUndo)
                {
                    ClearUndoStack();
                }
            }
        }
        /// <summary>
        ///
        /// </summary>
        public void Undo()
        {
            _undoServiceValidator.ValidateUndo();

            //If tagging is used, the part of the state that will be changed by this will be tagged in _currentState (the change there will be undone).
            var args = new StateSetEventArgs {
                Tag = _currentState.Tag, SettingAction = StateSetAction.Undo
            };

            var memento = _undoStack.Pop();

            SetState(memento.State);
            _redoStack.Push(_currentState);
            _currentState = memento;
            StateSet?.Invoke(this, args);
        }