public void Clear() { bool existsData = undoActions.Count != 0 || redoActions.Count != 0; foreach (Action action in redoActions) { action.Destroy(); ActionDestroy?.Invoke(action); } redoActions.Clear(); foreach (Action action in undoActions) { action.Destroy(); ActionDestroy?.Invoke(action); } undoActions.Clear(); if (existsData) { ListOfActionsChanged?.Invoke(this, EventArgs.Empty); } WasCleaned?.Invoke(this, EventArgs.Empty); }
public bool DoRedo() { if (redoActions.Count == 0) { return(false); } //remove from redo list Action action = redoActions[redoActions.Count - 1]; redoActions.RemoveAt(redoActions.Count - 1); //do redo action.DoRedo(); ActionRedo?.Invoke(action); //add to undo list if (undoActions.Count + 1 >= maxLevel) { undoActions[0].Destroy(); ActionDestroy?.Invoke(undoActions[0]); undoActions.RemoveAt(0); } undoActions.Add(action); ListOfActionsChanged?.Invoke(this, EventArgs.Empty); return(true); }
public void CommitAction(Action action) { foreach (Action a in redoActions) { a.Destroy(); ActionDestroy?.Invoke(a); } redoActions.Clear(); if (undoActions.Count + 1 >= maxLevel) { undoActions[0].Destroy(); ActionDestroy?.Invoke(undoActions[0]); undoActions.RemoveAt(0); } undoActions.Add(action); ListOfActionsChanged?.Invoke(this, EventArgs.Empty); }