Undoing and Redoing Automation Operations

The LEADTOOLS Automation features include an Undo/Redo engine for undoing and redoing automation operations. The undo level determines the number of operations that can be undone. For each undo that is performed, a redo operation can be performed. The undo level set for an automation handle applies to every container associated with that automation handle. For example, if an automation handle has four associated containers in four different windows, each container can have a maximum of 16 operations undone sequentially.

LEADTOOLS provides a number of functions for handling the undo/redo capabilities, as follows:

The following example determines whether the last operation performed in the active automation container can be undone. If it can be undone, then L_AutUndo is called.

/* This example shows how simple it is to undo the last automation operation */ 
L_INT AutomationUndoTest(pAUTOMATIONHANDLE pAutomation) 
{ 
   if (SUCCESS == L_AutIsValid(pAutomation)) /* check the validity of the automation handle */ 
   { 
      L_BOOL fCanUndo; 
      /* Query the ability of undoing */ 
      L_AutCanUndo(pAutomation, &fCanUndo); 
      if (fCanUndo) 
      { 
         /* undo the last automation operation */ 
         L_AutUndo(pAutomation, 0); 
      } 
      return SUCCESS; 
   } 
   else 
   { 
      return FAILURE; 
   } 
} 

Generally, operations are undone one operation at a time. If the last operation performed cut several objects from a container, undoing that operation would return the objects to the container.

Occasionally, it may be best to group several operations together so that calling L_AutUndo undoes the whole group of operations and not just the last operation performed. This can be accomplished by performing the following steps:

  1. Call L_AutAddUndoNode to add an undo node to the automation handle.

  2. Disable the undo feature by calling _AutSetUndoEnabled(pAutomation, FALSE).

  3. Perform the operations to be combined into one undo.

  4. Re-enable the undo feature by calling _AutSetUndoEnabled(pAutomation, TRUE).

When L_AutUndo is called for this node, all of the combined operations will be undone.

Help Version 21.0.2021.4.7
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Container and Automation C API Help