
178 Chapter 7: Creating an Operation
Creating a New Generalized Operation iTool Developer’s Guide
Creating an UndoOperation Method
The operation class UndoOperation method is called when the user undoes the
operation by selecting “Undo” from a menu or toolbar.
Example UndoOperation Method
The following example code shows a very simple UndoOperation method for the
ExampleOp operation:
FUNCTION ExampleOp::UndoOperation, oCommandSet
; Retrieve the IDLitCommand objects stored in the
; command set object.
oCmds = oCommandSet->Get(/ALL, COUNT = nObjs)
; Get a reference to the iTool object.
oTool = self->GetTool()
; Loop through the IDLitCommand objects and restore the
; original values.
FOR i = 0, nObjs-1 DO BEGIN
oCmds[i]->GetProperty, TARGET_IDENTIFIER = idTarget
oTarget = oTool->GetByIdentifier(idTarget)
; Get the old value
IF (oCmds[i]->GetItem('OLD_STYLE', styleIndex) EQ 1) THEN $
oTarget->SetProperty, STYLE = styleIndex
ENDFOR
RETURN, 1
END
Discussion
The UndoOperation method does the following things:
1. Retrieves an array of IDLitCommand objects from the supplied
IDLitCommandSet object
2. Gets a reference to the iTool object.
3. For each command object, retrieve the identifier string for the target object.
Use the identifier string to retrieve a reference to the target object itself.
4. Retrieve the OLD_STYLE item from the command object and use its value to
set the STYLE property on the target object.