Merge pull request #28262 from KoBeWi/gotta_close_them_all

Add Close Others/Right/All for scene tabs
This commit is contained in:
Rémi Verschelde 2019-04-25 22:46:46 +02:00 committed by GitHub
commit f05dce3ee2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 4 deletions

View File

@ -1936,6 +1936,21 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
opening_prev = true; opening_prev = true;
open_request(previous_scenes.back()->get()); open_request(previous_scenes.back()->get());
} break;
case FILE_CLOSE_OTHERS:
case FILE_CLOSE_RIGHT:
case FILE_CLOSE_ALL: {
if (editor_data.get_edited_scene_count() > 1 && (current_option != FILE_CLOSE_RIGHT || editor_data.get_edited_scene() < editor_data.get_edited_scene_count() - 1)) {
int next_tab = editor_data.get_edited_scene() + 1;
next_tab %= editor_data.get_edited_scene_count();
_scene_tab_closed(next_tab, current_option);
} else {
if (current_option != FILE_CLOSE_ALL)
current_option = -1;
else
_scene_tab_closed(editor_data.get_edited_scene());
}
} break; } break;
case FILE_CLOSE_ALL_AND_QUIT: case FILE_CLOSE_ALL_AND_QUIT:
case FILE_CLOSE_ALL_AND_RUN_PROJECT_MANAGER: case FILE_CLOSE_ALL_AND_RUN_PROJECT_MANAGER:
@ -2553,6 +2568,9 @@ void EditorNode::_discard_changes(const String &p_str) {
case FILE_CLOSE_ALL_AND_QUIT: case FILE_CLOSE_ALL_AND_QUIT:
case FILE_CLOSE_ALL_AND_RUN_PROJECT_MANAGER: case FILE_CLOSE_ALL_AND_RUN_PROJECT_MANAGER:
case FILE_CLOSE: case FILE_CLOSE:
case FILE_CLOSE_OTHERS:
case FILE_CLOSE_RIGHT:
case FILE_CLOSE_ALL:
case SCENE_TAB_CLOSE: { case SCENE_TAB_CLOSE: {
_remove_scene(tab_closing); _remove_scene(tab_closing);
@ -2565,6 +2583,15 @@ void EditorNode::_discard_changes(const String &p_str) {
} else { } else {
_menu_option_confirm(current_option, false); _menu_option_confirm(current_option, false);
} }
} else if (current_option == FILE_CLOSE_OTHERS || current_option == FILE_CLOSE_RIGHT) {
if (editor_data.get_edited_scene_count() == 1 || (current_option == FILE_CLOSE_RIGHT && editor_data.get_edited_scene_count() <= editor_data.get_edited_scene() + 1)) {
current_option = -1;
save_confirmation->hide();
} else {
_menu_option_confirm(current_option, false);
}
} else if (current_option == FILE_CLOSE_ALL && editor_data.get_edited_scene_count() > 0) {
_menu_option_confirm(current_option, false);
} else { } else {
current_option = -1; current_option = -1;
save_confirmation->hide(); save_confirmation->hide();
@ -4192,8 +4219,8 @@ void EditorNode::_scene_tab_script_edited(int p_tab) {
inspector_dock->edit_resource(script); inspector_dock->edit_resource(script);
} }
void EditorNode::_scene_tab_closed(int p_tab) { void EditorNode::_scene_tab_closed(int p_tab, int option) {
current_option = SCENE_TAB_CLOSE; current_option = option;
tab_closing = p_tab; tab_closing = p_tab;
Node *scene = editor_data.get_edited_scene_root(p_tab); Node *scene = editor_data.get_edited_scene_root(p_tab);
if (!scene) { if (!scene) {
@ -4266,7 +4293,11 @@ void EditorNode::_scene_tab_input(const Ref<InputEvent> &p_input) {
scene_tabs_context_menu->add_separator(); scene_tabs_context_menu->add_separator();
scene_tabs_context_menu->add_item(TTR("Show in FileSystem"), FILE_SHOW_IN_FILESYSTEM); scene_tabs_context_menu->add_item(TTR("Show in FileSystem"), FILE_SHOW_IN_FILESYSTEM);
scene_tabs_context_menu->add_item(TTR("Play This Scene"), RUN_PLAY_SCENE); scene_tabs_context_menu->add_item(TTR("Play This Scene"), RUN_PLAY_SCENE);
scene_tabs_context_menu->add_separator();
scene_tabs_context_menu->add_item(TTR("Close Tab"), FILE_CLOSE); scene_tabs_context_menu->add_item(TTR("Close Tab"), FILE_CLOSE);
scene_tabs_context_menu->add_item(TTR("Close Other Tabs"), FILE_CLOSE_OTHERS);
scene_tabs_context_menu->add_item(TTR("Close Tabs to the Right"), FILE_CLOSE_RIGHT);
scene_tabs_context_menu->add_item(TTR("Close All Tabs"), FILE_CLOSE_ALL);
} }
scene_tabs_context_menu->set_position(mb->get_global_position()); scene_tabs_context_menu->set_position(mb->get_global_position());
scene_tabs_context_menu->popup(); scene_tabs_context_menu->popup();
@ -5523,7 +5554,7 @@ EditorNode::EditorNode() {
scene_tabs->set_drag_to_rearrange_enabled(true); scene_tabs->set_drag_to_rearrange_enabled(true);
scene_tabs->connect("tab_changed", this, "_scene_tab_changed"); scene_tabs->connect("tab_changed", this, "_scene_tab_changed");
scene_tabs->connect("right_button_pressed", this, "_scene_tab_script_edited"); scene_tabs->connect("right_button_pressed", this, "_scene_tab_script_edited");
scene_tabs->connect("tab_close", this, "_scene_tab_closed"); scene_tabs->connect("tab_close", this, "_scene_tab_closed", varray(SCENE_TAB_CLOSE));
scene_tabs->connect("tab_hover", this, "_scene_tab_hover"); scene_tabs->connect("tab_hover", this, "_scene_tab_hover");
scene_tabs->connect("mouse_exited", this, "_scene_tab_exit"); scene_tabs->connect("mouse_exited", this, "_scene_tab_exit");
scene_tabs->connect("gui_input", this, "_scene_tab_input"); scene_tabs->connect("gui_input", this, "_scene_tab_input");

View File

@ -150,6 +150,9 @@ private:
FILE_QUICK_OPEN_SCRIPT, FILE_QUICK_OPEN_SCRIPT,
FILE_OPEN_PREV, FILE_OPEN_PREV,
FILE_CLOSE, FILE_CLOSE,
FILE_CLOSE_OTHERS,
FILE_CLOSE_RIGHT,
FILE_CLOSE_ALL,
FILE_CLOSE_ALL_AND_QUIT, FILE_CLOSE_ALL_AND_QUIT,
FILE_CLOSE_ALL_AND_RUN_PROJECT_MANAGER, FILE_CLOSE_ALL_AND_RUN_PROJECT_MANAGER,
FILE_QUIT, FILE_QUIT,
@ -563,7 +566,7 @@ private:
void _dock_split_dragged(int ofs); void _dock_split_dragged(int ofs);
void _dock_popup_exit(); void _dock_popup_exit();
void _scene_tab_changed(int p_tab); void _scene_tab_changed(int p_tab);
void _scene_tab_closed(int p_tab); void _scene_tab_closed(int p_tab, int option = SCENE_TAB_CLOSE);
void _scene_tab_hover(int p_tab); void _scene_tab_hover(int p_tab);
void _scene_tab_exit(); void _scene_tab_exit();
void _scene_tab_input(const Ref<InputEvent> &p_input); void _scene_tab_input(const Ref<InputEvent> &p_input);