Browse Source

Add interface for plugins to enable/disable other plugins

George Marques 7 năm trước cách đây
mục cha
commit
87be0bc110
3 tập tin đã thay đổi với 34 bổ sung0 xóa
  1. 20 0
      doc/classes/EditorInterface.xml
  2. 11 0
      editor/editor_plugin.cpp
  3. 3 0
      editor/editor_plugin.h

+ 20 - 0
doc/classes/EditorInterface.xml

@@ -100,6 +100,15 @@
 				Shows the given property on the given [code]object[/code] in the Editor's Inspector dock.
 			</description>
 		</method>
+		<method name="is_plugin_enabled" qualifiers="const">
+			<return type="bool">
+			</return>
+			<argument index="0" name="plugin" type="String">
+			</argument>
+			<description>
+				Returns the enabled status of a plugin. The plugin name is the same as its directory name.
+			</description>
+		</method>
 		<method name="make_mesh_previews">
 			<return type="Array">
 			</return>
@@ -155,6 +164,17 @@
 			<description>
 			</description>
 		</method>
+		<method name="set_plugin_enabled">
+			<return type="void">
+			</return>
+			<argument index="0" name="plugin" type="String">
+			</argument>
+			<argument index="1" name="enabled" type="bool">
+			</argument>
+			<description>
+				Sets the enabled status of a plugin. The plugin name is the same as its directory name.
+			</description>
+		</method>
 	</methods>
 	<constants>
 	</constants>

+ 11 - 0
editor/editor_plugin.cpp

@@ -235,6 +235,14 @@ Control *EditorInterface::get_base_control() {
 	return EditorNode::get_singleton()->get_gui_base();
 }
 
+void EditorInterface::set_plugin_enabled(const String &p_plugin, bool p_enabled) {
+	EditorNode::get_singleton()->set_addon_plugin_enabled(p_plugin, p_enabled);
+}
+
+bool EditorInterface::is_plugin_enabled(const String &p_plugin) const {
+	return EditorNode::get_singleton()->is_addon_plugin_enabled(p_plugin);
+}
+
 Error EditorInterface::save_scene() {
 	if (!get_edited_scene_root())
 		return ERR_CANT_CREATE;
@@ -271,6 +279,9 @@ void EditorInterface::_bind_methods() {
 	ClassDB::bind_method(D_METHOD("select_file", "p_file"), &EditorInterface::select_file);
 	ClassDB::bind_method(D_METHOD("get_selected_path"), &EditorInterface::get_selected_path);
 
+	ClassDB::bind_method(D_METHOD("set_plugin_enabled", "plugin", "enabled"), &EditorInterface::set_plugin_enabled);
+	ClassDB::bind_method(D_METHOD("is_plugin_enabled", "plugin"), &EditorInterface::is_plugin_enabled);
+
 	ClassDB::bind_method(D_METHOD("save_scene"), &EditorInterface::save_scene);
 	ClassDB::bind_method(D_METHOD("save_scene_as", "path", "with_preview"), &EditorInterface::save_scene_as, DEFVAL(true));
 }

+ 3 - 0
editor/editor_plugin.h

@@ -90,6 +90,9 @@ public:
 
 	Control *get_base_control();
 
+	void set_plugin_enabled(const String &p_plugin, bool p_enabled);
+	bool is_plugin_enabled(const String &p_plugin) const;
+
 	Error save_scene();
 	void save_scene_as(const String &p_scene, bool p_with_preview = true);