2
0
Эх сурвалжийг харах

Add a function to remove controls from containers

Closes #5968
George Marques 7 жил өмнө
parent
commit
da69a06253

+ 11 - 0
doc/classes/EditorPlugin.xml

@@ -274,6 +274,17 @@
 				Remove the control from the bottom panel. Don't forget to call this if you added one, so the editor can remove it cleanly.
 				Remove the control from the bottom panel. Don't forget to call this if you added one, so the editor can remove it cleanly.
 			</description>
 			</description>
 		</method>
 		</method>
+		<method name="remove_control_from_container">
+			<return type="void">
+			</return>
+			<argument index="0" name="container" type="int" enum="EditorPlugin.CustomControlContainer">
+			</argument>
+			<argument index="1" name="control" type="Control">
+			</argument>
+			<description>
+				Remove the control from the specified container. Use it when cleaning up after adding a control with [method add_control_to_container]. Note that you can simply free the control if you won't use it anymore.
+			</description>
+		</method>
 		<method name="remove_control_from_docks">
 		<method name="remove_control_from_docks">
 			<return type="void">
 			<return type="void">
 			</return>
 			</return>

+ 48 - 0
editor/editor_plugin.cpp

@@ -373,6 +373,53 @@ void EditorPlugin::add_control_to_container(CustomControlContainer p_location, C
 	}
 	}
 }
 }
 
 
