mirror of
https://github.com/godotengine/godot.git
synced 2025-10-24 18:33:36 +00:00
Merge pull request #33760 from nekomatata/script-editor-init-optimization
Optimized ScriptEditor initialization when many scripts are loaded
This commit is contained in:
commit
5700429e4e
9 changed files with 242 additions and 162 deletions
|
|
@ -696,7 +696,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) {
|
||||
|
|
@ -779,8 +779,10 @@ void ScriptEditor::_close_docs_tab() {
|
|||
|
||||
void ScriptEditor::_copy_script_path() {
|
||||
ScriptEditorBase *se = _get_current_editor();
|
||||
RES script = se->get_edited_resource();
|
||||
DisplayServer::get_singleton()->clipboard_set(script->get_path());
|
||||
if (se) {
|
||||
RES script = se->get_edited_resource();
|
||||
DisplayServer::get_singleton()->clipboard_set(script->get_path());
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptEditor::_close_other_tabs() {
|
||||
|
|
@ -1038,17 +1040,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)) {
|
||||
|
|
@ -1240,13 +1244,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 != nullptr) {
|
||||
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: {
|
||||
|
|
@ -1264,7 +1269,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 != nullptr) {
|
||||
file_dialog->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE);
|
||||
file_dialog->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
|
||||
|
|
@ -1280,8 +1286,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;
|
||||
|
||||
|
|
@ -1632,6 +1638,8 @@ void ScriptEditor::ensure_select_current() {
|
|||
if (tab_container->get_child_count() && tab_container->get_current_tab() >= 0) {
|
||||
ScriptEditorBase *se = _get_current_editor();
|
||||
if (se) {
|
||||
se->enable_editor();
|
||||
|
||||
if (!grab_focus_block && is_visible_in_tree()) {
|
||||
se->ensure_focus();
|
||||
}
|
||||
|
|
@ -1976,6 +1984,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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2150,6 +2163,8 @@ bool ScriptEditor::edit(const RES &p_resource, int p_line, int p_col, bool p_gra
|
|||
|
||||
if ((script != nullptr && 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();
|
||||
|
|
@ -2180,6 +2195,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.size(); i++) {
|
||||
|
|
@ -2200,7 +2217,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();
|
||||
|
|
@ -2210,6 +2231,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;
|
||||
|
|
@ -2234,7 +2256,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;
|
||||
}
|
||||
|
||||
|
|
@ -2706,7 +2727,7 @@ void ScriptEditor::set_window_layout(Ref<ConfigFile> p_layout) {
|
|||
if (!scr.is_valid()) {
|
||||
continue;
|
||||
}
|
||||
if (!edit(scr)) {
|
||||
if (!edit(scr, false)) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
|
|
@ -2715,7 +2736,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