The ILcdUndoable interface provides support to reverse the effect of an action. A class that wants it effects to be reversible should provide methods to register an ILcdUndoableListener. Whenever an ILcdUndoable object is created by the class, the listener gets notified of this object and can react to it in an appropriate way. One implementation of ILcdUndoableListener is TLcdUndoManager. This class collects all ILcdUndoable objects of which it is notified and provides methods to undo and redo these undoable objects in the correct order. The following sections describe the steps for adding undo support to your application in more detail. For more information on listening to changes, refer to Notifying objects of changes with listeners.

Adding undo/redo capabilities to your application

To add undo/redo support to your application, you should first create a TLcdUndoManager. You can then add this TLcdUndoManager as a listener to the appropriate class(es). The TLcdUndoAction and TLcdRedoAction can then be used to interact with the TLcdUndoManager.

Making graphical edits undoable

TLspEditController and TLspCreateController provide undo/redo support for the editing of domain objects. However, because the actual modification of the domain objects is delegated to ILspEditor instances, the creation of the ILcdUndoable objects must be delegated to them as well. In order to let the controllers capture these ILcdUndoable objects, it needs to attach itself as a listener to the ILspEditor. That is why the ILspEditor implementation needs to implement ILcdUndoableSource as well if the changes made by the ILspEditor need to be reversible. This interface allows ILcdUndoableListener objects to be attached.

For convenience, LuciadLightspeed provides a full implementation of ILcdUndoableSource in the abstract class ALspEditor. Hence, all editors derived from this abstract class automatically provide full undo/redo support.