UndoRedo

Inherits: Object

Category: Core

Brief Description

Helper to manage UndoRedo in the editor or custom tools.

Member Functions

Variant add_do_method ( Object object, String method ) vararg
void add_do_property ( Object object, String property, Variant value )
void add_do_reference ( Object object )
Variant add_undo_method ( Object object, String method ) vararg
void add_undo_property ( Object object, String property, Variant value )
void add_undo_reference ( Object object )
void clear_history ( )
void commit_action ( )
void create_action ( String name, int merge_mode=0 )
String get_current_action_name ( ) const
int get_max_steps ( ) const
int get_version ( ) const
void redo ( )
void set_max_steps ( int max_steps )
void undo ( )

Numeric Constants

  • MERGE_DISABLE = 0
  • MERGE_ENDS = 1
  • MERGE_ALL = 2

Description

Helper to manage UndoRedo in the editor or custom tools. It works by storing calls to functions in both ‘do’ an ‘undo’ lists.

Common behavior is to create an action, then add do/undo calls to functions or property changes, then committing the action.

Member Function Description

Set a property with a custom value.

  • void add_do_reference ( Object object )

Add a ‘do’ reference 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.

Undo setting of a property with a custom value.

  • void add_undo_reference ( Object object )

Add an ‘undo’ reference 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!).

  • void clear_history ( )

Clear the undo/redo history and associated references.

  • void commit_action ( )

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

  • void create_action ( String name, int merge_mode=0 )

Create a new action. After this is called, do all your calls to add_do_method, add_undo_method, add_do_property and add_undo_property.

  • String get_current_action_name ( ) const

Get the name of the current action.

  • int get_max_steps ( ) const
  • int get_version ( ) const

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.

  • void redo ( )
  • void set_max_steps ( int max_steps )
  • void undo ( )