Skip to content

Commit b4c92db

Browse files
committed
Refactor toggling script list
1 parent f648de1 commit b4c92db

File tree

7 files changed

+33
-14
lines changed

7 files changed

+33
-14
lines changed

editor/code_editor.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,7 +1548,8 @@ void CodeTextEditor::_set_show_warnings_panel(bool p_show) {
15481548
}
15491549

15501550
void CodeTextEditor::_toggle_scripts_pressed() {
1551-
ScriptEditor::get_singleton()->toggle_scripts_panel();
1551+
ERR_FAIL_NULL(toggle_scripts_list);
1552+
toggle_scripts_list->set_visible(!toggle_scripts_list->is_visible());
15521553
update_toggle_scripts_button();
15531554
}
15541555

@@ -1723,16 +1724,18 @@ void CodeTextEditor::set_code_complete_func(CodeTextEditorCodeCompleteFunc p_cod
17231724
code_complete_ud = p_ud;
17241725
}
17251726

1727+
void CodeTextEditor::set_toggle_list_control(Control *p_control) {
1728+
toggle_scripts_list = p_control;
1729+
}
1730+
17261731
void CodeTextEditor::show_toggle_scripts_button() {
17271732
toggle_scripts_button->show();
17281733
}
17291734

17301735
void CodeTextEditor::update_toggle_scripts_button() {
1731-
if (is_layout_rtl()) {
1732-
toggle_scripts_button->set_icon(get_editor_theme_icon(ScriptEditor::get_singleton()->is_scripts_panel_toggled() ? SNAME("Forward") : SNAME("Back")));
1733-
} else {
1734-
toggle_scripts_button->set_icon(get_editor_theme_icon(ScriptEditor::get_singleton()->is_scripts_panel_toggled() ? SNAME("Back") : SNAME("Forward")));
1735-
}
1736+
ERR_FAIL_NULL(toggle_scripts_list);
1737+
bool forward = toggle_scripts_list->is_visible() == is_layout_rtl();
1738+
toggle_scripts_button->set_icon(get_editor_theme_icon(forward ? SNAME("Forward") : SNAME("Back")));
17361739
toggle_scripts_button->set_tooltip_text(vformat("%s (%s)", TTR("Toggle Scripts Panel"), ED_GET_SHORTCUT("script_editor/toggle_scripts_panel")->get_as_text()));
17371740
}
17381741

