@@ -190,12 +190,6 @@ void ShaderEditorPlugin::edit(Object *p_object) {
190190 cte->connect (" zoomed" , callable_mp (this , &ShaderEditorPlugin::_set_text_shader_zoom_factor));
191191 cte->connect (SceneStringName (visibility_changed), callable_mp (this , &ShaderEditorPlugin::_update_shader_editor_zoom_factor).bind (cte));
192192 }
193-
194- if (text_shader_editor->get_top_bar ()) {
195- text_shader_editor->get_top_bar ()->set_h_size_flags (Control::SIZE_EXPAND_FILL);
196- menu_hb->add_child (text_shader_editor->get_top_bar ());
197- menu_hb->move_child (text_shader_editor->get_top_bar (), 1 );
198- }
199193 }
200194
201195 shader_tabs->set_current_tab (shader_tabs->get_tab_count () - 1 );
@@ -459,29 +453,22 @@ void ShaderEditorPlugin::_make_script_list_context_menu() {
459453
460454void ShaderEditorPlugin::_close_shader (int p_index) {
461455 ERR_FAIL_INDEX (p_index, shader_tabs->get_tab_count ());
462-
463- Control *c = shader_tabs->get_tab_control (p_index);
464- VisualShaderEditor *vs_editor = Object::cast_to<VisualShaderEditor>(c);
465- if (vs_editor) {
466- vs_editor->save_editor_layout ();
456+ if (file_menu->get_parent () != nullptr ) {
467457 file_menu->get_parent ()->remove_child (file_menu);
468- menu_hb->add_child (file_menu);
469- menu_hb->move_child (file_menu, 0 );
470-
458+ }
459+ if (make_floating->get_parent ()) {
471460 make_floating->get_parent ()->remove_child (make_floating);
472- menu_hb->add_child (make_floating);
473- } else {
474- memdelete (edited_shaders[p_index].shader_editor ->get_top_bar ());
475461 }
462+ ShaderEditor *shader_editor = Object::cast_to<ShaderEditor>(shader_tabs->get_tab_control (p_index));
463+ ERR_FAIL_NULL (shader_editor);
476464
477- memdelete (c );
465+ memdelete (shader_editor );
478466 edited_shaders.remove_at (p_index);
479467 _update_shader_list ();
480468 EditorUndoRedoManager::get_singleton ()->clear_history (); // To prevent undo on deleted graphs.
481469
482470 if (shader_tabs->get_tab_count () == 0 ) {
483471 shader_list->show (); // Make sure the panel is visible, because it can't be toggled without open shaders.
484- menu_spacer->show ();
485472 } else {
486473 _switch_to_editor (edited_shaders[shader_tabs->get_current_tab ()].shader_editor );
487474 }
@@ -795,44 +782,13 @@ void ShaderEditorPlugin::_update_shader_editor_zoom_factor(CodeTextEditor *p_sha
795782}
796783
797784void ShaderEditorPlugin::_switch_to_editor (ShaderEditor *p_editor) {
798- Control *bar = p_editor->get_top_bar ();
799-
800- VisualShaderEditor *vs_editor = Object::cast_to<VisualShaderEditor>(p_editor);
801- if (vs_editor) {
785+ if (file_menu->get_parent () != nullptr ) {
802786 file_menu->get_parent ()->remove_child (file_menu);
803- file_menu->set_switch_on_hover (false );
804- bar->add_child (file_menu);
805- bar->move_child (file_menu, 2 ); // Toggle Files Panel button + separator.
806-
807- make_floating->get_parent ()->remove_child (make_floating);
808- bar->add_child (make_floating);
809- } else {
810- if (menu_spacer->is_visible ()) {
811- menu_spacer->hide ();
812- }
813-
814- // Just swapped from a visual shader editor.
815- if (file_menu->get_parent () != menu_hb) {
816- file_menu->get_parent ()->remove_child (file_menu);
817- file_menu->set_switch_on_hover (true );
818- menu_hb->add_child (file_menu);
819- menu_hb->move_child (file_menu, 0 );
820-
821- make_floating->get_parent ()->remove_child (make_floating);
822- menu_hb->add_child (make_floating);
823- }
824787 }
825-
826- for (int i = 0 ; i < shader_tabs->get_tab_count (); i++) {
827- ShaderEditor *se = Object::cast_to<ShaderEditor>(shader_tabs->get_tab_control (i));
828- if (se && se->get_top_bar ()) {
829- if (se == p_editor) {
830- se->get_top_bar ()->show ();
831- } else {
832- se->get_top_bar ()->hide ();
833- }
834- }
788+ if (make_floating->get_parent ()) {
789+ make_floating->get_parent ()->remove_child (make_floating);
835790 }
791+ p_editor->use_menu_bar_items (file_menu, make_floating);
836792}
837793
838794void ShaderEditorPlugin::_file_removed (const String &p_removed_file) {
@@ -902,8 +858,6 @@ ShaderEditorPlugin::ShaderEditorPlugin() {
902858 files_split->set_split_offset (200 * EDSCALE);
903859 files_split->set_v_size_flags (Control::SIZE_EXPAND_FILL);
904860
905- menu_hb = memnew (HBoxContainer);
906- main_container->add_child (menu_hb);
907861 file_menu = memnew (MenuButton);
908862 file_menu->set_flat (false );
909863 file_menu->set_theme_type_variation (" FlatMenuButton" );
@@ -912,24 +866,20 @@ ShaderEditorPlugin::ShaderEditorPlugin() {
912866 file_menu->set_shortcut_context (files_split);
913867 _setup_popup_menu (FILE, file_menu->get_popup ());
914868 file_menu->get_popup ()->connect (SceneStringName (id_pressed), callable_mp (this , &ShaderEditorPlugin::_menu_item_pressed));
915- menu_hb->add_child (file_menu);
916869
917870 _set_file_specific_items_disabled (true );
918871
919872 context_menu = memnew (PopupMenu);
920873 add_child (context_menu);
921874 context_menu->connect (SceneStringName (id_pressed), callable_mp (this , &ShaderEditorPlugin::_menu_item_pressed));
922875
923- menu_spacer = menu_hb->add_spacer ();
924-
925876 make_floating = memnew (ScreenSelect);
926877 make_floating->connect (" request_open_in_screen" , callable_mp (window_wrapper, &WindowWrapper::enable_window_on_screen).bind (true ));
927878 if (!make_floating->is_disabled ()) {
928879 // Override default ScreenSelect tooltip if multi-window support is available.
929880 make_floating->set_tooltip_text (TTR (" Make the shader editor floating." ) + " \n " + TTR (" Right-click to open the screen selector." ));
930881 }
931882
932- menu_hb->add_child (make_floating);
933883 window_wrapper->connect (" window_visibility_changed" , callable_mp (this , &ShaderEditorPlugin::_window_changed));
934884
935885 shader_list = memnew (ItemList);
@@ -962,3 +912,8 @@ ShaderEditorPlugin::ShaderEditorPlugin() {
962912 shader_create_dialog->connect (" shader_created" , callable_mp (this , &ShaderEditorPlugin::_shader_created));
963913 shader_create_dialog->connect (" shader_include_created" , callable_mp (this , &ShaderEditorPlugin::_shader_include_created));
964914}
915+
916+ ShaderEditorPlugin::~ShaderEditorPlugin () {
917+ memdelete (file_menu);
918+ memdelete (make_floating);
919+ }
0 commit comments