示例#1
0
        public void Redo()
        {
            var restorePoint = _undoStack.Redo();

            restorePoint.Redo(_document);
            UndoStackChanged?.Invoke(this, EventArgs.Empty);
        }
示例#2
0
 public void Resize(int newSize)
 {
     if (newSize == _undoStack.Count)
     {
         return;
     }
     newSize = MathC.Clamp(newSize, 1, MaxUndoDepth);
     _undoStack.Resize(newSize);
     _redoStack.Resize(newSize);
     UndoStackChanged?.Invoke(this, new EventArgs());
 }
示例#3
0
        public void Push(List <UndoRedoInstance> instance)
        {
            if (!StackValid(_undoStack))
            {
                return;
            }

            _undoStack.Push(instance);
            _redoStack.Clear();
            UndoStackChanged?.Invoke(this, new EventArgs());
        }
示例#4
0
 private void Clear(UndoRedoStack stack, bool silent = false)
 {
     if (!StackValid(stack))
     {
         return;
     }
     stack.Clear();
     if (!silent)
     {
         UndoStackChanged?.Invoke(this, new EventArgs());
     }
 }
示例#5
0
        private void StoreFullNewState()
        {
            // stores the entire state of the document as a RestorePoint on the undoredo-stack
            var restorePoint = new RestorePoint();

            foreach (var layer in _document.Layers)
            {
                restorePoint.StoreNewState(layer);
            }
            _undoStack.Add(restorePoint);
            UndoStackChanged?.Invoke(this, EventArgs.Empty);
        }
示例#6
0
        private void Engage(UndoRedoStack stack)
        {
            if (!StackValid(stack))
            {
                return;
            }
            var counterStack = stack == _undoStack ? _redoStack : _undoStack;

            var instance = stack.Pop();

            if (instance == null)
            {
                return;
            }

            if (instance.All(item => item.Valid == null || item.Valid()))
            {
                // Generate and push redo instance, if exists. If not, reset redo stack, since action is irreversible.
                var redoList = instance.Where(item => item.RedoInstance != null).ToList().ConvertAll(item => item.RedoInstance());
                if (redoList.Count > 0)
                {
                    counterStack.Push(redoList);
                }
                else
                {
                    counterStack.Clear();
                }

                // Invoke original undo instance
                instance.ForEach(item => item.UndoAction?.Invoke());
            }
            else
            {
                MessageSent?.Invoke(this, new UndoManagerMessageEventArgs()
                {
                    Message = "Level state changed. " + (counterStack == _redoStack ? "Undo" : "Redo") + " action ignored."
                });
            }

            UndoStackChanged?.Invoke(this, new EventArgs());
        }
示例#7
0
 public void ClearAll()
 {
     Clear(_undoStack, true);
     Clear(_redoStack, true);
     UndoStackChanged?.Invoke(this, new EventArgs());
 }
示例#8
0
 internal void AddRestorePoint(RestorePoint restorePoint)
 {
     _undoStack.Add(restorePoint);
     UndoStackChanged?.Invoke(this, EventArgs.Empty);
 }