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 ¶
- 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) MoreArgs() MoreArgs
- 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 MoreArgs
- 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 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.
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 ¶
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 ¶
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 ¶
Returns the history ID deduced from the given 'object'. It can be used with GetHistoryUndoRedo.
func (Instance) IsCommittingAction ¶
Returns true if the EditorUndoRedoManager is currently committing the action, i.e. running its "do" method or property change (see CommitAction).
func (Instance) MoreArgs ¶
MoreArgs enables certain functions to be called with additional 'optional' arguments.
func (Instance) OnHistoryChanged ¶
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 ¶
Emitted when the version of any history has changed as a result of undo or redo call.
type MoreArgs ¶
type MoreArgs [1]gdclass.EditorUndoRedoManager
MoreArgs is a container for Instance functions with additional 'optional' arguments.
func (MoreArgs) 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 (MoreArgs) CommitAction ¶
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 )