Class UndoStack
An undo stack maintains a stack of commands that have been applied in your application.
New commands are pushed on the stack using Push(UndoCommand). Commands can be undone and redone using Undo() and Redo().
UndoStack keeps track of the current command. This is the command which will be executed by the next call to Redo(). The index of this command is returned by index. The state of the edited object can be rolled forward or back using index. If the top-most command on the stack has already been redone, index is equal to count.
UndoStack provides *command compression*, command *macros*, and supports the concept of a *clean state*.
Inherited Members
Namespace: Unity.AppUI.Undo
Assembly: solution.dll
Syntax
public class UndoStack
Constructors
Name | Description |
---|---|
UndoStack() | Default constructor. |
Properties
Name | Description |
---|---|
this[int] | Gets the command at the given index. |
canRedo | Weather the redo stack is empty. |
canUndo | Weather the undo stack is empty. |
cleanIndex | The index of the clean state. -1 if there is no clean state. |
commands | The whole commands list. |
count | The number of commands in the stack. Macros are counted as a single command. |
index | The index of the last command in the undo stack. |
isClean | Weather the undo stack is in a clean state. The clean state is useful when the application supports saving and restoring the state of an object. |
lastCommand | The last command in the undo stack. |
memorySize | The total memory size of the undo stack. |
undoLimit | The maximum number of memory units that can be stored in the undo stack. |
Methods
Name | Description |
---|---|
BeginMacro(string) | Begins composition of a macro command with the given text description. An empty command described by the specified text is pushed on the stack. Any subsequent commands pushed on the stack will be appended to the macro command's children until EndMacro() is called.
While a macro is being composed, the stack is disabled. This means that: Here is an example of how to use macros:
This code is equivalent to:
|
Clear() | Clears the undo and redo stacks. |
EndMacro() | Ends composition of a macro command. |
Push(UndoCommand) | Pushes the given command on the undo stack. |
Redo() | Calls Redo() on the last command in the redo stack. |
ResetClean() | Sets the clean state to -1. |
SetClean() | Sets the clean state to the last command in the undo stack. |
Undo() | Calls Undo() on the last command in the undo stack. |
Events
Name | Description |
---|---|
cleanStateChanged | Emitted when the clean state changes. |
indexChanged | Emitted the current Command index changes. |