// 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_Routed GetReversed(UndoableCommand_Routed command) { UndoableCommand_Routed reversed = command.Clone() as UndoableCommand_Routed; if (command.command == Command.SpreadsheetAddColumn) { reversed.command = Command.SpreadsheetDeleteColumn; } else if (command.command == Command.SpreadsheetDeleteColumn) { reversed.command = Command.SpreadsheetAddColumn; } else if (command.command == Command.SpreadsheetAddRow) { reversed.command = Command.SpreadsheetDeleteRow; } else if (command.command == Command.SpreadsheetDeleteRow) { reversed.command = Command.SpreadsheetAddRow; } else if (command.command == Command.MacroAddParam) { reversed.command = Command.MacroDeleteParam; } else if (command.command == Command.MacroDeleteParam) { reversed.command = Command.MacroAddParam; } else if (command.command == Command.LoopAddParam) { reversed.command = Command.LoopDeleteParam; } else if (command.command == Command.LoopDeleteParam) { reversed.command = Command.LoopAddParam; } else if (command.command == Command.CreateDatatable) { reversed.command = Command.DeleteDatatable; } else if (command.command == Command.DeleteDatatable) { reversed.command = Command.CreateDatatable; } else { throw new Exception(String.Format("Routed Command type {0} cannot be reversed", command.command)); } return(reversed); }