Log an action. The `action` must be an all-uppercase string identifying it. Arguments must also be strings. This method should be called once the action has been completed. This method can only be called when the Undo/Redo mechanism has been enabled. Other
(self, action: str, *args)
| 2566 | return self._curmark |
| 2567 | |
| 2568 | def _log(self, action: str, *args) -> None: |
| 2569 | """Log an action. |
| 2570 | |
| 2571 | The `action` must be an all-uppercase string identifying it. |
| 2572 | Arguments must also be strings. |
| 2573 | |
| 2574 | This method should be called once the action has been completed. |
| 2575 | |
| 2576 | This method can only be called when the Undo/Redo mechanism has |
| 2577 | been enabled. Otherwise, an `UndoRedoError` is raised. |
| 2578 | |
| 2579 | """ |
| 2580 | assert self.is_undo_enabled() |
| 2581 | |
| 2582 | maxundo = self.params["MAX_UNDO_PATH_LENGTH"] |
| 2583 | # Check whether we are at the end of the action log or not |
| 2584 | if self._curaction != self._actionlog.nrows - 1: |
| 2585 | # We are not, so delete the trailing actions |
| 2586 | self._actionlog.remove_rows( |
| 2587 | self._curaction + 1, self._actionlog.nrows |
| 2588 | ) |
| 2589 | # Reset the current marker group |
| 2590 | mnode = self.get_node( |
| 2591 | _mark_path % (self._curtransaction, self._curmark) |
| 2592 | ) |
| 2593 | mnode._g_reset() |
| 2594 | # Delete the marker groups with backup objects |
| 2595 | for mark in range(self._curmark + 1, self._nmarks): |
| 2596 | mnode = self.get_node( |
| 2597 | _mark_path % (self._curtransaction, mark) |
| 2598 | ) |
| 2599 | mnode._g_remove(recursive=1) |
| 2600 | # Update the new number of marks |
| 2601 | self._nmarks = self._curmark + 1 |
| 2602 | self._seqmarkers = self._seqmarkers[: self._nmarks] |
| 2603 | |
| 2604 | if action not in _op_to_code: # INTERNAL |
| 2605 | raise UndoRedoError( |
| 2606 | "Action ``%s`` not in ``_op_to_code`` " |
| 2607 | "dictionary: %r" % (action, _op_to_code) |
| 2608 | ) |
| 2609 | |
| 2610 | arg1 = "" |
| 2611 | arg2 = "" |
| 2612 | if len(args) <= 1: |
| 2613 | arg1 = args[0] |
| 2614 | elif len(args) <= 2: |
| 2615 | arg1 = args[0] |
| 2616 | arg2 = args[1] |
| 2617 | else: # INTERNAL |
| 2618 | raise UndoRedoError( |
| 2619 | "Too many parameters for action log: " "%r" |
| 2620 | ).with_traceback(args) |
| 2621 | if len(arg1) > maxundo or len(arg2) > maxundo: # INTERNAL |
| 2622 | raise UndoRedoError( |
| 2623 | "Parameter arg1 or arg2 is too long: " |
| 2624 | "(%r, %r)" % (arg1, arg2) |
| 2625 | ) |
no test coverage detected