EditorUndoRedoManager
Hereda: Object
Gestiona el historial de deshacer de las escenas abiertas en el editor.
Descripción
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.get_undo_redo(). 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 Callable.
Métodos
void |
add_do_method(object: Object, method: StringName, ...) vararg |
void |
add_do_property(object: Object, property: StringName, value: Variant) |
void |
add_do_reference(object: Object) |
void |
add_undo_method(object: Object, method: StringName, ...) vararg |
void |
add_undo_property(object: Object, property: StringName, value: Variant) |
void |
add_undo_reference(object: Object) |
void |
clear_history(id: int = -99, increase_version: bool = true) |
void |
commit_action(execute: bool = true) |
void |
create_action(name: String, merge_mode: MergeMode = 0, custom_context: Object = null, backward_undo_ops: bool = false, mark_unsaved: bool = true) |
void |
|
get_history_undo_redo(id: int) const |
|
get_object_history_id(object: Object) const |
|
is_committing_action() const |
Señales
history_changed() 🔗
Se emite cuando la lista de acciones en cualquier historial ha cambiado, ya sea cuando se confirma una acción o se borra un historial.
version_changed() 🔗
Se emite cuando la versión de cualquier historial ha cambiado como resultado de una llamada de deshacer o rehacer.
Enumeraciones
enum SpecialHistory: 🔗
SpecialHistory GLOBAL_HISTORY = 0
Historial global no asociado a ninguna escena, sino a recursos externos, etc.
SpecialHistory REMOTE_HISTORY = -9
Historial asociado con el inspector remoto. Se utiliza cuando se edita en vivo un proyecto en ejecución.
SpecialHistory INVALID_HISTORY = -99
Historial "nulo" inválido. Es un valor especial, no asociado a ningún objeto.
Descripciones de Métodos
void add_do_method(object: Object, method: StringName, ...) vararg 🔗
Registra un método que se llamará cuando se confirme la acción (es decir, la acción "do").
Si esta es la primera operación, el object se utilizará para deducir el historial de deshacer objetivo.
void add_do_property(object: Object, property: StringName, value: Variant) 🔗
Registra un cambio de valor de propiedad para "do".
Si esta es la primera operación, el object se utilizará para deducir el historial de deshacer objetivo.
void add_do_reference(object: Object) 🔗
Registra una referencia para "hacer" que se borrará si se pierde la historia de "hacer". Esto es útil sobre todo para los nuevos nodos creados para la llamada "hacer". No lo utilices para los recursos.
void add_undo_method(object: Object, method: StringName, ...) vararg 🔗
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.
void add_undo_property(object: Object, property: StringName, value: Variant) 🔗
Register a property value change for "undo".
If this is the first operation, the object will be used to deduce target undo history.
void add_undo_reference(object: Object) 🔗
Registra una referencia para "deshacer" que se borrará si se pierde la historia de "deshacer". Esto es útil sobre todo para los nodos eliminados con la llamada "hacer" (¡no la llamada "deshacer"!).
void clear_history(id: int = -99, increase_version: bool = true) 🔗
Limpia el historial de deshacer dado. Puedes limpiar el historial de una escena específica, el historial global o para todas las escenas a la vez si id es INVALID_HISTORY.
Si increase_version es true, la versión del historial de deshacer se incrementará, marcándola como no guardada. Útil para las operaciones que modifican la escena, pero no admiten deshacer.
var scene_root = EditorInterface.get_edited_scene_root()
var undo_redo = EditorInterface.get_editor_undo_redo()
undo_redo.clear_history(undo_redo.get_object_history_id(scene_root))
Nota: Si quieres marcar una escena editada como no guardada sin limpiar su historial, usa EditorInterface.mark_scene_as_unsaved() en su lugar.
void commit_action(execute: bool = true) 🔗
Confirma la acción. Si execute es true (por defecto), todos los métodos/propiedades "do" son llamados/establecidos cuando se llama a esta función.
void create_action(name: String, merge_mode: MergeMode = 0, custom_context: Object = null, backward_undo_ops: bool = false, mark_unsaved: bool = true) 🔗
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(), then commit the action with commit_action().
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.
void force_fixed_history() 🔗
Fuerza a que la siguiente operación (p. ej. add_do_method()) use el historial de la acción en lugar de adivinarlo del objeto. Esto a veces es necesario cuando no se puede determinar correctamente un historial, como para un recurso anidado que aún no tiene una ruta.
Este método solo debe usarse cuando sea absolutamente necesario, de lo contrario, podría causar un estado de historial no válido. Para la mayoría de los casos complejos, el parámetro custom_context de create_action() es suficiente.
UndoRedo get_history_undo_redo(id: int) const 🔗
Devuelve el objeto UndoRedo asociado con el id del historial dado.
id por encima de 0 se asignan a las pestañas de escena abiertas (pero no coinciden con su orden). id de 0 o inferior tienen un significado especial (véase SpecialHistory).
Se utiliza mejor con get_object_history_id(). Este método solo se proporciona en caso de que necesites algunos métodos más avanzados de UndoRedo (pero ten en cuenta que operar directamente en el objeto UndoRedo podría afectar la estabilidad del editor).
int get_object_history_id(object: Object) const 🔗
Devuelve el ID del historial deducido del object dado. Se puede usar con get_history_undo_redo().
bool is_committing_action() const 🔗
Devuelve true si el EditorUndoRedoManager está actualmente confirmando la acción, es decir, ejecutando su método "do" o el cambio de propiedad (véase commit_action()).