How to use the undo/redo mechanism

Using the undo/redo mechanism is easy and straightforward. The following steps are required:

  1. For every combination of arguments that can be passed to an instance of your commands and for every context that your commands will be able to store into the command execution history, define a class that inherits from CONTEXT and that has attributes for all the data that this context contains. Define a creation feature make that can set all these attributes to given values. Make sure that the both make and make_empty are creation features.

  2. For every command behavior that exists in your system, create a command behavior class that inherits from either UNDOABLE_COMMAND or NON_UNDOABLE_COMMAND. Effect the deferred features and redefine the type of the features arguments and/or context to the type of the context class they expect.

  3. Create a class that inherits from either SINGLE_LEVEL_UNDO or MULTI_LEVEL_UNDO depending on which undo mode you want to use for your application.

  4. Effect the unexported feature create_behavior_table inherited from class UNDO_MECHANISM. This feature has to create an instance of every command behavior class that exists in your system and put it into the command behavior table named commands. It has to be made sure, that all the 'slots' in the command behavior table are filled with an instance of one of your command behavior classes.

  5. Write a creation feature make for your class that
    a) calls set_history_size (only for multiple undo/redo)
    b) calls undo_initialize

  6. For every command or command group (several commmands executed as a single command), create a feature that does at least the following:
    a) call begin_entry
    b) call command_instance
    c) call execute
    d) repeat step b) and c) if necessary
    e) call end_entry