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.
This commit is contained in:
parent
758bccf364
commit
0ade686601
|
@ -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<TextFile> text_file = resource;
|
||||
Ref<Script> script = resource;
|
||||
|
||||
if (text_file != nullptr) {
|
||||
current->apply_code();
|
||||
_save_text_file(text_file, text_file->get_path());
|
||||
return;
|
||||
}
|
||||
|
||||
if (script != nullptr) {
|
||||
const Vector<DocData::ClassDoc> &documentations = script->get_documentation();
|
||||
for (int j = 0; j < documentations.size(); j++) {
|
||||
const DocData::ClassDoc &doc = documentations.get(j);
|
||||
if (EditorHelp::get_doc_data()->has_doc(doc.name)) {
|
||||
EditorHelp::get_doc_data()->remove_doc(doc.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
editor->save_resource(resource);
|
||||
|
||||
if (script != nullptr) {
|
||||
const Vector<DocData::ClassDoc> &documentations = script->get_documentation();
|
||||
for (int j = 0; j < documentations.size(); j++) {
|
||||
const DocData::ClassDoc &doc = documentations.get(j);
|
||||
EditorHelp::get_doc_data()->add_doc(doc);
|
||||
update_doc(doc.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptEditor::_menu_option(int p_option) {
|
||||
ScriptEditorBase *current = _get_current_editor();
|
||||
switch (p_option) {
|
||||
|
@ -1224,55 +1277,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;
|
||||
Ref<Script> script = resource;
|
||||
|
||||
if (text_file != nullptr) {
|
||||
current->apply_code();
|
||||
_save_text_file(text_file, text_file->get_path());
|
||||
break;
|
||||
}
|
||||
|
||||
if (script != nullptr) {
|
||||
const Vector<DocData::ClassDoc> &documentations = script->get_documentation();
|
||||
for (int j = 0; j < documentations.size(); j++) {
|
||||
const DocData::ClassDoc &doc = documentations.get(j);
|
||||
if (EditorHelp::get_doc_data()->has_doc(doc.name)) {
|
||||
EditorHelp::get_doc_data()->remove_doc(doc.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
editor->save_resource(resource);
|
||||
|
||||
if (script != nullptr) {
|
||||
const Vector<DocData::ClassDoc> &documentations = script->get_documentation();
|
||||
for (int j = 0; j < documentations.size(); j++) {
|
||||
const DocData::ClassDoc &doc = documentations.get(j);
|
||||
EditorHelp::get_doc_data()->add_doc(doc);
|
||||
update_doc(doc.name);
|
||||
}
|
||||
}
|
||||
|
||||
_save_current_script();
|
||||
} break;
|
||||
case FILE_SAVE_AS: {
|
||||
if (trim_trailing_whitespace_on_save) {
|
||||
|
@ -2439,6 +2444,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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -312,6 +312,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 New Issue