How to work with the operation stack


Summary
The EngineEditor singleton can create edit operations in an ArcGIS Engine application. Undo and redo capabilities are available by accessing the operation stack associated with a ToolbarControl that has been linked with the EngineEditor.

In this topic


About working with the operation stack

Edit sessions managed by the EngineEditor that require undo and redo capabilities must contain a ToolbarControl. The IToolbarControl.OperationStack property provides access to the operation stack, which stores graphic, edit, and sketch operations. The IOperationStack.Undo and IOperationStack.Redo methods can then be used to sequentially undo and redo operations, respectively.

Adding edit and sketch operations

Edit and sketch operations will only be added to the operation stack after doing the following steps:
  1. Add a ToolbarControl to the application.
  2. Instantiate the ControlsOperationStack class and associate it with the ToolbarControl.
  3. Link the EngineEditor to the ToolbarControl.
  4. Start an edit session, and enable undo and redo capabilities.
  5. Add a ToolbarControl to the application.
  6. Add a ToolbarControl and buddy it with a MapControl. The ToolbarControl can be hidden by setting the Visible property to false.
  7. Instantiate the ControlsOperationStack class and associate it with the ToolbarControl.
  8. Add the following code example to the Form_Load event.
[Java]
IOperationStack operationStack = new ControlsOperationStack();
toolbarControl1.setOperationStackByRef(operationStack);
toolbarControl2.setOperationStackByRef(operationStack);
This step can be omitted for applications containing one MapControl and one ToolbarControl. Applications containing a single MapControl buddied with multiple ToolbarControls should do this step to ensure that operations will be added to a single operation stack. 
  1. Link the EngineEditor to the ToolbarControl. The EngineEditor must be linked to the ToolbarControl so that the operation stack contains edit and sketch operations. Do this by adding a command from the Feature Editing toolset to the ToolbarControl or by programmatically linking the EngineEditor to the ToolbarControl. See the following code example:
[Java]
Object tbr = toolbarControl.getObject();
IExtension engineEditorExt = engineEditor;
engineEditorExt.startup(tbr);
Care should be taken if the application contains multiple ToolbarControls buddied to different MapControls. In this situation, the IExtension.Startup method should be re-executed each time editing switches to a different MapControl, ensuring that the appropriate ToolbarControl is passed in.
  1. Start an edit session, and enable undo and redo capabilities.
  2. Start an edit session and set IEngineEditor.EnableUndoRedo to true. For more information on edit sessions, see How to create an edit session.
Attempting to call IEngineEditor.EnableUndoRedo before starting an edit session, causes an error. Within an edit session, all operations on the operation stack will be removed if IEngineEditor.EnableUndoRedo is set to false.

Using the operation stack

Edit operations will be added to the operation stack when the IEngineEditor.StopOperation method is called, and sketch operations will be added when the IEngineSketchOperation.Finish method is called. For more information, see the previously referenced topic, "How to create an edit session" and How to create a sketch operation.
Sequentially undo or redo operations on the operation stack as shown in the following code example:
[Java]
IOperationStack operationStack = toolbarControl.getOperationStack();
// To undo the previous operation on the stack.
operationStack.undo();
// To redo the next operation on the stack.
operationStack.redo();
The Undo and Redo methods do not remove operations from the operation stack, but moves an internal pointer up and down the stack.
Individual operations can be accessed using the IOperationStack.Item property and performed using the IOperationStack.Do, IOperationStack.UndoOperation, or IOperationStack.RedoOperation methods; however, this is not recommended for edit and sketch operations.


See Also:

How to create an edit session
How to create a sketch operation
How to listen to an edit event
Sample: Editing custom application




Additional Requirements
  • The code examples assume that an instance of EngineEditor has been created at the class level: IEngineEditor engineEditor = new EngineEditor();

Development licensingDeployment licensing
Engine Developer KitEngine
ArcGIS for Desktop Basic
ArcGIS for Desktop Standard
ArcGIS for Desktop Advanced