diff options
Diffstat (limited to 'editor/editor_file_system.cpp')
-rw-r--r-- | editor/editor_file_system.cpp | 139 |
1 files changed, 87 insertions, 52 deletions
diff --git a/editor/editor_file_system.cpp b/editor/editor_file_system.cpp index 9c056ffdd9..a9b4c08698 100644 --- a/editor/editor_file_system.cpp +++ b/editor/editor_file_system.cpp @@ -602,10 +602,19 @@ bool EditorFileSystem::_update_scan_actions() { fs_changed = true; + if (ClassDB::is_parent_class(ia.new_file->type, SNAME("Script"))) { + _queue_update_script_class(ia.dir->get_file_path(idx)); + } + } break; case ItemAction::ACTION_FILE_REMOVE: { int idx = ia.dir->find_file_index(ia.file); ERR_CONTINUE(idx == -1); + + if (ClassDB::is_parent_class(ia.dir->files[idx]->type, SNAME("Script"))) { + _queue_update_script_class(ia.dir->get_file_path(idx)); + } + _delete_internal_files(ia.dir->files[idx]->file); memdelete(ia.dir->files[idx]); ia.dir->files.remove_at(idx); @@ -640,6 +649,10 @@ bool EditorFileSystem::_update_scan_actions() { ERR_CONTINUE(idx == -1); String full_path = ia.dir->get_file_path(idx); + if (ClassDB::is_parent_class(ia.dir->files[idx]->type, SNAME("Script"))) { + _queue_update_script_class(full_path); + } + reloads.push_back(full_path); } break; @@ -708,9 +721,9 @@ void EditorFileSystem::scan() { new_filesystem = nullptr; _update_scan_actions(); scanning = false; + _update_pending_script_classes(); emit_signal(SNAME("filesystem_changed")); emit_signal(SNAME("sources_changed"), sources_changed.size() > 0); - _queue_update_script_classes(); first_scan = false; } else { ERR_FAIL_COND(thread.is_started()); @@ -911,6 +924,10 @@ void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir, Ref<DirAc fi->modified_time = mt; fi->import_modified_time = 0; fi->import_valid = true; + + if (ClassDB::is_parent_class(fi->type, SNAME("Script"))) { + _queue_update_script_class(path); + } } } @@ -922,20 +939,6 @@ void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir, Ref<DirAc } } - for (int i = 0; i < ScriptServer::get_language_count(); i++) { - ScriptLanguage *lang = ScriptServer::get_language(i); - if (lang->supports_documentation() && fi->type == lang->get_type()) { - Ref<Script> scr = ResourceLoader::load(path); - if (scr == nullptr) { - continue; - } - Vector<DocData::ClassDoc> docs = scr->get_documentation(); - for (int j = 0; j < docs.size(); j++) { - EditorHelp::get_doc_data()->add_doc(docs[j]); - } - } - } - p_dir->files.push_back(fi); p_progress.update(idx, total); } @@ -1176,7 +1179,9 @@ void EditorFileSystem::scan_changes() { sp.low = 0; scan_total = 0; _scan_fs_changes(filesystem, sp); - if (_update_scan_actions()) { + bool changed = _update_scan_actions(); + _update_pending_script_classes(); + if (changed) { emit_signal(SNAME("filesystem_changed")); } } @@ -1225,11 +1230,12 @@ void EditorFileSystem::_notification(int p_what) { set_process(false); thread_sources.wait_to_finish(); - if (_update_scan_actions()) { + bool changed = _update_scan_actions(); + _update_pending_script_classes(); + if (changed) { emit_signal(SNAME("filesystem_changed")); } emit_signal(SNAME("sources_changed"), sources_changed.size() > 0); - _queue_update_script_classes(); first_scan = false; } } else if (!scanning && thread.is_started()) { @@ -1242,9 +1248,9 @@ void EditorFileSystem::_notification(int p_what) { new_filesystem = nullptr; thread.wait_to_finish(); _update_scan_actions(); + _update_pending_script_classes(); emit_signal(SNAME("filesystem_changed")); emit_signal(SNAME("sources_changed"), sources_changed.size() > 0); - _queue_update_script_classes(); first_scan = false; } @@ -1491,40 +1497,60 @@ String EditorFileSystem::_get_global_script_class(const String &p_type, const St return String(); } -void EditorFileSystem::_scan_script_classes(EditorFileSystemDirectory *p_dir) { - int filecount = p_dir->files.size(); - const EditorFileSystemDirectory::FileInfo *const *files = p_dir->files.ptr(); - for (int i = 0; i < filecount; i++) { - if (files[i]->script_class_name.is_empty()) { +void EditorFileSystem::_update_script_classes() { + update_script_mutex.lock(); + + for (const String &path : update_script_paths) { + ScriptServer::remove_global_class_by_path(path); // First remove, just in case it changed + + int index = -1; + EditorFileSystemDirectory *efd = find_file(path, &index); + + if (!efd || index < 0) { + // The file was removed continue; } - String lang; - for (int j = 0; j < ScriptServer::get_language_count(); j++) { - if (ScriptServer::get_language(j)->handles_global_class_type(files[i]->type)) { - lang = ScriptServer::get_language(j)->get_name(); + if (!efd->files[index]->script_class_name.is_empty()) { + String lang; + for (int j = 0; j < ScriptServer::get_language_count(); j++) { + if (ScriptServer::get_language(j)->handles_global_class_type(efd->files[index]->type)) { + lang = ScriptServer::get_language(j)->get_name(); + } } + if (lang.is_empty()) { + continue; // No lang found that can handle this global class + } + + ScriptServer::add_global_class(efd->files[index]->script_class_name, efd->files[index]->script_class_extends, lang, path); + EditorNode::get_editor_data().script_class_set_icon_path(efd->files[index]->script_class_name, efd->files[index]->script_class_icon_path); + EditorNode::get_editor_data().script_class_set_name(efd->files[index]->file, efd->files[index]->script_class_name); } - ScriptServer::add_global_class(files[i]->script_class_name, files[i]->script_class_extends, lang, p_dir->get_file_path(i)); - EditorNode::get_editor_data().script_class_set_icon_path(files[i]->script_class_name, files[i]->script_class_icon_path); - EditorNode::get_editor_data().script_class_set_name(files[i]->file, files[i]->script_class_name); } - for (int i = 0; i < p_dir->get_subdir_count(); i++) { - _scan_script_classes(p_dir->get_subdir(i)); - } -} -void EditorFileSystem::update_script_classes() { - if (!update_script_classes_queued.is_set()) { - return; - } + // Parse documentation second, as it requires the class names to be correct and registered + for (const String &path : update_script_paths) { + int index = -1; + EditorFileSystemDirectory *efd = find_file(path, &index); - update_script_classes_queued.clear(); - ScriptServer::global_classes_clear(); - if (get_filesystem()) { - _scan_script_classes(get_filesystem()); + for (int i = 0; i < ScriptServer::get_language_count(); i++) { + ScriptLanguage *lang = ScriptServer::get_language(i); + if (lang->supports_documentation() && efd->files[index]->type == lang->get_type()) { + Ref<Script> scr = ResourceLoader::load(path); + if (scr.is_null()) { + continue; + } + Vector<DocData::ClassDoc> docs = scr->get_documentation(); + for (int j = 0; j < docs.size(); j++) { + EditorHelp::get_doc_data()->add_doc(docs[j]); + } + } + } } + update_script_paths.clear(); + update_script_mutex.unlock(); + ScriptServer::save_global_classes(); EditorNode::get_editor_data().script_class_save_icon_paths(); emit_signal("script_classes_updated"); @@ -1538,13 +1564,16 @@ void EditorFileSystem::update_script_classes() { ResourceSaver::add_custom_savers(); } -void EditorFileSystem::_queue_update_script_classes() { - if (update_script_classes_queued.is_set()) { - return; +void EditorFileSystem::_update_pending_script_classes() { + if (!update_script_paths.is_empty()) { + _update_script_classes(); } +} - update_script_classes_queued.set(); - call_deferred(SNAME("update_script_classes")); +void EditorFileSystem::_queue_update_script_class(const String &p_path) { + update_script_mutex.lock(); + update_script_paths.insert(p_path); + update_script_mutex.unlock(); } void EditorFileSystem::update_file(const String &p_file) { @@ -1566,12 +1595,16 @@ void EditorFileSystem::update_file(const String &p_file) { ResourceUID::get_singleton()->remove_id(fs->files[cpos]->uid); } } + if (ClassDB::is_parent_class(fs->files[cpos]->type, SNAME("Script"))) { + _queue_update_script_class(p_file); + } + memdelete(fs->files[cpos]); fs->files.remove_at(cpos); } + _update_pending_script_classes(); call_deferred(SNAME("emit_signal"), "filesystem_changed"); //update later - _queue_update_script_classes(); return; } @@ -1631,8 +1664,12 @@ void EditorFileSystem::update_file(const String &p_file) { // Update preview EditorResourcePreview::get_singleton()->check_for_invalidation(p_file); + if (ClassDB::is_parent_class(fs->files[cpos]->type, SNAME("Script"))) { + _queue_update_script_class(p_file); + } + + _update_pending_script_classes(); call_deferred(SNAME("emit_signal"), "filesystem_changed"); //update later - _queue_update_script_classes(); } HashSet<String> EditorFileSystem::get_valid_extensions() const { @@ -2414,7 +2451,6 @@ void EditorFileSystem::_bind_methods() { ClassDB::bind_method(D_METHOD("update_file", "path"), &EditorFileSystem::update_file); ClassDB::bind_method(D_METHOD("get_filesystem_path", "path"), &EditorFileSystem::get_filesystem_path); ClassDB::bind_method(D_METHOD("get_file_type", "path"), &EditorFileSystem::get_file_type); - ClassDB::bind_method(D_METHOD("update_script_classes"), &EditorFileSystem::update_script_classes); ClassDB::bind_method(D_METHOD("reimport_files", "files"), &EditorFileSystem::reimport_files); ADD_SIGNAL(MethodInfo("filesystem_changed")); @@ -2474,7 +2510,6 @@ EditorFileSystem::EditorFileSystem() { using_fat32_or_exfat = (da->get_filesystem_type() == "FAT32" || da->get_filesystem_type() == "exFAT"); scan_total = 0; - update_script_classes_queued.clear(); MessageQueue::get_singleton()->push_callable(callable_mp(ResourceUID::get_singleton(), &ResourceUID::clear)); // Will be updated on scan. ResourceSaver::set_get_resource_id_for_path(_resource_saver_get_resource_id_for_path); } |