| 1 | <?xml version="1.0" encoding="UTF-8" ?> |
| 2 | <class name="EditorUndoRedoManager" inherits="Object" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd"> |
| 3 | <brief_description> |
| 4 | Manages undo history of scenes opened in the editor. |
| 5 | </brief_description> |
| 6 | <description> |
| 7 | [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. |
| 8 | 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: |
| 9 | - If the object is a [Node], use the currently edited scene; |
| 10 | - If the object is a built-in resource, use the scene from its path; |
| 11 | - If the object is external resource or anything else, use global history. |
| 12 | This guessing can sometimes yield false results, so you can provide a custom context object when creating an action. |
| 13 | [EditorUndoRedoManager] is intended to be used by Godot editor plugins. You can obtain it using [method 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. |
| 14 | 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]. |
| 15 | </description> |
| 16 | <tutorials> |
| 17 | </tutorials> |
| 18 | <methods> |
| 19 | <method name="add_do_method" qualifiers="vararg"> |
| 20 | <return type="void" /> |
| 21 | <param index="0" name="object" type="Object" /> |
| 22 | <param index="1" name="method" type="StringName" /> |
| 23 | <description> |
| 24 | Register a method that will be called when the action is committed (i.e. the "do" action). |
| 25 | If this is the first operation, the [param object] will be used to deduce target undo history. |
| 26 | </description> |
| 27 | </method> |
| 28 | <method name="add_do_property"> |
| 29 | <return type="void" /> |
| 30 | <param index="0" name="object" type="Object" /> |
| 31 | <param index="1" name="property" type="StringName" /> |
| 32 | <param index="2" name="value" type="Variant" /> |
| 33 | <description> |
| 34 | Register a property value change for "do". |
| 35 | If this is the first operation, the [param object] will be used to deduce target undo history. |
| 36 | </description> |
| 37 | </method> |
| 38 | <method name="add_do_reference"> |
| 39 | <return type="void" /> |
| 40 | <param index="0" name="object" type="Object" /> |
| 41 | <description> |
| 42 | 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. |
| 43 | </description> |
| 44 | </method> |
| 45 | <method name="add_undo_method" qualifiers="vararg"> |
| 46 | <return type="void" /> |
| 47 | <param index="0" name="object" type="Object" /> |
| 48 | <param index="1" name="method" type="StringName" /> |
| 49 | <description> |
| 50 | Register a method that will be called when the action is undone (i.e. the "undo" action). |
| 51 | If this is the first operation, the [param object] will be used to deduce target undo history. |
| 52 | </description> |
| 53 | </method> |
| 54 | <method name="add_undo_property"> |
| 55 | <return type="void" /> |
| 56 | <param index="0" name="object" type="Object" /> |
| 57 | <param index="1" name="property" type="StringName" /> |
| 58 | <param index="2" name="value" type="Variant" /> |
| 59 | <description> |
| 60 | Register a property value change for "undo". |
| 61 | If this is the first operation, the [param object] will be used to deduce target undo history. |
| 62 | </description> |
| 63 | </method> |
| 64 | <method name="add_undo_reference"> |
| 65 | <return type="void" /> |
| 66 | <param index="0" name="object" type="Object" /> |
| 67 | <description> |
| 68 | 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!). |
| 69 | </description> |
| 70 | </method> |
| 71 | <method name="clear_history"> |
| 72 | <return type="void" /> |
| 73 | <param index="0" name="id" type="int" default="-99" /> |
| 74 | <param index="1" name="increase_version" type="bool" default="true" /> |
| 75 | <description> |
| 76 | Clears the given undo history. You can clear history for a specific scene, global history, or for all histories at once (except [constant REMOTE_HISTORY]) if [param id] is [constant INVALID_HISTORY]. |
| 77 | If [param increase_version] is [code]true[/code], the undo history version will be increased, marking it as unsaved. Useful for operations that modify the scene, but don't support undo. |
| 78 | [codeblock] |
| 79 | var scene_root = EditorInterface.get_edited_scene_root() |
| 80 | var undo_redo = EditorInterface.get_editor_undo_redo() |
| 81 | undo_redo.clear_history(undo_redo.get_object_history_id(scene_root)) |
| 82 | [/codeblock] |
| 83 | [b]Note:[/b] If you want to mark an edited scene as unsaved without clearing its history, use [method EditorInterface.mark_scene_as_unsaved] instead. |
| 84 | </description> |
| 85 | </method> |
| 86 | <method name="commit_action"> |
| 87 | <return type="void" /> |
| 88 | <param index="0" name="execute" type="bool" default="true" /> |
| 89 | <description> |
| 90 | Commits the action. If [param execute] is [code]true[/code] (default), all "do" methods/properties are called/set when this function is called. |
| 91 | </description> |
| 92 | </method> |
| 93 | <method name="create_action"> |
| 94 | <return type="void" /> |
| 95 | <param index="0" name="name" type="String" /> |
| 96 | <param index="1" name="merge_mode" type="int" enum="UndoRedo.MergeMode" default="0" /> |
| 97 | <param index="2" name="custom_context" type="Object" default="null" /> |
| 98 | <param index="3" name="backward_undo_ops" type="bool" default="false" /> |
| 99 | <param index="4" name="mark_unsaved" type="bool" default="true" /> |
| 100 | <description> |
| 101 | Create a new action. After this is called, do all your calls to [method add_do_method], [method add_undo_method], [method add_do_property], and [method add_undo_property], then commit the action with [method commit_action]. |
| 102 | The way actions are merged is dictated by the [param merge_mode] argument. |
| 103 | If [param custom_context] object is provided, it will be used for deducing target history (instead of using the first operation). |
| 104 | The way undo operation are ordered in actions is dictated by [param backward_undo_ops]. When [param backward_undo_ops] is [code]false[/code] 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. |
| 105 | If [param mark_unsaved] is [code]false[/code], 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 [code]true[/code] if the action requires saving by the user or if it can cause data loss when left unsaved. |
| 106 | </description> |
| 107 | </method> |
| 108 | <method name="force_fixed_history"> |
| 109 | <return type="void" /> |
| 110 | <description> |
| 111 | Forces the next operation (e.g. [method add_do_method]) 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. |
| 112 | This method should only be used when absolutely necessary, otherwise it might cause invalid history state. For most of complex cases, the [code]custom_context[/code] parameter of [method create_action] is sufficient. |
| 113 | </description> |
| 114 | </method> |
| 115 | <method name="get_history_undo_redo" qualifiers="const"> |
| 116 | <return type="UndoRedo" /> |
| 117 | <param index="0" name="id" type="int" /> |
| 118 | <description> |
| 119 | Returns the [UndoRedo] object associated with the given history [param id]. |
| 120 | [param id] above [code]0[/code] are mapped to the opened scene tabs (but it doesn't match their order). [param id] of [code]0[/code] or lower have special meaning (see [enum SpecialHistory]). |
| 121 | Best used with [method get_object_history_id]. 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). |
| 122 | </description> |
| 123 | </method> |
| 124 | <method name="get_object_history_id" qualifiers="const"> |
| 125 | <return type="int" /> |
| 126 | <param index="0" name="object" type="Object" /> |
| 127 | <description> |
| 128 | Returns the history ID deduced from the given [param object]. It can be used with [method get_history_undo_redo]. |
| 129 | </description> |
| 130 | </method> |
| 131 | <method name="is_committing_action" qualifiers="const"> |
| 132 | <return type="bool" /> |
| 133 | <description> |
| 134 | Returns [code]true[/code] if the [EditorUndoRedoManager] is currently committing the action, i.e. running its "do" method or property change (see [method commit_action]). |
| 135 | </description> |
| 136 | </method> |
| 137 | </methods> |
| 138 | <signals> |
| 139 | <signal name="history_changed"> |
| 140 | <description> |
| 141 | Emitted when the list of actions in any history has changed, either when an action is committed or a history is cleared. |
| 142 | </description> |
| 143 | </signal> |
| 144 | <signal name="version_changed"> |
| 145 | <description> |
| 146 | Emitted when the version of any history has changed as a result of undo or redo call. |
| 147 | </description> |
| 148 | </signal> |
| 149 | </signals> |
| 150 | <constants> |
| 151 | <constant name="GLOBAL_HISTORY" value="0" enum="SpecialHistory"> |
| 152 | Global history not associated with any scene, but with external resources etc. |
| 153 | </constant> |
| 154 | <constant name="REMOTE_HISTORY" value="-9" enum="SpecialHistory"> |
| 155 | History associated with remote inspector. Used when live editing a running project. |
| 156 | </constant> |
| 157 | <constant name="INVALID_HISTORY" value="-99" enum="SpecialHistory"> |
| 158 | Invalid "null" history. It's a special value, not associated with any object. |
| 159 | </constant> |
| 160 | </constants> |
| 161 | </class> |