Merge pull request #48578 from Calinou/editor-no-scene-ctrl-s-saves-script
Save the current script when pressing Ctrl + S if no scene is open
This commit is contained in:
commit
e9e601d18e
|
@ -2447,15 +2447,24 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
|
||||||
Node *scene = editor_data.get_edited_scene_root(scene_idx);
|
Node *scene = editor_data.get_edited_scene_root(scene_idx);
|
||||||
|
|
||||||
if (!scene) {
|
if (!scene) {
|
||||||
int saved = _save_external_resources();
|
if (p_option == FILE_SAVE_SCENE) {
|
||||||
String err_text;
|
// Pressing Ctrl + S saves the current script if a scene is currently open, but it won't if the scene has no root node.
|
||||||
if (saved > 0) {
|
// Work around this by explicitly saving the script in this case (similar to pressing Ctrl + Alt + S).
|
||||||
err_text = vformat(TTR("Saved %s modified resource(s)."), itos(saved));
|
ScriptEditor::get_singleton()->save_current_script();
|
||||||
} else {
|
}
|
||||||
err_text = TTR("A root node is required to save the scene.");
|
|
||||||
|
const int saved = _save_external_resources();
|
||||||
|
if (saved > 0) {
|
||||||
|
show_accept(
|
||||||
|
vformat(TTR("The current scene has no root node, but %d modified external resource(s) were saved anyway."), saved),
|
||||||
|
TTR("OK"));
|
||||||
|
} else if (p_option == FILE_SAVE_AS_SCENE) {
|
||||||
|
// Don't show this dialog when pressing Ctrl + S to avoid interfering with script saving.
|
||||||
|
show_accept(
|
||||||
|
TTR("A root node is required to save the scene. You can add a root node using the Scene tree dock."),
|
||||||
|
TTR("OK"));
|
||||||
}
|
}
|
||||||
|
|
||||||
show_accept(err_text, TTR("OK"));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -703,7 +703,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
|
// Do not try to save internal scripts, but prompt to save in-memory
|
||||||
// scripts which are not saved to disk yet (have empty path).
|
// scripts which are not saved to disk yet (have empty path).
|
||||||
if (script->get_path().find("local://") == -1 && script->get_path().find("::") == -1) {
|
if (script->get_path().find("local://") == -1 && script->get_path().find("::") == -1) {
|
||||||
_save_current_script();
|
save_current_script();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (script.is_valid()) {
|
if (script.is_valid()) {
|
||||||
|
@ -1101,59 +1101,6 @@ bool ScriptEditor::is_scripts_panel_toggled() {
|
||||||
return list_split->is_visible();
|
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) {
|
void ScriptEditor::_menu_option(int p_option) {
|
||||||
ScriptEditorBase *current = _get_current_editor();
|
ScriptEditorBase *current = _get_current_editor();
|
||||||
switch (p_option) {
|
switch (p_option) {
|
||||||
|
@ -1282,7 +1229,7 @@ void ScriptEditor::_menu_option(int p_option) {
|
||||||
if (current) {
|
if (current) {
|
||||||
switch (p_option) {
|
switch (p_option) {
|
||||||
case FILE_SAVE: {
|
case FILE_SAVE: {
|
||||||
_save_current_script();
|
save_current_script();
|
||||||
} break;
|
} break;
|
||||||
case FILE_SAVE_AS: {
|
case FILE_SAVE_AS: {
|
||||||
if (trim_trailing_whitespace_on_save) {
|
if (trim_trailing_whitespace_on_save) {
|
||||||
|
@ -2330,6 +2277,59 @@ bool ScriptEditor::edit(const RES &p_resource, int p_line, int p_col, bool p_gra
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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::save_all_scripts() {
|
void ScriptEditor::save_all_scripts() {
|
||||||
for (int i = 0; i < tab_container->get_child_count(); i++) {
|
for (int i = 0; i < tab_container->get_child_count(); i++) {
|
||||||
ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
|
ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
|
||||||
|
@ -2445,7 +2445,7 @@ void ScriptEditor::_add_callback(Object *p_obj, const String &p_function, const
|
||||||
script_list->select(script_list->find_metadata(i));
|
script_list->select(script_list->find_metadata(i));
|
||||||
|
|
||||||
// Save the current script so the changes can be picked up by an external editor.
|
// Save the current script so the changes can be picked up by an external editor.
|
||||||
_save_current_script();
|
save_current_script();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -312,7 +312,6 @@ class ScriptEditor : public PanelContainer {
|
||||||
|
|
||||||
String _get_debug_tooltip(const String &p_text, Node *_se);
|
String _get_debug_tooltip(const String &p_text, Node *_se);
|
||||||
|
|
||||||
void _save_current_script();
|
|
||||||
void _resave_scripts(const String &p_str);
|
void _resave_scripts(const String &p_str);
|
||||||
void _reload_scripts();
|
void _reload_scripts();
|
||||||
|
|
||||||
|
@ -464,6 +463,7 @@ public:
|
||||||
|
|
||||||
void get_breakpoints(List<String> *p_breakpoints);
|
void get_breakpoints(List<String> *p_breakpoints);
|
||||||
|
|
||||||
|
void save_current_script();
|
||||||
void save_all_scripts();
|
void save_all_scripts();
|
||||||
|
|
||||||
void set_window_layout(Ref<ConfigFile> p_layout);
|
void set_window_layout(Ref<ConfigFile> p_layout);
|
||||||
|
|
Loading…
Reference in New Issue