mirror of
https://github.com/godotengine/godot.git
synced 2025-10-20 00:13:30 +00:00
Optimized ScriptEditor initialization when many scripts are loaded
This change avoids the editor to freeze for several seconds when a project with lots of scripts is loaded in the editor. It focuses on a few heavy operations previously executed on all previously loaded scripts: - Initialize script resource (script validation/parsing) only on focus - ScriptTextEditor: code editor and edit menu are added to the scene only on focus - Add to recent scripts only when opening new scripts (load/save scene metadata)
This commit is contained in:
parent
89f57ae122
commit
e3765e97de
9 changed files with 226 additions and 124 deletions
|
@ -580,7 +580,7 @@ void ScriptEditor::_close_tab(int p_idx, bool p_save, bool p_history_back) {
|
|||
|
||||
Node *tselected = tab_container->get_child(selected);
|
||||
|
||||
ScriptEditorBase *current = Object::cast_to<ScriptEditorBase>(tab_container->get_child(selected));
|
||||
ScriptEditorBase *current = Object::cast_to<ScriptEditorBase>(tselected);
|
||||
if (current) {
|
||||
Ref<Script> script = current->get_edited_resource();
|
||||
if (p_save) {
|
||||
|
@ -666,8 +666,10 @@ void ScriptEditor::_close_docs_tab() {
|
|||
|
||||
void ScriptEditor::_copy_script_path() {
|
||||
ScriptEditorBase *se = _get_current_editor();
|
||||
RES script = se->get_edited_resource();
|
||||
OS::get_singleton()->set_clipboard(script->get_path());
|
||||
if (se) {
|
||||
RES script = se->get_edited_resource();
|
||||
OS::get_singleton()->set_clipboard(script->get_path());
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptEditor::_close_other_tabs() {
|
||||
|
@ -943,17 +945,19 @@ void ScriptEditor::_file_dialog_action(String p_file) {
|
|||
} break;
|
||||
case FILE_SAVE_AS: {
|
||||
ScriptEditorBase *current = _get_current_editor();
|
||||
if (current) {
|
||||
RES resource = current->get_edited_resource();
|
||||
String path = ProjectSettings::get_singleton()->localize_path(p_file);
|
||||
Error err = _save_text_file(resource, path);
|
||||
|
||||
String path = ProjectSettings::get_singleton()->localize_path(p_file);
|
||||
Error err = _save_text_file(current->get_edited_resource(), path);
|
||||
if (err != OK) {
|
||||
editor->show_accept(TTR("Error saving file!"), TTR("OK"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (err != OK) {
|
||||
editor->show_accept(TTR("Error saving file!"), TTR("OK"));
|
||||
return;
|
||||
resource->set_path(path);
|
||||
_update_script_names();
|
||||
}
|
||||
|
||||
((Resource *)current->get_edited_resource().ptr())->set_path(path);
|
||||
_update_script_names();
|
||||
} break;
|
||||
case THEME_SAVE_AS: {
|
||||
if (!EditorSettings::get_singleton()->save_text_editor_theme_as(p_file)) {
|
||||
|
@ -1170,13 +1174,14 @@ void ScriptEditor::_menu_option(int p_option) {
|
|||
}
|
||||
}
|
||||
|
||||
Ref<TextFile> text_file = current->get_edited_resource();
|
||||
RES resource = current->get_edited_resource();
|
||||
Ref<TextFile> text_file = resource;
|
||||
if (text_file != NULL) {
|
||||
current->apply_code();
|
||||
_save_text_file(text_file, text_file->get_path());
|
||||
break;
|
||||
}
|
||||
editor->save_resource(current->get_edited_resource());
|
||||
editor->save_resource(resource);
|
||||
|
||||
} break;
|
||||
case FILE_SAVE_AS: {
|
||||
|
@ -1194,7 +1199,8 @@ void ScriptEditor::_menu_option(int p_option) {
|
|||
}
|
||||
}
|
||||
|
||||
Ref<TextFile> text_file = current->get_edited_resource();
|
||||
RES resource = current->get_edited_resource();
|
||||
Ref<TextFile> text_file = resource;
|
||||
if (text_file != NULL) {
|
||||
file_dialog->set_mode(EditorFileDialog::MODE_SAVE_FILE);
|
||||
file_dialog->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
|
||||
|
@ -1210,8 +1216,8 @@ void ScriptEditor::_menu_option(int p_option) {
|
|||
break;
|
||||
}
|
||||
|
||||
editor->push_item(Object::cast_to<Object>(current->get_edited_resource().ptr()));
|
||||
editor->save_resource_as(current->get_edited_resource());
|
||||
editor->push_item(resource.ptr());
|
||||
editor->save_resource_as(resource);
|
||||
|
||||
} break;
|
||||
|
||||
|
@ -1615,9 +1621,11 @@ void ScriptEditor::ensure_select_current() {
|
|||
|
||||
ScriptEditorBase *se = _get_current_editor();
|
||||
if (se) {
|
||||
se->enable_editor();
|
||||
|
||||
if (!grab_focus_block && is_visible_in_tree())
|
||||
if (!grab_focus_block && is_visible_in_tree()) {
|
||||
se->ensure_focus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1954,6 +1962,11 @@ void ScriptEditor::_update_script_names() {
|
|||
script_list->select(index);
|
||||
script_name_label->set_text(sedata_filtered[i].name);
|
||||
script_icon->set_texture(sedata_filtered[i].icon);
|
||||
ScriptEditorBase *se = _get_current_editor();
|
||||
if (se) {
|
||||
se->enable_editor();
|
||||
_update_selected_editor_menu();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2131,6 +2144,8 @@ bool ScriptEditor::edit(const RES &p_resource, int p_line, int p_col, bool p_gra
|
|||
if ((script != NULL && se->get_edited_resource() == p_resource) || se->get_edited_resource()->get_path() == p_resource->get_path()) {
|
||||
|
||||
if (should_open) {
|
||||
se->enable_editor();
|
||||
|
||||
if (tab_container->get_current_tab() != i) {
|
||||
_go_to_tab(i);
|
||||
_update_script_names();
|
||||
|
@ -2159,6 +2174,8 @@ bool ScriptEditor::edit(const RES &p_resource, int p_line, int p_col, bool p_gra
|
|||
}
|
||||
ERR_FAIL_COND_V(!se, false);
|
||||
|
||||
se->set_edited_resource(p_resource);
|
||||
|
||||
if (p_resource->get_class_name() != StringName("VisualScript")) {
|
||||
bool highlighter_set = false;
|
||||
for (int i = 0; i < syntax_highlighters_func_count; i++) {
|
||||
|
@ -2176,7 +2193,11 @@ bool ScriptEditor::edit(const RES &p_resource, int p_line, int p_col, bool p_gra
|
|||
}
|
||||
|
||||
tab_container->add_child(se);
|
||||
se->set_edited_resource(p_resource);
|
||||
|
||||
if (p_grab_focus) {
|
||||
se->enable_editor();
|
||||
}
|
||||
|
||||
se->set_tooltip_request_func("_get_debug_tooltip", this);
|
||||
if (se->get_edit_menu()) {
|
||||
se->get_edit_menu()->hide();
|
||||
|
@ -2186,6 +2207,7 @@ bool ScriptEditor::edit(const RES &p_resource, int p_line, int p_col, bool p_gra
|
|||
|
||||
if (p_grab_focus) {
|
||||
_go_to_tab(tab_container->get_tab_count() - 1);
|
||||
_add_recent_script(p_resource->get_path());
|
||||
}
|
||||
|
||||
_sort_list_on_update = true;
|
||||
|
@ -2209,7 +2231,6 @@ bool ScriptEditor::edit(const RES &p_resource, int p_line, int p_col, bool p_gra
|
|||
}
|
||||
|
||||
notify_script_changed(p_resource);
|
||||
_add_recent_script(p_resource->get_path());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -2708,7 +2729,7 @@ void ScriptEditor::set_window_layout(Ref<ConfigFile> p_layout) {
|
|||
if (!scr.is_valid()) {
|
||||
continue;
|
||||
}
|
||||
if (!edit(scr)) {
|
||||
if (!edit(scr, false)) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
|
@ -2717,7 +2738,7 @@ void ScriptEditor::set_window_layout(Ref<ConfigFile> p_layout) {
|
|||
if (error != OK || !text_file.is_valid()) {
|
||||
continue;
|
||||
}
|
||||
if (!edit(text_file)) {
|
||||
if (!edit(text_file, false)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue