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.
(cherry picked from commit 0ade686601
)
This commit is contained in:
parent
f4e653d88f
commit
dc42ef2df9
2 changed files with 39 additions and 28 deletions
|
@ -551,7 +551,7 @@ void ScriptEditor::_close_tab(int p_idx, bool p_save, bool p_history_back) {
|
|||
if (p_save) {
|
||||
// Do not try to save internal scripts
|
||||
if (!script.is_valid() || !(script->get_path() == "" || script->get_path().find("local://") != -1 || script->get_path().find("::") != -1)) {
|
||||
_menu_option(FILE_SAVE);
|
||||
_save_current_script();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -948,6 +948,39 @@ 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<TextFile> text_file = resource;
|
||||
|
||||
if (text_file != nullptr) {
|
||||
current->apply_code();
|
||||
_save_text_file(text_file, text_file->get_path());
|
||||
return;
|
||||
}
|
||||
|
||||
editor->save_resource(resource);
|
||||
}
|
||||
|
||||
void ScriptEditor::_menu_option(int p_option) {
|
||||
ScriptEditorBase *current = _get_current_editor();
|
||||
switch (p_option) {
|
||||
|
@ -1089,33 +1122,7 @@ void ScriptEditor::_menu_option(int p_option) {
|
|||
if (current) {
|
||||
switch (p_option) {
|
||||
case FILE_SAVE: {
|
||||
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<TextFile> text_file = resource;
|
||||
if (text_file != nullptr) {
|
||||
current->apply_code();
|
||||
_save_text_file(text_file, text_file->get_path());
|
||||
break;
|
||||
}
|
||||
editor->save_resource(resource);
|
||||
|
||||
_save_current_script();
|
||||
} break;
|
||||
case FILE_SAVE_AS: {
|
||||
if (trim_trailing_whitespace_on_save) {
|
||||
|
@ -2284,6 +2291,9 @@ void ScriptEditor::_add_callback(Object *p_obj, const String &p_function, const
|
|||
|
||||
script_list->select(script_list->find_metadata(i));
|
||||
|
||||
// Save the current script so the changes can be picked up by an external editor.
|
||||
_save_current_script();
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -276,6 +276,7 @@ class ScriptEditor : public PanelContainer {
|
|||
|
||||
String _get_debug_tooltip(const String &p_text, Node *_se);
|
||||
|
||||
void _save_current_script();
|
||||
void _resave_scripts(const String &p_str);
|
||||
void _reload_scripts();
|
||||
|
||||
|
|
Loading…
Reference in a new issue