require(["esri/undoManager"], function(UndoManager) { /* code goes here */ });
Description
(Added at v2.2)
The UndoManager is a utility object that allows you to easily build applications with undo/redo functionality. Use the UndoManager to add operations (edits, navigation changes, graphics drawing) to the stack. The API includes a set of edit operations (
add,
delete,
update,
cut and
union), created by inheriting from the OperationBase class. You can inherit from the
OperationBase class to create custom operations that take advantage of undo/redo.
Samples
Search for
samples that use this class.
Constructors
Properties
Methods
Events
[ On Style Events | Connect Style Event ]
All On Style event listeners receive a single event object. Additionally, the event object also contains a 'target' property whose value is the object which fired the event.
Events
add | | Fires when the add method is called to add an operation is added to the stack. |
change | | Fires when the undo/redo stack changes. |
redo | | Fires when the redo method is called. |
undo | | Fires when the undo method is called. |
Old Events
onAdd() | Fires when the add method is called to add an operation is added to the stack. |
onChange() | Fires when the undo/redo stack changes. |
onRedo() | Fires when the redo method is called. |
onUndo() | Fires when the undo method is called. |
Constructor Details
Creates a new UndoManager object.
Parameters:
<Object > options |
Optional |
See options list for parameters. |
options
properties:
<Number > maxOperations |
Optional |
The maximum number of operations the UndoManager can perform. If a number less than or equal to zero is provided the number of operations is unlimited. The default value is 10. |
Sample:
require([
"esri/undoManager", ...
], function(UndoManager, ... ) {
var undoManager = new UndoManager({maxOperations:8});
...
});
Property Details
When true, there are redo operations available on the stack.
Known values: true | false
Sample:
require([
"esri/undoManager", "dijit/registry", ...
], function(UndoManager, registry, ... ) {
var undoManager = new UndoManager( ... );
if (undoManager.canRedo) {
registry.byId("redo").set("disabled", false);
} else {
registry.byId("redo").set("disabled", true);
}
...
});
When true, there are undo operations available on the stack.
Known values: true | false
Sample:
require([
"esri/undoManager", "dijit/registry", ...
], function(UndoManager, registry, ... ) {
var undoManager = new UndoManager( ... );
if (undoManager.canUndo) {
registry.byId("undo").set("disabled", false);
} else {
registry.byId("undo").set("disabled", true);
};
...
});
The number of operations stored in the history stack.
The current operation position. A position value of 0 means that no operations are available on the stack. When an undo operation is performed the position decreases by 1. When a redo occurs the position is incremented by 1.
Sample:
require([
"esri/undoManager", ...
], function(UndoManager, ... ) {
var undoManager = new UndoManager( ... );
console.log('The current position is: " + undoManager.position);
...
});
Method Details
Adds an undo operation to the stack and clears the redo stack.
Parameters:
<OperationBase > operation |
Required |
An operation to add to the stack. |
Sample:
require([
"esri/undoManager", "esri/dijit/editing/Delete", ...
], function(UndoManager, Delete, ... ) {
var undoManager = new UndoManager();
var operation = new Delete({
featureLayer: layer,
deletedGraphics: [feature]
});
undoManager.add(operation);
...
});
Destroy the operation manager. Sets the history stack to null and cleans up all references.
Get the specified operation from the stack.
Parameters:
<Number > operationId |
Required |
The operation id. |
Sample:
var lastOperation = undoManager.get(2);
Get the next redo operation from the stack
Sample:
var nextOperation = undoManager.peekRedo();
Get the next undo operation from the stack.
Sample:
var nextOperation = undoManager.peekUndo();
Moves the current position to the next redo operation and calls the operation's performRedo()
method.
Sample:
<button onclick="undoManager.redo();" data-dojo-type="dijit.form.Button">Redo</button>
Remove the specified operation from the stack.
Parameters:
<Number > operationId |
Required |
The operation id. |
Sample:
var operation = undoManager.remove(2);
Moves the current position to the next undo operation and calls the operation's performUndo
method.
Sample:
undoManager.undo();
Event Details
[ On Style Events | Connect Style Event ]
Fires when the add method is called to add an operation is added to the stack. Should be used in favor of onAdd. (Added at v3.5)
Fires when the undo/redo stack changes. Should be used in favor of onChange. (Added at v3.5)
Fires when the redo method is called. Should be used in favor of onRedo. (Added at v3.5)
Fires when the undo method is called. Should be used in favor of onUndo. (Added at v3.5)
Fires when the add method is called to add an operation is added to the stack.
Fires when the undo/redo stack changes.
Fires when the redo method is called.
Fires when the undo method is called.