From 0ade6866014b9d4bf8469b4fe06e6a7ef9e82592 Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Tue, 29 Sep 2020 23:00:34 +0200 Subject: [PATCH] Save the current script when adding a new method via signal connection This makes it possible for external editors to pick up the changes. Most modern editors should reload the file automatically, but some older/lightweight editors may ask the user instead (or only warn after trying to save in the external editor). This closes #41283. --- editor/plugins/script_editor_plugin.cpp | 108 +++++++++++++----------- editor/plugins/script_editor_plugin.h | 1 + 2 files changed, 59 insertions(+), 50 deletions(-) diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 58e6717a3d9..ed34a6182e4 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -698,7 +698,7 @@ void ScriptEditor::_close_tab(int p_idx, bool p_save, bool p_history_back) { // Do not try to save internal scripts, but prompt to save in-memory // scripts which are not saved to disk yet (have empty path). if (script->get_path().find("local://") == -1 && script->get_path().find("::") == -1) { - _menu_option(FILE_SAVE); + _save_current_script(); } } if (script.is_valid()) { @@ -1096,6 +1096,59 @@ bool ScriptEditor::is_scripts_panel_toggled() { return list_split->is_visible(); } +void ScriptEditor::_save_current_script() { + ScriptEditorBase *current = _get_current_editor(); + + if (_test_script_times_on_disk()) { + return; + } + + if (trim_trailing_whitespace_on_save) { + current->trim_trailing_whitespace(); + } + + current->insert_final_newline(); + + if (convert_indent_on_save) { + if (use_space_indentation) { + current->convert_indent_to_spaces(); + } else { + current->convert_indent_to_tabs(); + } + } + + RES resource = current->get_edited_resource(); + Ref text_file = resource; + Ref