+void EditorPlugin::remove_control_from_container(CustomControlContainer p_location, Control *p_control) {
+
+	switch (p_location) {
+
+		case CONTAINER_TOOLBAR: {
+
+			EditorNode::get_menu_hb()->remove_child(p_control);
+		} break;
+
+		case CONTAINER_SPATIAL_EDITOR_MENU: {
+
+			SpatialEditor::get_singleton()->remove_control_from_menu_panel(p_control);
+
+		} break;
+		case CONTAINER_SPATIAL_EDITOR_SIDE: {
+
+			SpatialEditor::get_singleton()->get_palette_split()->remove_child(p_control);
+
+		} break;
+		case CONTAINER_SPATIAL_EDITOR_BOTTOM: {
+
+			SpatialEditor::get_singleton()->get_shader_split()->remove_child(p_control);
+
+		} break;
+		case CONTAINER_CANVAS_EDITOR_MENU: {
+
+			CanvasItemEditor::get_singleton()->remove_control_from_menu_panel(p_control);
+
+		} break;
+		case CONTAINER_CANVAS_EDITOR_SIDE: {
+
+			CanvasItemEditor::get_singleton()->get_palette_split()->remove_child(p_control);
+
+		} break;
+		case CONTAINER_CANVAS_EDITOR_BOTTOM: {
+
+			CanvasItemEditor::get_singleton()->get_bottom_split()->remove_child(p_control);
+
+		} break;
+		case CONTAINER_PROPERTY_EDITOR_BOTTOM: {
+
+			EditorNode::get_singleton()->get_property_editor_vb()->remove_child(p_control);
+
+		} break;
+	}
+}
+
 void EditorPlugin::add_tool_menu_item(const String &p_name, Object *p_handler, const String &p_callback, const Variant &p_ud) {
 void EditorPlugin::add_tool_menu_item(const String &p_name, Object *p_handler, const String &p_callback, const Variant &p_ud) {
 
 
 	//EditorNode::get_singleton()->add_tool_menu_item(p_name, p_handler, p_callback, p_ud);
 	//EditorNode::get_singleton()->add_tool_menu_item(p_name, p_handler, p_callback, p_ud);
@@ -651,6 +698,7 @@ void EditorPlugin::_bind_methods() {
 	ClassDB::bind_method(D_METHOD("add_control_to_dock", "slot", "control"), &EditorPlugin::add_control_to_dock);
 	ClassDB::bind_method(D_METHOD("add_control_to_dock", "slot", "control"), &EditorPlugin::add_control_to_dock);
 	ClassDB::bind_method(D_METHOD("remove_control_from_docks", "control"), &EditorPlugin::remove_control_from_docks);
 	ClassDB::bind_method(D_METHOD("remove_control_from_docks", "control"), &EditorPlugin::remove_control_from_docks);
 	ClassDB::bind_method(D_METHOD("remove_control_from_bottom_panel", "control"), &EditorPlugin::remove_control_from_bottom_panel);
 	ClassDB::bind_method(D_METHOD("remove_control_from_bottom_panel", "control"), &EditorPlugin::remove_control_from_bottom_panel);
+	ClassDB::bind_method(D_METHOD("remove_control_from_container", "container", "control"), &EditorPlugin::remove_control_from_container);
 	//ClassDB::bind_method(D_METHOD("add_tool_menu_item", "name", "handler", "callback", "ud"),&EditorPlugin::add_tool_menu_item,DEFVAL(Variant()));
 	//ClassDB::bind_method(D_METHOD("add_tool_menu_item", "name", "handler", "callback", "ud"),&EditorPlugin::add_tool_menu_item,DEFVAL(Variant()));
 	ClassDB::bind_method(D_METHOD("add_tool_submenu_item", "name", "submenu"), &EditorPlugin::add_tool_submenu_item);
 	ClassDB::bind_method(D_METHOD("add_tool_submenu_item", "name", "submenu"), &EditorPlugin::add_tool_submenu_item);
 	//ClassDB::bind_method(D_METHOD("remove_tool_menu_item", "name"),&EditorPlugin::remove_tool_menu_item);
 	//ClassDB::bind_method(D_METHOD("remove_tool_menu_item", "name"),&EditorPlugin::remove_tool_menu_item);

+ 1 - 0
editor/editor_plugin.h

@@ -148,6 +148,7 @@ public:
 	//TODO: send a resource for editing to the editor node?
 	//TODO: send a resource for editing to the editor node?
 
 
 	void add_control_to_container(CustomControlContainer p_location, Control *p_control);
 	void add_control_to_container(CustomControlContainer p_location, Control *p_control);
+	void remove_control_from_container(CustomControlContainer p_location, Control *p_control);
 	ToolButton *add_control_to_bottom_panel(Control *p_control, const String &p_title);
 	ToolButton *add_control_to_bottom_panel(Control *p_control, const String &p_title);
 	void add_control_to_dock(DockSlot p_slot, Control *p_control);
 	void add_control_to_dock(DockSlot p_slot, Control *p_control);
 	void remove_control_from_docks(Control *p_control);
 	void remove_control_from_docks(Control *p_control);

+ 5 - 0
editor/plugins/canvas_item_editor_plugin.cpp

@@ -4002,6 +4002,11 @@ void CanvasItemEditor::add_control_to_menu_panel(Control *p_control) {
 	hb->add_child(p_control);
 	hb->add_child(p_control);
 }
 }
 
 
+void CanvasItemEditor::remove_control_from_menu_panel(Control *p_control) {
+
+	hb->remove_child(p_control);
+}
+
 HSplitContainer *CanvasItemEditor::get_palette_split() {
 HSplitContainer *CanvasItemEditor::get_palette_split() {
 
 
 	return palette_split;
 	return palette_split;

+ 1 - 0
editor/plugins/canvas_item_editor_plugin.h

@@ -509,6 +509,7 @@ public:
 	void set_state(const Dictionary &p_state);
 	void set_state(const Dictionary &p_state);
 
 
 	void add_control_to_menu_panel(Control *p_control);
 	void add_control_to_menu_panel(Control *p_control);
+	void remove_control_from_menu_panel(Control *p_control);
 
 
 	HSplitContainer *get_palette_split();
 	HSplitContainer *get_palette_split();
 	VSplitContainer *get_bottom_split();
 	VSplitContainer *get_bottom_split();

+ 5 - 0
editor/plugins/spatial_editor_plugin.cpp

@@ -4778,6 +4778,11 @@ void SpatialEditor::add_control_to_menu_panel(Control *p_control) {
 	hbc_menu->add_child(p_control);
 	hbc_menu->add_child(p_control);
 }
 }
 
 
+void SpatialEditor::remove_control_from_menu_panel(Control *p_control) {
+
+	hbc_menu->remove_child(p_control);
+}
+
 void SpatialEditor::set_can_preview(Camera *p_preview) {
 void SpatialEditor::set_can_preview(Camera *p_preview) {
 
 
 	for (int i = 0; i < 4; i++) {
 	for (int i = 0; i < 4; i++) {

+ 1 - 0
editor/plugins/spatial_editor_plugin.h

@@ -605,6 +605,7 @@ public:
 	UndoRedo *get_undo_redo() { return undo_redo; }
 	UndoRedo *get_undo_redo() { return undo_redo; }
 
 
 	void add_control_to_menu_panel(Control *p_control);
 	void add_control_to_menu_panel(Control *p_control);
+	void remove_control_from_menu_panel(Control *p_control);
 
 
 	VSplitContainer *get_shader_split();
 	VSplitContainer *get_shader_split();
 	HSplitContainer *get_palette_split();
 	HSplitContainer *get_palette_split();