editor/code_editor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ class CodeTextEditor : public VBoxContainer {
161161
HBoxContainer *status_bar = nullptr;
162162

163163
Button *toggle_scripts_button = nullptr;
164+
Control *toggle_scripts_list = nullptr;
164165
Button *error_button = nullptr;
165166
Button *warning_button = nullptr;
166167

@@ -285,6 +286,7 @@ class CodeTextEditor : public VBoxContainer {
285286

286287
void validate_script();
287288

289+
void set_toggle_list_control(Control *p_control);
288290
void show_toggle_scripts_button();
289291
void update_toggle_scripts_button();
290292

editor/plugins/script_text_editor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2373,6 +2373,7 @@ void ScriptTextEditor::_enable_code_editor() {
23732373

23742374
ScriptTextEditor::ScriptTextEditor() {
23752375
code_editor = memnew(CodeTextEditor);
2376+
code_editor->set_toggle_list_control(ScriptEditor::get_singleton()->get_left_list_split());
23762377
code_editor->add_theme_constant_override("separation", 2);
23772378
code_editor->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);
23782379
code_editor->set_code_complete_func(_code_complete_scripts, this);

editor/plugins/shader_editor_plugin.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ void ShaderEditorPlugin::edit(Object *p_object) {
149149
}
150150
}
151151
es.shader_inc = Ref<ShaderInclude>(si);
152-
es.shader_editor = memnew(TextShaderEditor);
152+
TextShaderEditor *text_shader = memnew(TextShaderEditor);
153+
text_shader->get_code_editor()->set_toggle_list_control(left_panel);
154+
es.shader_editor = text_shader;
153155
es.shader_editor->edit_shader_include(si);
154156
shader_tabs->add_child(es.shader_editor);
155157
} else {
@@ -166,7 +168,9 @@ void ShaderEditorPlugin::edit(Object *p_object) {
166168
if (vs.is_valid()) {
167169
es.shader_editor = memnew(VisualShaderEditor);
168170
} else {
169-
es.shader_editor = memnew(TextShaderEditor);
171+
TextShaderEditor *text_shader = memnew(TextShaderEditor);
172+
text_shader->get_code_editor()->set_toggle_list_control(left_panel);
173+
es.shader_editor = text_shader;
170174
}
171175
shader_tabs->add_child(es.shader_editor);
172176
es.shader_editor->edit_shader(es.shader);
@@ -434,6 +438,10 @@ void ShaderEditorPlugin::_close_shader(int p_index) {
434438
edited_shaders.remove_at(p_index);
435439
_update_shader_list();
436440
EditorUndoRedoManager::get_singleton()->clear_history(); // To prevent undo on deleted graphs.
441+
442+
if (shader_tabs->get_tab_count() == 0) {
443+
left_panel->show(); // Make sure the panel is visible, because it can't be toggled without open shaders.
444+
}
437445
}
438446

439447
void ShaderEditorPlugin::_close_builtin_shaders_from_scene(const String &p_scene) {
@@ -768,10 +776,10 @@ ShaderEditorPlugin::ShaderEditorPlugin() {
768776
Ref<Shortcut> make_floating_shortcut = ED_SHORTCUT_AND_COMMAND("shader_editor/make_floating", TTR("Make Floating"));
769777
window_wrapper->set_wrapped_control(main_split, make_floating_shortcut);
770778

771-
VBoxContainer *vb = memnew(VBoxContainer);
779+
left_panel = memnew(VBoxContainer);
772780

773781
HBoxContainer *menu_hb = memnew(HBoxContainer);
774-
vb->add_child(menu_hb);
782+
left_panel->add_child(menu_hb);
775783
file_menu = memnew(MenuButton);
776784
file_menu->set_text(TTR("File"));
777785
file_menu->set_shortcut_context(main_split);
@@ -803,14 +811,14 @@ ShaderEditorPlugin::ShaderEditorPlugin() {
803811
shader_list = memnew(ItemList);
804812
shader_list->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
805813
shader_list->set_v_size_flags(Control::SIZE_EXPAND_FILL);
806-
vb->add_child(shader_list);
814+
left_panel->add_child(shader_list);
807815
shader_list->connect(SceneStringName(item_selected), callable_mp(this, &ShaderEditorPlugin::_shader_selected));
808816
shader_list->connect("item_clicked", callable_mp(this, &ShaderEditorPlugin::_shader_list_clicked));
809817
shader_list->set_allow_rmb_select(true);
810818
SET_DRAG_FORWARDING_GCD(shader_list, ShaderEditorPlugin);
811819

812-
main_split->add_child(vb);
813-
vb->set_custom_minimum_size(Size2(200, 300) * EDSCALE);
820+
main_split->add_child(left_panel);
821+
left_panel->set_custom_minimum_size(Size2(200, 300) * EDSCALE);
814822

815823
shader_tabs = memnew(TabContainer);
816824
shader_tabs->set_tabs_visible(false);
@@ -823,7 +831,7 @@ ShaderEditorPlugin::ShaderEditorPlugin() {
823831
button = EditorNode::get_bottom_panel()->add_item(TTR("Shader Editor"), window_wrapper, ED_SHORTCUT_AND_COMMAND("bottom_panels/toggle_shader_editor_bottom_panel", TTR("Toggle Shader Editor Bottom Panel"), KeyModifierMask::ALT | Key::S));
824832

825833
shader_create_dialog = memnew(ShaderCreateDialog);
826-
vb->add_child(shader_create_dialog);
834+
main_split->add_child(shader_create_dialog);
827835
shader_create_dialog->connect("shader_created", callable_mp(this, &ShaderEditorPlugin::_shader_created));
828836
shader_create_dialog->connect("shader_include_created", callable_mp(this, &ShaderEditorPlugin::_shader_include_created));
829837
}

editor/plugins/shader_editor_plugin.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class ShaderCreateDialog;
4040
class ShaderEditor;
4141
class TabContainer;
4242
class TextShaderEditor;
43+
class VBoxContainer;
4344
class VisualShaderEditor;
4445
class WindowWrapper;
4546

@@ -82,6 +83,7 @@ class ShaderEditorPlugin : public EditorPlugin {
8283
};
8384

8485
HSplitContainer *main_split = nullptr;
86+
VBoxContainer *left_panel = nullptr;
8587
ItemList *shader_list = nullptr;
8688
TabContainer *shader_tabs = nullptr;
8789

editor/plugins/text_editor.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "editor/editor_node.h"
3636
#include "editor/editor_settings.h"
3737
#include "scene/gui/menu_button.h"
38+
#include "scene/gui/split_container.h"
3839

3940
void TextEditor::add_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_highlighter) {
4041
ERR_FAIL_COND(p_highlighter.is_null());
@@ -606,6 +607,7 @@ TextEditor::TextEditor() {
606607
code_editor->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);
607608
code_editor->set_v_size_flags(Control::SIZE_EXPAND_FILL);
608609
code_editor->show_toggle_scripts_button();
610+
code_editor->set_toggle_list_control(ScriptEditor::get_singleton()->get_left_list_split());
609611

610612
update_settings();
611613

editor/plugins/text_shader_editor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,4 +1256,5 @@ TextShaderEditor::TextShaderEditor() {
12561256
add_child(disk_changed);
12571257

12581258
_editor_settings_changed();
1259+
code_editor->show_toggle_scripts_button(); // TODO: Disabled for now, because it doesn't work properly.
12591260
}

0 commit comments

Comments
 (0)