aeidon.agents.register

Source: aeidon/agents/register.py

Managing revertable actions.

To hook a method up with the undo/redo system, the following need to be done:

  1. The last argument to the method must be a keyword argument register with a default value of -1. This argument indicates which of doing, undoing or redoing is in process.
  2. At the end of the method, register_action() needs to be called with an instance of aeidon.RevertableAction. Calling this method takes care of the management of undo and redo stacks.
  3. The method should be marked with the aeidon.deco.revertable() decorator. This decorator takes care of emitting an action signal once the method has been run, cuts the undo and redo stacks if needed and defaults the register keyword argument to aeidon.registers.DO.

Each method marked as revertable should match exactly one action in the undo and redo stacks. Hence, if a method calls other revertable methods, the resulting action needs to be grouped as one using group_actions().

If a revertable method needs to be performed without the possibility of reverting, the register keyword argument should be given a value of None. This way it will not be in any way processed by the undo/redo system.