UndoRedo

Helper to manage UndoRedo in the editor or custom tools.

It works by registering methods and property changes inside 'actions'. Common behavior is to create an action, then add do/undo calls to functions or property changes, then committing the action. Here's an example on how to add an action to Godot editor's own 'undoredo':

More...

Members

Aliases

BaseClasses
alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses)
Undocumented in source.

Enums

Constants
enum Constants
MergeMode
enum MergeMode

Functions

addDoMethod
Variant addDoMethod(GodotObject object, StringArg1 method, VarArgs varArgs)

Register a method that will be called when the action is committed.

addDoProperty
void addDoProperty(GodotObject object, StringArg1 property, VariantArg2 value)

Register a property value change for 'do'.

addDoReference
void addDoReference(GodotObject 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.

addUndoMethod
Variant addUndoMethod(GodotObject object, StringArg1 method, VarArgs varArgs)

Register a method that will be called when the action is undone.

addUndoProperty
void addUndoProperty(GodotObject object, StringArg1 property, VariantArg2 value)

Register a property value change for 'undo'.

addUndoReference
void addUndoReference(GodotObject 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!).

clearHistory
void clearHistory()

Clear the undo/redo history and associated references.

commitAction
void commitAction()

Commit the action. All 'do' methods/properties are called/set when this function is called.

createAction
void createAction(StringArg0 name, long merge_mode)

Create a new action. After this is called, do all your calls to addDoMethod, addUndoMethod, addDoProperty, and addUndoProperty, then commit the action with commitAction.

getCurrentActionName
String getCurrentActionName()

Get the name of the current action.

getVersion
long getVersion()

Get the version, each time a new action is committed, the version number of the UndoRedo is increased automatically. This is useful mostly to check if something changed from a saved version.

opAssign
UndoRedo opAssign(T n)
Undocumented in source. Be warned that the author may not have intended to support it.
opEquals
bool opEquals(UndoRedo other)
Undocumented in source. Be warned that the author may not have intended to support it.
opEquals
bool opEquals(typeof(null) n)
Undocumented in source. Be warned that the author may not have intended to support it.
redo
bool redo()

Redo last action.

undo
bool undo()

Undo last action.

Mixins

__anonymous
mixin baseCasts
Undocumented in source.

Static functions

_new
UndoRedo _new()
Undocumented in source. Be warned that the author may not have intended to support it.

Static variables

_classBindingInitialized
bool _classBindingInitialized;
Undocumented in source.

Structs

_classBinding
struct _classBinding
Undocumented in source.

Unions

__anonymous
union __anonymous
Undocumented in source.

Variables

_GODOT_internal_name
enum string _GODOT_internal_name;
Undocumented in source.

Mixed In Members

From mixin baseCasts

as
To as()
Undocumented in source. Be warned that the author may not have intended to support it.
as
To as()
Undocumented in source. Be warned that the author may not have intended to support it.
as
ToRef as()
Undocumented in source. Be warned that the author may not have intended to support it.
opCast
template opCast(To)
Undocumented in source.
opCast
template opCast(To)
Undocumented in source.
opCast
template opCast(ToRef)
Undocumented in source.
opCast
void* opCast()
Undocumented in source. Be warned that the author may not have intended to support it.
opCast
godot_object opCast()
Undocumented in source. Be warned that the author may not have intended to support it.
opCast
bool opCast()
Undocumented in source. Be warned that the author may not have intended to support it.

Detailed Description

var undoredo = get_undo_redo() # method of EditorPlugin

func do_something(): pass # put your code here

func undo_something(): pass # put here the code that reverts what's done by "do_something()"

func _on_MyButton_pressed(): var node = get_node("MyNode2D") undoredo.create_action("Move the node") undoredo.add_do_method(self, "do_something") undoredo.add_undo_method(self, "undo_something") undoredo.add_do_property(node, "position", Vector2(100,100)) undoredo.add_undo_property(node, "position", node.position) undoredo.commit_action()

createAction, addDoMethod, addUndoMethod, addDoProperty, addUndoProperty, and commitAction should be called one after the other, like in the example. Not doing so could lead to crashes. If you don't need to register a method you can leave addDoMethod and addUndoMethod out, and so it goes for properties. You can register more than one method/property.

Meta