Undo the last command. Returns: Description of undone command if successful, None otherwise
(self)
| 102 | return False |
| 103 | |
| 104 | def undo(self) -> Optional[str]: |
| 105 | """ |
| 106 | Undo the last command. |
| 107 | |
| 108 | Returns: |
| 109 | Description of undone command if successful, None otherwise |
| 110 | """ |
| 111 | print(f"\n=== COMMAND HISTORY UNDO START ===") |
| 112 | print(f"DEBUG: Attempting to undo command") |
| 113 | print(f"DEBUG: Current index: {self.current_index}") |
| 114 | print(f"DEBUG: History size: {len(self.commands)}") |
| 115 | print(f"DEBUG: Can undo: {self.can_undo()}") |
| 116 | |
| 117 | if not self.can_undo(): |
| 118 | print(f"DEBUG: Cannot undo - no commands available") |
| 119 | return None |
| 120 | |
| 121 | command = self.commands[self.current_index] |
| 122 | print(f"DEBUG: Undoing command: {command.get_description()}") |
| 123 | print(f"DEBUG: Command type: {type(command).__name__}") |
| 124 | |
| 125 | try: |
| 126 | print(f"DEBUG: Calling command.undo()...") |
| 127 | result = command.undo() |
| 128 | print(f"DEBUG: Command.undo() returned: {result}") |
| 129 | |
| 130 | if result: |
| 131 | command._mark_undone() |
| 132 | self.current_index -= 1 |
| 133 | print(f"DEBUG: Command undone successfully, index now: {self.current_index}") |
| 134 | print(f"=== COMMAND HISTORY UNDO END ===\n") |
| 135 | return command.get_description() |
| 136 | else: |
| 137 | print(f"DEBUG: Command undo failed") |
| 138 | |
| 139 | except Exception as e: |
| 140 | print(f"DEBUG: ERROR - Undo failed for '{command.get_description()}': {e}") |
| 141 | import traceback |
| 142 | traceback.print_exc() |
| 143 | |
| 144 | print(f"=== COMMAND HISTORY UNDO END (FAILED) ===\n") |
| 145 | return None |
| 146 | |
| 147 | def redo(self) -> Optional[str]: |
| 148 | """ |