EditorUndoRedoManager

package
v0.0.0-...-c858641 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2025 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

graphics.gd/classdb/EditorUndoRedoManager is a manager for graphics.gd/classdb/UndoRedo objects associated with edited scenes. Each scene has its own undo history and graphics.gd/classdb/EditorUndoRedoManager ensures that each action performed in the editor gets associated with a proper scene. For actions not related to scenes (graphics.gd/classdb/ProjectSettings edits, external resources, etc.), a separate global history is used.

The usage is mostly the same as graphics.gd/classdb/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 graphics.gd/classdb/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.

graphics.gd/classdb/EditorUndoRedoManager is intended to be used by Godot editor plugins. You can obtain it using graphics.gd/classdb/EditorPlugin.Instance.GetUndoRedo. For non-editor uses or plugins that don't need to integrate with the editor's undo history, use graphics.gd/classdb/UndoRedo instead.

The manager's API is mostly the same as in graphics.gd/classdb/UndoRedo, so you can refer to its documentation for more examples. The main difference is that graphics.gd/classdb/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 [1]gdclass.EditorUndoRedoManager

func (Expanded) ClearHistory

func (self Expanded) 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.

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

func (Expanded) CommitAction

func (self Expanded) CommitAction(execute bool)

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

func (Expanded) CreateAction

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

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

The way actions are merged is dictated by the 'merge_mode' argument. See [UndoRedo.MergeMode] for details.

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.

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.

Note: If you want to mark an edited scene as unsaved without clearing its history, use graphics.gd/classdb/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 Instance.AddDoMethod, Instance.AddUndoMethod, Instance.AddDoProperty, and Instance.AddUndoProperty, then commit the action with Instance.CommitAction.

The way actions are merged is dictated by the 'merge_mode' argument. See [UndoRedo.MergeMode] for details.

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.

func (Instance) ForceFixedHistory

func (self Instance) ForceFixedHistory()

Forces the next operation (e.g. Instance.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 Instance.CreateAction is sufficient.

func (Instance) GetHistoryUndoRedo

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

Returns the graphics.gd/classdb/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 Instance.GetObjectHistoryId. This method is only provided in case you need some more advanced methods of graphics.gd/classdb/UndoRedo (but keep in mind that directly operating on the graphics.gd/classdb/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 Instance.GetHistoryUndoRedo.

func (Instance) ID

func (self Instance) ID() ID

func (Instance) IsCommittingAction

func (self Instance) IsCommittingAction() bool

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

func (Instance) OnHistoryChanged

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

func (Instance) OnVersionChanged

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

func (*Instance) SetObject

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

func (Instance) Virtual

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

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