From 92103366a502607f215cb2613d12969993a2dbe9 Mon Sep 17 00:00:00 2001 From: kobewi Date: Tue, 5 Nov 2024 14:02:51 +0100 Subject: [PATCH] Add "Close Tabs Below" option to script editor context menu Co-authored-by: PrecisionRender --- editor/plugins/script_editor_plugin.cpp | 20 +++++++++++++++++++- editor/plugins/script_editor_plugin.h | 2 ++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 0731818be1c..77b50e64a64 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -1017,6 +1017,15 @@ void ScriptEditor::_close_other_tabs() { _queue_close_tabs(); } +void ScriptEditor::_close_tabs_below() { + int current_idx = tab_container->get_current_tab(); + for (int i = tab_container->get_tab_count() - 1; i > current_idx; i--) { + script_close_queue.push_back(i); + } + _go_to_tab(current_idx); + _queue_close_tabs(); +} + void ScriptEditor::_close_all_tabs() { for (int i = tab_container->get_tab_count() - 1; i >= 0; i--) { script_close_queue.push_back(i); @@ -1595,6 +1604,9 @@ void ScriptEditor::_menu_option(int p_option) { case CLOSE_OTHER_TABS: { _close_other_tabs(); } break; + case CLOSE_TABS_BELOW: { + _close_tabs_below(); + } break; case CLOSE_ALL: { _close_all_tabs(); } break; @@ -1641,6 +1653,9 @@ void ScriptEditor::_menu_option(int p_option) { case CLOSE_OTHER_TABS: { _close_other_tabs(); } break; + case CLOSE_TABS_BELOW: { + _close_tabs_below(); + } break; case CLOSE_ALL: { _close_all_tabs(); } break; @@ -3457,8 +3472,9 @@ void ScriptEditor::_make_script_list_context_menu() { context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/save_as"), FILE_SAVE_AS); } context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/close_file"), FILE_CLOSE); - context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/close_all"), CLOSE_ALL); context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/close_other_tabs"), CLOSE_OTHER_TABS); + context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/close_tabs_below"), CLOSE_TABS_BELOW); + context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/close_all"), CLOSE_ALL); context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/close_docs"), CLOSE_DOCS); context_menu->add_separator(); if (se) { @@ -3484,6 +3500,7 @@ void ScriptEditor::_make_script_list_context_menu() { context_menu->set_item_disabled(context_menu->get_item_index(CLOSE_ALL), tab_container->get_tab_count() <= 0); context_menu->set_item_disabled(context_menu->get_item_index(CLOSE_OTHER_TABS), tab_container->get_tab_count() <= 1); context_menu->set_item_disabled(context_menu->get_item_index(CLOSE_DOCS), !_has_docs_tab()); + context_menu->set_item_disabled(context_menu->get_item_index(CLOSE_TABS_BELOW), tab_container->get_current_tab() >= tab_container->get_tab_count() - 1); context_menu->set_item_disabled(context_menu->get_item_index(WINDOW_MOVE_UP), tab_container->get_current_tab() <= 0); context_menu->set_item_disabled(context_menu->get_item_index(WINDOW_MOVE_DOWN), tab_container->get_current_tab() >= tab_container->get_tab_count() - 1); context_menu->set_item_disabled(context_menu->get_item_index(WINDOW_SORT), tab_container->get_tab_count() <= 1); @@ -4353,6 +4370,7 @@ ScriptEditor::ScriptEditor(WindowWrapper *p_wrapper) { file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/close_file", TTRC("Close"), KeyModifierMask::CMD_OR_CTRL | Key::W), FILE_CLOSE); file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/close_all", TTRC("Close All")), CLOSE_ALL); file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/close_other_tabs", TTRC("Close Other Tabs")), CLOSE_OTHER_TABS); + file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/close_tabs_below", TTRC("Close Tabs Below")), CLOSE_TABS_BELOW); file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/close_docs", TTRC("Close Docs")), CLOSE_DOCS); file_menu->get_popup()->add_separator(); diff --git a/editor/plugins/script_editor_plugin.h b/editor/plugins/script_editor_plugin.h index 3d9f705d889..5b779af7d95 100644 --- a/editor/plugins/script_editor_plugin.h +++ b/editor/plugins/script_editor_plugin.h @@ -252,6 +252,7 @@ class ScriptEditor : public PanelContainer { CLOSE_DOCS, CLOSE_ALL, CLOSE_OTHER_TABS, + CLOSE_TABS_BELOW, TOGGLE_FILES_PANEL, SHOW_IN_FILE_SYSTEM, FILE_COPY_PATH, @@ -398,6 +399,7 @@ class ScriptEditor : public PanelContainer { void _close_discard_current_tab(const String &p_str); void _close_docs_tab(); void _close_other_tabs(); + void _close_tabs_below(); void _close_all_tabs(); void _queue_close_tabs();