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.

To determine the current undo level of the automation handle, call LAutomation::GetUndoLevel. The default value is DEF_AUTOMATION_UNDO_LEVEL [16]. To set a new undo level for the automation handle, call LAutomation::SetUndoLevel.

To determine whether the last automation operation performed can be undone or redone, use LAutomation::CanUndo and LAutomation::CanRedo respectively.

LAutomation::Undo undoes the last automation operation performed, while LAutomation::Redo redoes the last automation operation undone.

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

/* This example shows how simple it is to undo the last automation operation */ 
L_INT AutomationUndoTest (LAutomation &lauto) 
{ 
   if ( SUCCESS == lauto.IsValid () ) /* check the validity of the automation handle */ 
   { 
      L_BOOL fCanUndo ; 
      /* Query the ability of undoing */ 
      fCanUndo = lauto.CanUndo () ; 
      if ( fCanUndo ) 
      { 
         /* undo the last automation operation */ 
         lauto.Undo () ; 
      } 
      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 LAutomation::Undo undoes the whole group of operations and not just the last operation performed. This can be accomplished using the following steps:

  1. Call LAutomation::AddUndoNode to add an undo node to the automation handle.

  2. Disable the undo feature by calling LAutomation::SetUndoEnabled(FALSE).

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

  4. Re-enable the undo feature by calling LAutomation::SetUndoEnabled(TRUE).

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

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

LEADTOOLS Container and Automation C++ Class Library Help

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.