Enable the Undo/Redo mechanism. This operation prepares the database for undoing and redoing modifications in the node hierarchy. This allows :meth:`File.mark`, :meth:`File.undo`, :meth:`File.redo` and other methods to be called. The filters argument, when s
(self, filters: Filters = Filters(complevel=1))
| 2386 | return MarkG(trans, _mark_name % mid, "Mark number %d" % mid, new=True) |
| 2387 | |
| 2388 | def enable_undo(self, filters: Filters = Filters(complevel=1)) -> None: |
| 2389 | """Enable the Undo/Redo mechanism. |
| 2390 | |
| 2391 | This operation prepares the database for undoing and redoing |
| 2392 | modifications in the node hierarchy. This |
| 2393 | allows :meth:`File.mark`, :meth:`File.undo`, :meth:`File.redo` and |
| 2394 | other methods to be called. |
| 2395 | |
| 2396 | The filters argument, when specified, |
| 2397 | must be an instance of class Filters (see :ref:`FiltersClassDescr`) and |
| 2398 | is meant for setting the compression values for the action log. The |
| 2399 | default is having compression enabled, as the gains in terms of |
| 2400 | space can be considerable. You may want to disable compression if |
| 2401 | you want maximum speed for Undo/Redo operations. |
| 2402 | |
| 2403 | Calling this method when the Undo/Redo mechanism is already |
| 2404 | enabled raises an UndoRedoError. |
| 2405 | |
| 2406 | """ |
| 2407 | maxundo = self.params["MAX_UNDO_PATH_LENGTH"] |
| 2408 | |
| 2409 | class ActionLog(NotLoggedMixin, Table): |
| 2410 | pass |
| 2411 | |
| 2412 | class ActionLogDesc(IsDescription): |
| 2413 | opcode = UInt8Col(pos=0) |
| 2414 | arg1 = StringCol(maxundo, pos=1, dflt=b"") |
| 2415 | arg2 = StringCol(maxundo, pos=2, dflt=b"") |
| 2416 | |
| 2417 | self._check_open() |
| 2418 | |
| 2419 | # Enabling several times is not allowed to avoid the user having |
| 2420 | # the illusion that a new implicit mark has been created |
| 2421 | # when calling enable_undo for the second time. |
| 2422 | |
| 2423 | if self.is_undo_enabled(): |
| 2424 | raise UndoRedoError("Undo/Redo feature is already enabled!") |
| 2425 | |
| 2426 | self._markers: dict[str, int] = {} |
| 2427 | self._seqmarkers: list[int] = [] |
| 2428 | self._nmarks = 0 |
| 2429 | self._curtransaction = 0 |
| 2430 | self._curmark = -1 # No marks yet |
| 2431 | |
| 2432 | # Get the Group for keeping user actions |
| 2433 | try: |
| 2434 | tgroup = self.get_node(_trans_group_path) |
| 2435 | except NodeError: |
| 2436 | # The file is going to be changed. |
| 2437 | self._check_writable() |
| 2438 | |
| 2439 | # A transaction log group does not exist. Create it |
| 2440 | tgroup = self._create_transaction_group() |
| 2441 | |
| 2442 | # Create a transaction. |
| 2443 | self._trans = self._create_transaction( |
| 2444 | tgroup, self._curtransaction |
| 2445 | ) |