Update UndoRedo.xml

(cherry picked from commit 57f3e89f70)
This commit is contained in:
VirtualBox 2018-08-26 21:11:17 +02:00 committed by Rémi Verschelde
parent 172c6c615e
commit 3395a55db4
1 changed files with 31 additions and 6 deletions

37
doc/classes/UndoRedo.xml Normal file → Executable file
View File

@ -4,8 +4,29 @@
Helper to manage UndoRedo in the editor or custom tools. Helper to manage UndoRedo in the editor or custom tools.
</brief_description> </brief_description>
<description> <description>
Helper to manage UndoRedo in the editor or custom tools. It works by storing calls to functions in both 'do' an 'undo' lists. Helper to manage UndoRedo in the editor or custom tools. It works by registering methods and property changes inside 'actions'.
Common behavior is to create an action, then add do/undo calls to functions or property changes, then committing the action. Common behavior is to create an action, then add do/undo calls to functions or property changes, then committing the action.
Here's an example on how to add an action to Godot editor's own 'undoredo':
[codeblock]
var undoredo = get_undo_redo() # method of EditorPlugin
func do_something():
pass # put your code here
func undo_something():
pass # put here the code that reverts what's done by "do_something()"
func _on_MyButton_pressed():
var node = get_node("MyNode2D")
undoredo.create_action("Move the node")
undoredo.add_do_method(self, "do_something")
undoredo.add_undo_method(self, "undo_something")
undoredo.add_do_property(node, "position", Vector2(100,100))
undoredo.add_undo_property(node, "position", node.position)
undoredo.commit_action()
[/codeblock]
[method create_action], [method add_do_method], [method add_undo_method], [method add_do_property], [method add_undo_property], and [method commit_action] should be called one after the other, like in the example. Not doing so could lead to crashes.
If you don't need to register a method you can leave [method add_do_method] and [method add_undo_method] out, and so it goes for properties. You can register more than one method/property.
</description> </description>
<tutorials> <tutorials>
</tutorials> </tutorials>
@ -20,6 +41,7 @@
<argument index="1" name="method" type="String"> <argument index="1" name="method" type="String">
</argument> </argument>
<description> <description>
Register a method that will be called when the action is committed.
</description> </description>
</method> </method>
<method name="add_do_property"> <method name="add_do_property">
@ -32,7 +54,7 @@
<argument index="2" name="value" type="Variant"> <argument index="2" name="value" type="Variant">
</argument> </argument>
<description> <description>
Set a property with a custom value. Register a property value change for 'do'.
</description> </description>
</method> </method>
<method name="add_do_reference"> <method name="add_do_reference">
@ -41,7 +63,7 @@
<argument index="0" name="object" type="Object"> <argument index="0" name="object" type="Object">
</argument> </argument>
<description> <description>
Add a 'do' reference 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. 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.
</description> </description>
</method> </method>
<method name="add_undo_method" qualifiers="vararg"> <method name="add_undo_method" qualifiers="vararg">
@ -52,6 +74,7 @@
<argument index="1" name="method" type="String"> <argument index="1" name="method" type="String">
</argument> </argument>
<description> <description>
Register a method that will be called when the action is undone.
</description> </description>
</method> </method>
<method name="add_undo_property"> <method name="add_undo_property">
@ -64,7 +87,7 @@
<argument index="2" name="value" type="Variant"> <argument index="2" name="value" type="Variant">
</argument> </argument>
<description> <description>
Undo setting of a property with a custom value. Register a property value change for 'undo'.
</description> </description>
</method> </method>
<method name="add_undo_reference"> <method name="add_undo_reference">
@ -73,7 +96,7 @@
<argument index="0" name="object" type="Object"> <argument index="0" name="object" type="Object">
</argument> </argument>
<description> <description>
Add an 'undo' reference 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!). 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!).
</description> </description>
</method> </method>
<method name="clear_history"> <method name="clear_history">
@ -98,7 +121,7 @@
<argument index="1" name="merge_mode" type="int" enum="UndoRedo.MergeMode" default="0"> <argument index="1" name="merge_mode" type="int" enum="UndoRedo.MergeMode" default="0">
</argument> </argument>
<description> <description>
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]. 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].
</description> </description>
</method> </method>
<method name="get_current_action_name" qualifiers="const"> <method name="get_current_action_name" qualifiers="const">
@ -120,12 +143,14 @@
<return type="void"> <return type="void">
</return> </return>
<description> <description>
Redo last action.
</description> </description>
</method> </method>
<method name="undo"> <method name="undo">
<return type="void"> <return type="void">
</return> </return>
<description> <description>
Undo last action.
</description> </description>
</method> </method>
</methods> </methods>