Added CLOSE_ALL files option to script editor

This commit is contained in:
supaiku 2016-08-13 02:56:38 +02:00
parent b9e8bddf19
commit 3d84849e03
2 changed files with 40 additions and 2 deletions

View file

@ -480,6 +480,33 @@ void ScriptEditor::_close_docs_tab() {
}
void ScriptEditor::_close_all_tabs() {
int child_count = tab_container->get_child_count();
for (int i = child_count-1; i>=0; i--) {
tab_container->set_current_tab(i);
ScriptEditorBase *se = tab_container->get_child(i)->cast_to<ScriptEditorBase>();
if (se) {
// Maybe there are unsaved changes
if (se->is_unsaved()) {
_ask_close_current_unsaved_tab(se);
continue;
}
}
_close_current_tab();
}
}
void ScriptEditor::_ask_close_current_unsaved_tab(ScriptEditorBase *current) {
erase_tab_confirm->set_text("Close and save changes?\n\""+current->get_name()+"\"");
erase_tab_confirm->popup_centered_minsize();
}
void ScriptEditor::_resave_scripts(const String& p_str) {
@ -831,8 +858,7 @@ void ScriptEditor::_menu_option(int p_option) {
case FILE_CLOSE: {
if (current->is_unsaved()) {
erase_tab_confirm->set_text("Close and save changes?\n\""+current->get_name()+"\"");
erase_tab_confirm->popup_centered_minsize();
_ask_close_current_unsaved_tab(current);
} else {
_close_current_tab();
}
@ -840,6 +866,9 @@ void ScriptEditor::_menu_option(int p_option) {
case CLOSE_DOCS: {
_close_docs_tab();
} break;
case CLOSE_ALL: {
_close_all_tabs();
} break;
case DEBUG_NEXT: {
if (debugger)
@ -913,6 +942,9 @@ void ScriptEditor::_menu_option(int p_option) {
case CLOSE_DOCS: {
_close_docs_tab();
} break;
case CLOSE_ALL: {
_close_all_tabs();
} break;
}
@ -1949,6 +1981,7 @@ void ScriptEditor::_bind_methods() {
ObjectTypeDB::bind_method("_menu_option",&ScriptEditor::_menu_option);
ObjectTypeDB::bind_method("_close_current_tab",&ScriptEditor::_close_current_tab);
ObjectTypeDB::bind_method("_close_docs_tab", &ScriptEditor::_close_docs_tab);
ObjectTypeDB::bind_method("_close_all_tabs", &ScriptEditor::_close_all_tabs);
ObjectTypeDB::bind_method("_editor_play",&ScriptEditor::_editor_play);
ObjectTypeDB::bind_method("_editor_pause",&ScriptEditor::_editor_pause);
ObjectTypeDB::bind_method("_editor_stop",&ScriptEditor::_editor_stop);
@ -2039,6 +2072,7 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) {
file_menu->get_popup()->add_separator();
file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/close_docs", TTR("Close Docs")), CLOSE_DOCS);
file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/close_file", TTR("Close"), KEY_MASK_CMD | KEY_W), FILE_CLOSE);
file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/close_all", TTR("Close All")), CLOSE_ALL);
file_menu->get_popup()->connect("item_pressed", this,"_menu_option");

View file

@ -132,6 +132,7 @@ class ScriptEditor : public VBoxContainer {
FILE_SAVE_THEME_AS,
FILE_CLOSE,
CLOSE_DOCS,
CLOSE_ALL,
FILE_TOOL_RELOAD,
FILE_TOOL_RELOAD_SOFT,
DEBUG_NEXT,
@ -220,6 +221,9 @@ class ScriptEditor : public VBoxContainer {
void _close_current_tab();
void _close_docs_tab();
void _close_all_tabs();
void _ask_close_current_unsaved_tab(ScriptEditorBase *current);
bool grab_focus_block;