Mark the state of the database. Creates a mark for the current state of the database. A unique (and immutable) identifier for the mark is returned. An optional name (a string) can be assigned to the mark. Both the identifier of a mark and its name can be used in :met
(self, name: str | None = None)
| 2520 | self._undoEnabled = False |
| 2521 | |
| 2522 | def mark(self, name: str | None = None) -> int: |
| 2523 | """Mark the state of the database. |
| 2524 | |
| 2525 | Creates a mark for the current state of the database. A unique (and |
| 2526 | immutable) identifier for the mark is returned. An optional name (a |
| 2527 | string) can be assigned to the mark. Both the identifier of a mark and |
| 2528 | its name can be used in :meth:`File.undo` and :meth:`File.redo` |
| 2529 | operations. When the name has already been used for another mark, |
| 2530 | an UndoRedoError is raised. |
| 2531 | |
| 2532 | This method can only be called when the Undo/Redo mechanism has been |
| 2533 | enabled. Otherwise, an UndoRedoError is raised. |
| 2534 | |
| 2535 | """ |
| 2536 | self._check_open() |
| 2537 | self._check_undo_enabled() |
| 2538 | |
| 2539 | if name is None: |
| 2540 | name = "" |
| 2541 | else: |
| 2542 | if not isinstance(name, str): |
| 2543 | raise TypeError( |
| 2544 | "Only strings are allowed as mark names. " |
| 2545 | "You passed object: '%s'" % name |
| 2546 | ) |
| 2547 | if name in self._markers: |
| 2548 | raise UndoRedoError( |
| 2549 | "Name '%s' is already used as a marker " |
| 2550 | "name. Try another one." % name |
| 2551 | ) |
| 2552 | |
| 2553 | # The file is going to be changed. |
| 2554 | self._check_writable() |
| 2555 | |
| 2556 | self._markers[name] = self._curmark + 1 |
| 2557 | |
| 2558 | # Create an explicit mark |
| 2559 | # Insert the mark in the action log |
| 2560 | self._log("MARK", str(self._curmark + 1), name) |
| 2561 | self._curmark += 1 |
| 2562 | self._nmarks = self._curmark + 1 |
| 2563 | self._seqmarkers.append(self._curaction) |
| 2564 | # Create a group for the current mark |
| 2565 | self._create_mark(self._trans, self._curmark) |
| 2566 | return self._curmark |
| 2567 | |
| 2568 | def _log(self, action: str, *args) -> None: |
| 2569 | """Log an action. |