EditorUndoRedoManager

package
v0.0.0-...-20ed0ac Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 19, 2025 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

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 EditorPlugin.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 func.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Advanced

type Advanced = class

Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.

type Any

type Any interface {
	gd.IsClass
	AsEditorUndoRedoManager() Instance
}

type Expanded

type Expanded = MoreArgs

type Extension

type Extension[T gdclass.Interface] struct{ gdclass.Extension[T, Instance] }

Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this Extension

func (*Extension[T]) AsEditorUndoRedoManager

func (self *Extension[T]) AsEditorUndoRedoManager() Instance

func (*Extension[T]) AsObject

func (self *Extension[T]) AsObject() [1]gd.Object

type ID

type ID Object.ID

ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.

func (ID) Instance

func (id ID) Instance() (Instance, bool)

type Instance

type Instance [1]gdclass.EditorUndoRedoManager

Instance of the class with convieniently typed arguments and results.

var Nil Instance

Nil is a nil/null instance of the class. Equivalent to the zero value.

func New

func New() Instance

func (Instance) AddDoMethod

func (self Instance) AddDoMethod(obj Object.Instance, method string, args ...any)

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.

func (Instance) AddDoProperty

func (self Instance) AddDoProperty(obj Object.Instance, property string, value any)

Register a property value change for "do".

If this is the first operation, the 'object' will be used to deduce target undo history.

func (Instance) AddDoReference

func (self Instance) AddDoReference(obj Object.Instance)

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 (Instance) AddUndoMethod

func (self Instance) AddUndoMethod(obj Object.Instance, method string, args ...any)

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.

func (Instance) AddUndoProperty

func (self Instance) AddUndoProperty(obj Object.Instance, property string, value any)

Register a property value change for "undo".

If this is the first operation, the 'object' will be used to deduce target undo history.

func (Instance) AddUndoReference

func (self Instance) AddUndoReference(obj Object.Instance)

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 (Instance) AsEditorUndoRedoManager

func (self Instance) AsEditorUndoRedoManager() Instance

func (Instance) AsObject

func (self Instance) AsObject() [1]gd.Object

func (Instance) ClearHistory

func (self Instance) ClearHistory()

Clears the given undo history. You can clear history for a specific scene, global history, or for all scenes at once if 'id' is InvalidHistory.

If 'increase_version' is true, the undo history version will be increased, marking it as unsaved. Useful for operations that modify the scene, but don't support undo.

var scene_root = EditorInterface.GetEditedSceneRoot()
var undo_redo = EditorInterface.GetEditorUndoRedo()
undo_redo.MoreArgs().ClearHistory(undo_redo.GetObjectHistoryId(scene_root.AsObject()), false)

Note: If you want to mark an edited scene as unsaved without clearing its history, use EditorInterface.MarkSceneAsUnsaved instead.

func (Instance) CommitAction

func (self Instance) CommitAction()

Commits the action. If 'execute' is true (default), all "do" methods/properties are called/set when this function is called.

func (Instance) CreateAction

func (self Instance) CreateAction(name string)

Create a new action. After this is called, do all your calls to AddDoMethod, AddUndoMethod, AddDoProperty, and AddUndoProperty, then commit the action with CommitAction.

The way actions are merged is dictated by the 'merge_mode' argument.

If 'custom_context' 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 'backward_undo_ops'. When 'backward_undo_ops' 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.

If 'mark_unsaved' is false, the action will not mark the history as unsaved. This is useful for example for actions that change a selection, or a setting that will be saved automatically. Otherwise, this should be left to true if the action requires saving by the user or if it can cause data loss when left unsaved.

func (Instance) ForceFixedHistory

func (self Instance) ForceFixedHistory()

Forces the next operation (e.g. AddDoMethod) 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.

This method should only be used when absolutely necessary, otherwise it might cause invalid history state. For most of complex cases, the custom_context parameter of CreateAction is sufficient.

func (Instance) GetHistoryUndoRedo

func (self Instance) GetHistoryUndoRedo(id int) UndoRedo.Instance

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 SpecialHistory).

Best used with GetObjectHistoryId. 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).

func (Instance) GetObjectHistoryId

func (self Instance) GetObjectHistoryId(obj Object.Instance) int

Returns the history ID deduced from the given 'object'. It can be used with GetHistoryUndoRedo.

func (Instance) ID

func (self Instance) ID() ID

func (Instance) IsCommittingAction

func (self Instance) IsCommittingAction() bool

Returns true if the EditorUndoRedoManager is currently committing the action, i.e. running its "do" method or property change (see CommitAction).

func (Instance) MoreArgs

func (self Instance) MoreArgs() MoreArgs

MoreArgs enables certain functions to be called with additional 'optional' arguments.

func (Instance) OnHistoryChanged

func (self Instance) OnHistoryChanged(cb func(), flags ...Signal.Flags)

Emitted when the list of actions in any history has changed, either when an action is committed or a history is cleared.

func (Instance) OnVersionChanged

func (self Instance) OnVersionChanged(cb func(), flags ...Signal.Flags)

Emitted when the version of any history has changed as a result of undo or redo call.

func (*Instance) SetObject

func (self *Instance) SetObject(obj [1]gd.Object) bool

func (Instance) Virtual

func (self Instance) Virtual(name string) reflect.Value

type MoreArgs

type MoreArgs [1]gdclass.EditorUndoRedoManager

MoreArgs is a container for Instance functions with additional 'optional' arguments.

func (MoreArgs) ClearHistory

func (self MoreArgs) ClearHistory(id int, increase_version bool)

Clears the given undo history. You can clear history for a specific scene, global history, or for all scenes at once if 'id' is InvalidHistory.

If 'increase_version' is true, the undo history version will be increased, marking it as unsaved. Useful for operations that modify the scene, but don't support undo.

var scene_root = EditorInterface.GetEditedSceneRoot()
var undo_redo = EditorInterface.GetEditorUndoRedo()
undo_redo.MoreArgs().ClearHistory(undo_redo.GetObjectHistoryId(scene_root.AsObject()), false)

Note: If you want to mark an edited scene as unsaved without clearing its history, use EditorInterface.MarkSceneAsUnsaved instead.

func (MoreArgs) CommitAction

func (self MoreArgs) CommitAction(execute bool)

Commits the action. If 'execute' is true (default), all "do" methods/properties are called/set when this function is called.

func (MoreArgs) CreateAction

func (self MoreArgs) CreateAction(name string, merge_mode UndoRedo.MergeMode, custom_context Object.Instance, backward_undo_ops bool, mark_unsaved bool)

Create a new action. After this is called, do all your calls to AddDoMethod, AddUndoMethod, AddDoProperty, and AddUndoProperty, then commit the action with CommitAction.

The way actions are merged is dictated by the 'merge_mode' argument.

If 'custom_context' 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 'backward_undo_ops'. When 'backward_undo_ops' 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.

If 'mark_unsaved' is false, the action will not mark the history as unsaved. This is useful for example for actions that change a selection, or a setting that will be saved automatically. Otherwise, this should be left to true if the action requires saving by the user or if it can cause data loss when left unsaved.

type SpecialHistory

type SpecialHistory int //gd:EditorUndoRedoManager.SpecialHistory
const (
	// Global history not associated with any scene, but with external resources etc.
	GlobalHistory SpecialHistory = 0
	// History associated with remote inspector. Used when live editing a running project.
	RemoteHistory SpecialHistory = -9
	// Invalid "null" history. It's a special value, not associated with any object.
	InvalidHistory SpecialHistory = -99
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL