Example #1
0
        public bool DoUndo()
        {
            if (undoActions.Count == 0)
            {
                return(false);
            }

            //remove from undo list
            Action action = undoActions[undoActions.Count - 1];

            undoActions.RemoveAt(undoActions.Count - 1);

            //do undo
            action.DoUndo();
            ActionUndo?.Invoke(action);

            //add to redo list
            if (redoActions.Count + 1 >= maxLevel)
            {
                redoActions[0].Destroy();
                ActionDestroy?.Invoke(redoActions[0]);
                redoActions.RemoveAt(0);
            }
            redoActions.Add(action);

            ListOfActionsChanged?.Invoke(this, EventArgs.Empty);

            return(true);
        }