Class EditorUndoRedoManager
- Namespace
- Godot
- Assembly
- GodotSharpEditor.dll
EditorUndoRedoManager is a manager for UndoRedo objects associated with edited scenes. Each scene has its own undo history and EditorUndoRedoManager ensures that each action performed in the editor gets associated with a proper scene. For actions not related to scenes (ProjectSettings edits, external resources, etc.), a separate global history is used.
The usage is mostly the same as UndoRedo. You create and commit actions and the manager automatically decides under-the-hood what scenes it belongs to. The scene is deduced based on the first operation in an action, using the object from the operation. The rules are as follows:
- If the object is a Node, use the currently edited scene;
- If the object is a built-in resource, use the scene from its path;
- If the object is external resource or anything else, use global history.
This guessing can sometimes yield false results, so you can provide a custom context object when creating an action.
EditorUndoRedoManager is intended to be used by Godot editor plugins. You can obtain it using GetUndoRedo(). For non-editor uses or plugins that don't need to integrate with the editor's undo history, use UndoRedo instead.
The manager's API is mostly the same as in UndoRedo, so you can refer to its documentation for more examples. The main difference is that EditorUndoRedoManager uses object + method name for actions, instead of Callable.
public class EditorUndoRedoManager : GodotObject, IDisposable
- Inheritance
-
EditorUndoRedoManager
- Implements
- Inherited Members
Methods
AddDoMethod(GodotObject, StringName, params Variant[])
Register a method that will be called when the action is committed (i.e. the "do" action).
If this is the first operation, the object
will be used to deduce target undo history.
public void AddDoMethod(GodotObject @object, StringName method, params Variant[] args)
Parameters
object
GodotObjectmethod
StringNameargs
Variant[]
AddDoProperty(GodotObject, StringName, Variant)
Register a property value change for "do".
If this is the first operation, the object
will be used to deduce target undo history.
public void AddDoProperty(GodotObject @object, StringName property, Variant value)
Parameters
object
GodotObjectproperty
StringNamevalue
Variant
AddDoReference(GodotObject)
Register a reference for "do" that will be erased if the "do" history is lost. This is useful mostly for new nodes created for the "do" call. Do not use for resources.
public void AddDoReference(GodotObject @object)
Parameters
object
GodotObject
AddUndoMethod(GodotObject, StringName, params Variant[])
Register a method that will be called when the action is undone (i.e. the "undo" action).
If this is the first operation, the object
will be used to deduce target undo history.
public void AddUndoMethod(GodotObject @object, StringName method, params Variant[] args)
Parameters
object
GodotObjectmethod
StringNameargs
Variant[]
AddUndoProperty(GodotObject, StringName, Variant)
Register a property value change for "undo".
If this is the first operation, the object
will be used to deduce target undo history.
public void AddUndoProperty(GodotObject @object, StringName property, Variant value)
Parameters
object
GodotObjectproperty
StringNamevalue
Variant
AddUndoReference(GodotObject)
Register a reference for "undo" that will be erased if the "undo" history is lost. This is useful mostly for nodes removed with the "do" call (not the "undo" call!).
public void AddUndoReference(GodotObject @object)
Parameters
object
GodotObject
CommitAction(bool)
Commit the action. If execute
is true (default), all "do" methods/properties are called/set when this function is called.
public void CommitAction(bool execute = true)
Parameters
execute
bool
CreateAction(string, MergeMode, GodotObject, bool)
Create a new action. After this is called, do all your calls to AddDoMethod(GodotObject, StringName, params Variant[]), AddUndoMethod(GodotObject, StringName, params Variant[]), AddDoProperty(GodotObject, StringName, Variant), and AddUndoProperty(GodotObject, StringName, Variant), then commit the action with CommitAction(bool).
The way actions are merged is dictated by the mergeMode
argument. See UndoRedo.MergeMode for details.
If customContext
object is provided, it will be used for deducing target history (instead of using the first operation).
The way undo operation are ordered in actions is dictated by backwardUndoOps
. When backwardUndoOps
is false
undo option are ordered in the same order they were added. Which means the first operation to be added will be the first to be undone.
public void CreateAction(string name, UndoRedo.MergeMode mergeMode = MergeMode.Disable, GodotObject customContext = null, bool backwardUndoOps = false)
Parameters
name
stringmergeMode
UndoRedo.MergeModecustomContext
GodotObjectbackwardUndoOps
bool
GetHistoryUndoRedo(int)
Returns the UndoRedo object associated with the given history id
.
id
above 0
are mapped to the opened scene tabs (but it doesn't match their order). id
of 0
or lower have special meaning (see EditorUndoRedoManager.SpecialHistory).
Best used with GetObjectHistoryId(GodotObject). This method is only provided in case you need some more advanced methods of UndoRedo (but keep in mind that directly operating on the UndoRedo object might affect editor's stability).
public UndoRedo GetHistoryUndoRedo(int id)
Parameters
id
int
Returns
GetObjectHistoryId(GodotObject)
Returns the history ID deduced from the given object
. It can be used with GetHistoryUndoRedo(int).
public int GetObjectHistoryId(GodotObject @object)
Parameters
object
GodotObject
Returns
HasGodotClassMethod(in godot_string_name)
Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.
protected override bool HasGodotClassMethod(in godot_string_name method)
Parameters
method
godot_string_nameName of the method to check for.
Returns
HasGodotClassSignal(in godot_string_name)
Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.
protected override bool HasGodotClassSignal(in godot_string_name signal)
Parameters
signal
godot_string_nameName of the signal to check for.
Returns
InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)
Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.
protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)
Parameters
method
godot_string_nameName of the method to invoke.
args
NativeVariantPtrArgsArguments to use with the invoked method.
ret
godot_variantValue returned by the invoked method.
Returns
IsCommittingAction()
Returns true
if the EditorUndoRedoManager is currently committing the action, i.e. running its "do" method or property change (see CommitAction(bool)).
public bool IsCommittingAction()
Returns
Events
HistoryChanged
Emitted when the list of actions in any history has changed, either when an action is committed or a history is cleared.
public event Action HistoryChanged
Event Type
VersionChanged
Emitted when the version of any history has changed as a result of undo or redo call.
public event Action VersionChanged