Forráskód Böngészése

Merge pull request #6163 from TheHX/pr-editor-plugin

Expose additional functions for the EditorPlugin class
Rémi Verschelde 9 éve
szülő
commit
d7e75a0978
3 módosított fájl, 50 hozzáadás és 3 törlés
  1. 24 0
      doc/base/classes.xml
  2. 25 3
      tools/editor/editor_plugin.cpp
  3. 1 0
      tools/editor/editor_plugin.h

+ 24 - 0
doc/base/classes.xml

@@ -11505,6 +11505,13 @@
 				Get the undo/redo object. Most actions in the editor can be undoable, so use this object to make sure this happens when it's worth it.
 			</description>
 		</method>
+		<method name="get_window_layout" qualifiers="virtual">
+			<argument index="0" name="layout" type="ConfigFile">
+			</argument>
+			<description>
+				Get the GUI layout of the plugin. This is used to save the project's editor layout when the [method EditorPlugin.queue_save_layout] is called or the editor layout was changed(For example changing the position of a dock).
+			</description>
+		</method>
 		<method name="handles" qualifiers="virtual">
 			<return type="bool">
 			</return>
@@ -11529,6 +11536,11 @@
 				Remember that you have to manage the visibility of all your editor controls manually.
 			</description>
 		</method>
+		<method name="queue_save_layout" qualifiers="const">
+			<description>
+				Queue save the project's editor layout.
+			</description>
+		</method>
 		<method name="remove_control_from_bottom_panel">
 			<argument index="0" name="control" type="Control">
 			</argument>
@@ -11564,6 +11576,11 @@
 				Remove the import plugin, don't forget to call this on exit.
 			</description>
 		</method>
+		<method name="save_external_data" qualifiers="virtual">
+			<description>
+				This method is called after the editor save the project or when the it's closed. It asks the plugin to save edited external scenes/resources.
+			</description>
+		</method>
 		<method name="set_state" qualifiers="virtual">
 			<argument index="0" name="state" type="Dictionary">
 			</argument>
@@ -11571,6 +11588,13 @@
 				Restore the state saved by [method EditorPlugin.get_state].
 			</description>
 		</method>
+		<method name="set_window_layout" qualifiers="virtual">
+			<argument index="0" name="layout" type="ConfigFile">
+			</argument>
+			<description>
+				Restore the plugin GUI layout saved by [method EditorPlugin.get_window_layout].
+			</description>
+		</method>
 	</methods>
 	<constants>
 		<constant name="CONTAINER_TOOLBAR" value="0">

+ 25 - 3
tools/editor/editor_plugin.cpp

@@ -211,15 +211,22 @@ void EditorPlugin::clear() {
 
 }
 
-void EditorPlugin::save_external_data() {} // if editor references external resources/scenes, save them
+// if editor references external resources/scenes, save them
+void EditorPlugin::save_external_data() {
+
+	if (get_script_instance() && get_script_instance()->has_method("save_external_data")) {
+		get_script_instance()->call("save_external_data");
+	}
+}
+
+// if changes are pending in editor, apply them
 void EditorPlugin::apply_changes() {
 
 	if (get_script_instance() && get_script_instance()->has_method("apply_changes")) {
 		get_script_instance()->call("apply_changes");
 	}
+}
 
-
-} // if changes are pending in editor, apply them
 void EditorPlugin::get_breakpoints(List<String> *p_breakpoints) {
 
 	if (get_script_instance() && get_script_instance()->has_method("get_breakpoints")) {
@@ -239,10 +246,21 @@ void EditorPlugin::save_global_state() {}
 
 void EditorPlugin::set_window_layout(Ref<ConfigFile> p_layout) {
 
+	if (get_script_instance() && get_script_instance()->has_method("set_window_layout")) {
+		get_script_instance()->call("set_window_layout", p_layout);
+	}
 }
 
 void EditorPlugin::get_window_layout(Ref<ConfigFile> p_layout){
 
+	if (get_script_instance() && get_script_instance()->has_method("get_window_layout")) {
+		get_script_instance()->call("get_window_layout", p_layout);
+	}
+}
+
+void EditorPlugin::queue_save_layout() const {
+
+	EditorNode::get_singleton()->save_layout();
 }
 
 EditorSelection* EditorPlugin::get_selection() {
@@ -302,6 +320,7 @@ void EditorPlugin::_bind_methods() {
 	ObjectTypeDB::bind_method(_MD("get_undo_redo:UndoRedo"),&EditorPlugin::_get_undo_redo);
 	ObjectTypeDB::bind_method(_MD("get_selection:EditorSelection"),&EditorPlugin::get_selection);
 	ObjectTypeDB::bind_method(_MD("get_editor_settings:EditorSettings"),&EditorPlugin::get_editor_settings);
+	ObjectTypeDB::bind_method(_MD("queue_save_layout"),&EditorPlugin::queue_save_layout);
 
 	ObjectTypeDB::add_virtual_method(get_type_static(),MethodInfo(Variant::BOOL,"forward_input_event",PropertyInfo(Variant::INPUT_EVENT,"event")));
 	ObjectTypeDB::add_virtual_method(get_type_static(),MethodInfo(Variant::BOOL,"forward_spatial_input_event",PropertyInfo(Variant::OBJECT,"camera",PROPERTY_HINT_RESOURCE_TYPE,"Camera"),PropertyInfo(Variant::INPUT_EVENT,"event")));
@@ -317,8 +336,11 @@ void EditorPlugin::_bind_methods() {
 	ObjectTypeDB::add_virtual_method(get_type_static(),MethodInfo(Variant::DICTIONARY,"get_state"));
 	ObjectTypeDB::add_virtual_method(get_type_static(),MethodInfo("set_state",PropertyInfo(Variant::DICTIONARY,"state")));
 	ObjectTypeDB::add_virtual_method(get_type_static(),MethodInfo("clear"));
+	ObjectTypeDB::add_virtual_method(get_type_static(),MethodInfo("save_external_data"));
 	ObjectTypeDB::add_virtual_method(get_type_static(),MethodInfo("apply_changes"));
 	ObjectTypeDB::add_virtual_method(get_type_static(),MethodInfo(Variant::STRING_ARRAY,"get_breakpoints"));
+	ObjectTypeDB::add_virtual_method(get_type_static(),MethodInfo("set_window_layout",PropertyInfo(Variant::OBJECT,"layout",PROPERTY_HINT_RESOURCE_TYPE,"ConfigFile")));
+	ObjectTypeDB::add_virtual_method(get_type_static(),MethodInfo("get_window_layout",PropertyInfo(Variant::OBJECT,"layout",PROPERTY_HINT_RESOURCE_TYPE,"ConfigFile")));
 
 	BIND_CONSTANT( CONTAINER_TOOLBAR );
 	BIND_CONSTANT( CONTAINER_SPATIAL_EDITOR_MENU );

+ 1 - 0
tools/editor/editor_plugin.h

@@ -118,6 +118,7 @@ public:
 	virtual void get_window_layout(Ref<ConfigFile> p_layout);
 	virtual void edited_scene_changed(){}; // if changes are pending in editor, apply them
 
+	void queue_save_layout() const;
 
 	Control *get_base_control();