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 ¶
- type Advanced
- type Any
- type Expanded
- type Extension
- type ID
- type Instance
- func (self Instance) AddDoMethod(obj Object.Instance, method string, args ...any)
- func (self Instance) AddDoProperty(obj Object.Instance, property string, value any)
- func (self Instance) AddDoReference(obj Object.Instance)
- func (self Instance) AddUndoMethod(obj Object.Instance, method string, args ...any)
- func (self Instance) AddUndoProperty(obj Object.Instance, property string, value any)
- func (self Instance) AddUndoReference(obj Object.Instance)
- func (self Instance) AsEditorUndoRedoManager() Instance
- func (self Instance) AsObject() [1]gd.Object
- func (self Instance) ClearHistory()
- func (self Instance) CommitAction()
- func (self Instance) CreateAction(name string)
- func (self Instance) ForceFixedHistory()
- func (self Instance) GetHistoryUndoRedo(id int) UndoRedo.Instance
- func (self Instance) GetObjectHistoryId(obj Object.Instance) int
- func (self Instance) ID() ID
- func (self Instance) IsCommittingAction() bool
- func (self Instance) OnHistoryChanged(cb func(), flags ...Signal.Flags)
- func (self Instance) OnVersionChanged(cb func(), flags ...Signal.Flags)
- func (self *Instance) SetObject(obj [1]gd.Object) bool
- func (self Instance) Virtual(name string) reflect.Value
- type SpecialHistory
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 Expanded ¶
type Expanded [1]gdclass.EditorUndoRedoManager
func (Expanded) 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 (Expanded) CommitAction ¶
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 ¶
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 ¶
type 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.
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 (Instance) AddDoMethod ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 (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 ¶
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 ¶
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 ¶
Returns the history ID deduced from the given 'object'. It can be used with Instance.GetHistoryUndoRedo.
func (Instance) IsCommittingAction ¶
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 (Instance) OnVersionChanged ¶
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 )