// 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); }
static public UndoableCommand_Property GetReversed(UndoableCommand_Property command) { UndoableCommand_Property reversed = command.Clone() as UndoableCommand_Property; reversed.newValue = command.oldValue; reversed.oldValue = command.newValue; return(reversed); }