public void SetCurrentAsSaveState() { if (undoList.Count > 0) { lastSaveState = undoList.Last(); } }
// return reversed command for Undo. Redo is not reversed static public UndoableCommand GetReversedForUndo(UndoableCommand command) { UndoableCommand reversed = null; if (command.type == UndoableCommandType.InsertComponent) { reversed = command.Clone() as UndoableCommand; reversed.type = UndoableCommandType.DeleteComponent; } else if (command.type == UndoableCommandType.DeleteComponent) { reversed = command.Clone() as UndoableCommand; reversed.type = UndoableCommandType.InsertComponent; } else if (command.type == UndoableCommandType.ChangeComponentProperty) { reversed = UndoableCommand_Property.GetReversed(command as UndoableCommand_Property); } else if (command.type == UndoableCommandType.RoutedCommand) { reversed = UndoableCommand_Routed.GetReversed(command as UndoableCommand_Routed); } else { throw new Exception(String.Format("Command type {0} cannot be reversed", command.type)); } return(reversed); }
public UndoableCommand Redo() { if (redoList.Count == 0) { return(null); } UndoableCommand command = redoList.Last(); redoList.RemoveLast(); // when Redoing, push the command back to Undo list undoList.AddLast(command); CommandManager.InvalidateRequerySuggested(); return(command); }
public void PushCommand(UndoableCommand command) { undoList.AddLast(command); if (undoList.Count > MAX_STATES) { // if over capacity, remove old command if (lastSaveState != null && undoList.First() == lastSaveState) { lastSaveState = null; } undoList.RemoveFirst(); } // when pushing a command, the redo list always becomes empty redoList.Clear(); CommandManager.InvalidateRequerySuggested(); }