EditorUndoRedoManager
Manages undo history of scenes opened in the editor.
EditorUndoRedoManager.swift:38class EditorUndoRedoManager
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
.
This object emits the following signals:
Superclasses
class Object
Base class for all other classes in the engine.
Citizens in SwiftGodot
Conformances
protocol CustomStringConvertible
A type with a customized textual representation.
protocol Equatable
A type that can be compared for value equality.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol Identifiable<ID>
A class of types whose instances hold the value of an entity with stable identity.
protocol VariantRepresentable
Types that conform to VariantRepresentable can be stored directly in
Variant
with no conversion. These include all of the Variant types from Godot (for exampleGString
,Rect
,Plane
), Godot objects (those that subclass SwiftGodot.Object) as well as the built-in Swift types UInt8, Int64 and Double.protocol VariantStorable
Types that conform to VariantStorable can be stored in a Variant and can be extracted back out of a Variant.
Types
Type members
Instance members
var historyChanged: SimpleSignal
Emitted when the list of actions in any history has changed, either when an action is committed or a history is cleared.
var versionChanged: SimpleSignal
Emitted when the version of any history has changed as a result of undo or redo call.
func addDoMethod(object: Object?, method: StringName, Variant...
) Register a method that will be called when the action is committed (i.e. the “do” action).
func addDoProperty(object: Object?, property: StringName, value: Variant
) Register a property value change for “do”.
func addDoReference(object: Object?
) 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.
func addUndoMethod(object: Object?, method: StringName, Variant...
) Register a method that will be called when the action is undone (i.e. the “undo” action).
func addUndoProperty(object: Object?, property: StringName, value: Variant
) Register a property value change for “undo”.
func addUndoReference(object: Object?
) 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!).
func commitAction(execute: Bool
) Commit the action. If
execute
is true (default), all “do” methods/properties are called/set when this function is called.func createAction(name: String, mergeMode: UndoRedo.MergeMode, customContext: Object?, backwardUndoOps: Bool
) Create a new action. After this is called, do all your calls to
addDoMethod(object:method:)
,addUndoMethod(object:method:)
,addDoProperty(object:property:value:)
, andaddUndoProperty(object:property:value:)
, then commit the action withcommitAction(execute:)
.func forceFixedHistory(
) Forces the next operation (e.g.
addDoMethod(object:method:)
) to use the action’s history rather than guessing it from the object. This is sometimes needed when a history can’t be correctly determined, like for a nested resource that doesn’t have a path yet.func getHistoryUndoRedo(id: Int32
) -> UndoRedo? Returns the
UndoRedo
object associated with the given historyid
.func getObjectHistoryId(object: Object?
) -> Int32 Returns the history ID deduced from the given
object
. It can be used withgetHistoryUndoRedo(id:)
.func isCommittingAction(
) -> Bool Returns
true
if theEditorUndoRedoManager
is currently committing the action, i.e. running its “do” method or property change (seecommitAction(execute:)
).