In this topic
- About working with the operation stack
- Adding edit and sketch operations to the operation stack
- Using the operation stack
About working with the operation stack
Edit sessions managed by the EngineEditor that require undo or 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 to the operation stack
Do the following to add edit and sketch operations to the operation stack:
- Add a ToolbarControl to the application and buddy it with a MapControl. The ToolbarControl can be hidden by setting the Visible property to false.
- Instantiate the ControlsOperationStack class and associate it with the ToolbarControl.
Add the following code example to the Form_Load event:
[C#] IOperationStack operationStack=new ControlsOperationStackClass();
axToolbarControl1.OperationStack=operationStack;
axToolbarControl2.OperationStack=operationStack;
[VB.NET] Dim operationStack As IOperationStack=New ControlsOperationStack()
axToolbarControl1.OperationStack=operationStack
axToolbarControl2.OperationStack=operationStack
Step 2 can be omitted for applications containing one MapControl and one ToolbarControl. Perform step 2 for applications containing a single MapControl buddied with multiple ToolbarControls to ensure that operations are added to a single operation stack.
- Link the EngineEditor to the ToolbarControl so 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 in the Form_Load event. See the following code example:
object tbr=(object)axToolbarControl1.Object;
IExtension engineEditorExt=m_engineEditor as IExtension;
engineEditorExt.Startup(ref tbr);
[VB.NET] Dim tbr As Object=axToolbarControl1.Object
Dim engineEditorExt As IExtension=m_engineEditor
engineEditorExt.Startup(tbr)
If the application contains multiple ToobarControls buddied to different MapControls, re-execute IExtension.Startup each time editing switches to a different MapControl to ensure the appropriate ToolbarControl is passed in.
- Start an edit session and enable undo and redo capabilities by setting 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. In an edit session, all operations on the operation stack are removed if IEngineEditor.EnableUndoRedo is set to false.
Using the operation stack
Edit operations are added to the operation stack when IEngineEditor.StopOperation is called, and sketch operations are added when IEngineSketchOperation.Finish is called. For more information, see How to create an edit session and How to create a sketch operation.
See the following code example to sequentially undo or redo operations on the operation stack:
[C#] IOperationStack operationStack=m_ToolbarControl.OperationStack;
//Do the following to undo the previous operation on the stack.
operationStack.Undo();
//Do the following to redo the next operation on the stack.
operationStack.Redo();
[VB.NET] Dim operationStack As IOperationStack=m_ToolbarControl.OperationStack
'Do the following to undo the previous operation on the stack.
operationStack.Undo()
'Do the following to redo the next operation on the stack.
operationStack.Redo()
The Undo and Redo methods do not remove operations from the operation stack, but rather move an internal pointer up and down the stack.
Individual operations can be accessed using IOperationStack.Item and performed using IOperationStack.Do, IOperationStack.UndoOperation, or IOperationStack.RedoOperation; however, this is not recommended for edit and sketch operations.
See Also:
How to create an edit sessionHow to create a sketch operation
How to listen to edit events
To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):
- ESRI.ArcGIS.Controls
- ESRI.ArcGIS.SystemUI
- ESRI.ArcGIS.System (ESRI.ArcGIS.esriSystem)
Development licensing | Deployment licensing |
---|---|
Engine Developer Kit | Engine |
ArcGIS for Desktop Basic | |
ArcGIS for Desktop Standard | |
ArcGIS for Desktop Advanced |