Always soft-reload scripts

This commit is contained in:
kobewi 2021-11-19 17:45:16 +01:00
parent 4a127fd2cc
commit ca4c63d654
3 changed files with 18 additions and 11 deletions

View File

@ -962,7 +962,7 @@ void ScriptEditor::_reload_scripts() {
ERR_CONTINUE(!rel_script.is_valid());
script->set_source_code(rel_script->get_source_code());
script->set_last_modified_time(rel_script->get_last_modified_time());
script->reload();
script->reload(true);
}
Ref<TextFile> text_file = edited_res;
@ -1366,9 +1366,17 @@ void ScriptEditor::_menu_option(int p_option) {
}
} break;
case FILE_TOOL_RELOAD:
case FILE_TOOL_RELOAD_SOFT: {
current->reload(p_option == FILE_TOOL_RELOAD_SOFT);
Ref<Script> scr = current->get_edited_resource();
if (scr == nullptr || scr.is_null()) {
EditorNode::get_singleton()->show_warning(TTR("Can't obtain the script for reloading."));
break;
}
if (!scr->is_tool()) {
EditorNode::get_singleton()->show_warning(TTR("Reload only takes effect on tool scripts."));
return;
}
scr->reload(true);
} break;
case FILE_RUN: {
@ -1377,6 +1385,10 @@ void ScriptEditor::_menu_option(int p_option) {
EditorNode::get_singleton()->show_warning(TTR("Can't obtain the script for running."));
break;
}
if (!scr->is_tool()) {
EditorNode::get_singleton()->show_warning(TTR("Script is not in tool mode, will not be able to run."));
return;
}
current->apply_code();
Error err = scr->reload(false); //hard reload script before running always
@ -1385,10 +1397,6 @@ void ScriptEditor::_menu_option(int p_option) {
EditorNode::get_singleton()->show_warning(TTR("Script failed reloading, check console for errors."));
return;
}
if (!scr->is_tool()) {
EditorNode::get_singleton()->show_warning(TTR("Script is not in tool mode, will not be able to run."));
return;
}
if (!ClassDB::is_parent_class(scr->get_instance_base_type(), "EditorScript")) {
EditorNode::get_singleton()->show_warning(TTR("To run this script, it must inherit EditorScript and be set to tool mode."));
@ -3035,8 +3043,8 @@ void ScriptEditor::_make_script_list_context_menu() {
if (se) {
Ref<Script> scr = se->get_edited_resource();
if (scr != nullptr) {
context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/reload_script_soft"), FILE_TOOL_RELOAD_SOFT);
if (!scr.is_null() && scr->is_tool()) {
context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/reload_script_soft"), FILE_TOOL_RELOAD_SOFT);
context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/run_file"), FILE_RUN);
context_menu->add_separator();
}
@ -3699,7 +3707,7 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) {
file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/save_as", TTR("Save As...")), FILE_SAVE_AS);
file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/save_all", TTR("Save All"), KeyModifierMask::SHIFT | KeyModifierMask::ALT | Key::S), FILE_SAVE_ALL);
file_menu->get_popup()->add_separator();
file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/reload_script_soft", TTR("Soft Reload Script"), KeyModifierMask::CMD | KeyModifierMask::ALT | Key::R), FILE_TOOL_RELOAD_SOFT);
file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/reload_script_soft", TTR("Soft Reload Tool Script"), KeyModifierMask::CMD | KeyModifierMask::ALT | Key::R), FILE_TOOL_RELOAD_SOFT);
file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/copy_path", TTR("Copy Script Path")), FILE_COPY_PATH);
file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/show_in_file_system", TTR("Show in FileSystem")), SHOW_IN_FILE_SYSTEM);
file_menu->get_popup()->add_separator();

View File

@ -205,7 +205,6 @@ class ScriptEditor : public PanelContainer {
TOGGLE_SCRIPTS_PANEL,
SHOW_IN_FILE_SYSTEM,
FILE_COPY_PATH,
FILE_TOOL_RELOAD,
FILE_TOOL_RELOAD_SOFT,
SEARCH_IN_FILES,
REPLACE_IN_FILES,

View File

@ -2339,7 +2339,7 @@ Error ResourceFormatSaverGDScript::save(const String &p_path, const RES &p_resou
memdelete(file);
if (ScriptServer::is_reload_scripts_on_save_enabled()) {
GDScriptLanguage::get_singleton()->reload_tool_script(p_resource, false);
GDScriptLanguage::get_singleton()->reload_tool_script(p_resource, true);
}
return OK;