Improve EditorPlugin state documentation

(cherry picked from commit 505a2ce468)
This commit is contained in:
kobewi 2022-06-02 03:49:30 +02:00 committed by Rémi Verschelde
parent fe13b94a14
commit 7882b1ea05

View file

@ -310,7 +310,15 @@
<method name="get_state" qualifiers="virtual">
<return type="Dictionary" />
<description>
Gets the state of your plugin editor. This is used when saving the scene (so state is kept when opening it again) and for switching tabs (so state can be restored when the tab returns).
Override this method to provide a state data you want to be saved, like view position, grid settings, folding, etc. This is used when saving the scene (so state is kept when opening it again) and for switching tabs (so state can be restored when the tab returns). This data is automatically saved for each scene in an [code]editstate[/code] file in the editor metadata folder. If you want to store global (scene-independent) editor data for your plugin, you can use [method get_window_layout] instead.
Use [method set_state] to restore your saved state.
[b]Note:[/b] This method should not be used to save important settings that should persist with the project.
[b]Note:[/b] You must implement [method get_plugin_name] for the state to be stored and restored correctly.
[codeblock]
func get_state():
var state = {"zoom": zoom, "preferred_color": my_color}
return state
[/codeblock]
</description>
</method>
<method name="get_undo_redo">
@ -323,7 +331,13 @@
<return type="void" />
<argument index="0" name="layout" type="ConfigFile" />
<description>
Gets the GUI layout of the plugin. This is used to save the project's editor layout when [method queue_save_layout] is called or the editor layout was changed(For example changing the position of a dock).
Override this method to provide the GUI layout of the plugin or any other data you want to be stored. This is used to save the project's editor layout when [method queue_save_layout] is called or the editor layout was changed (for example changing the position of a dock). The data is stored in the [code]editor_layout.cfg[/code] file in the editor metadata directory.
Use [method set_window_layout] to restore your saved layout.
[codeblock]
func get_window_layout(configuration):
configuration.set_value("MyPlugin", "window_position", $Window.position)
configuration.set_value("MyPlugin", "icon_color", $Icon.modulate)
[/codeblock]
</description>
</method>
<method name="handles" qualifiers="virtual">
@ -466,14 +480,25 @@
<return type="void" />
<argument index="0" name="state" type="Dictionary" />
<description>
Restore the state saved by [method get_state].
Restore the state saved by [method get_state]. This method is called when the current scene tab is changed in the editor.
[b]Note:[/b] Your plugin must implement [method get_plugin_name], otherwise it will not be recognized and this method will not be called.
[codeblock]
func set_state(data):
zoom = data.get("zoom", 1.0)
preferred_color = data.get("my_color", Color.white)
[/codeblock]
</description>
</method>
<method name="set_window_layout" qualifiers="virtual">
<return type="void" />
<argument index="0" name="layout" type="ConfigFile" />
<description>
Restore the plugin GUI layout saved by [method get_window_layout].
Restore the plugin GUI layout and data saved by [method get_window_layout]. This method is called for every plugin on editor startup. Use the provided [code]configuration[/code] file to read your saved data.
[codeblock]
func set_window_layout(configuration):
$Window.position = configuration.get_value("MyPlugin", "window_position", Vector2())
$Icon.modulate = configuration.get_value("MyPlugin", "icon_color", Color.white)
[/codeblock]
</description>
</method>
<method name="update_overlays" qualifiers="const">