summaryrefslogtreecommitdiffstats
path: root/editor/editor_file_system.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/editor_file_system.cpp')
-rw-r--r--editor/editor_file_system.cpp109
1 files changed, 96 insertions, 13 deletions
diff --git a/editor/editor_file_system.cpp b/editor/editor_file_system.cpp
index b1b64b5d60..2b51071b15 100644
--- a/editor/editor_file_system.cpp
+++ b/editor/editor_file_system.cpp
@@ -32,6 +32,7 @@
#include "core/config/project_settings.h"
#include "core/extension/gdextension_manager.h"
+#include "core/io/dir_access.h"
#include "core/io/file_access.h"
#include "core/io/resource_saver.h"
#include "core/object/worker_thread_pool.h"
@@ -42,6 +43,7 @@
#include "editor/editor_paths.h"
#include "editor/editor_resource_preview.h"
#include "editor/editor_settings.h"
+#include "editor/plugins/script_editor_plugin.h"
#include "editor/project_settings_editor.h"
#include "scene/resources/packed_scene.h"
@@ -806,18 +808,11 @@ bool EditorFileSystem::_update_scan_actions() {
case ItemAction::ACTION_FILE_RELOAD: {
int idx = ia.dir->find_file_index(ia.file);
ERR_CONTINUE(idx == -1);
- String full_path = ia.dir->get_file_path(idx);
- const EditorFileSystemDirectory::FileInfo *fi = ia.dir->files[idx];
- if (ClassDB::is_parent_class(fi->type, SNAME("Script"))) {
- _queue_update_script_class(full_path, fi->type, fi->script_class_name, fi->script_class_extends, fi->script_class_icon_path);
- }
- if (fi->type == SNAME("PackedScene")) {
- _queue_update_scene_groups(full_path);
+ // Only reloads the resources that are already loaded.
+ if (ResourceCache::has(ia.dir->get_file_path(idx))) {
+ reloads.push_back(ia.dir->get_file_path(idx));
}
-
- reloads.push_back(full_path);
-
} break;
}
@@ -841,7 +836,7 @@ bool EditorFileSystem::_update_scan_actions() {
}
}
- if (reimports.size()) {
+ if (!reimports.is_empty()) {
if (_scan_import_support(reimports)) {
return true;
}
@@ -852,6 +847,11 @@ bool EditorFileSystem::_update_scan_actions() {
ResourceUID::get_singleton()->update_cache();
}
+ if (!reloads.is_empty()) {
+ // Update global class names, dependencies, etc...
+ update_files(reloads);
+ }
+
if (first_scan) {
//only on first scan this is valid and updated, then settings changed.
revalidate_import_files = false;
@@ -1142,6 +1142,14 @@ void EditorFileSystem::_process_file_system(const ScannedDirectory *p_scan_dir,
if (fi->uid != ResourceUID::INVALID_ID) {
if (ResourceUID::get_singleton()->has_id(fi->uid)) {
+ // Restrict UID dupe warning to first-scan since we know there are no file moves going on yet.
+ if (first_scan) {
+ // Warn if we detect files with duplicate UIDs.
+ const String other_path = ResourceUID::get_singleton()->get_id_path(fi->uid);
+ if (other_path != path) {
+ WARN_PRINT(vformat("UID duplicate detected between %s and %s.", path, other_path));
+ }
+ }
ResourceUID::get_singleton()->set_id(fi->uid, path);
} else {
ResourceUID::get_singleton()->add_id(fi->uid, path);
@@ -1341,8 +1349,7 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir, ScanPr
ia.file = p_dir->files[i]->file;
scan_actions.push_back(ia);
}
- } else if (ResourceCache::has(path)) { //test for potential reload
-
+ } else {
uint64_t mt = FileAccess::get_modified_time(path);
if (mt != p_dir->files[i]->modified_time) {
@@ -1967,13 +1974,23 @@ void EditorFileSystem::_update_script_documentation() {
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()) {
+ bool should_reload_script = _should_reload_script(path);
Ref<Script> scr = ResourceLoader::load(path);
if (scr.is_null()) {
continue;
}
+ if (should_reload_script) {
+ // Reloading the script from disk. Otherwise, the ResourceLoader::load will
+ // return the last loaded version of the script (without the modifications).
+ scr->reload_from_file();
+ }
Vector<DocData::ClassDoc> docs = scr->get_documentation();
for (int j = 0; j < docs.size(); j++) {
EditorHelp::get_doc_data()->add_doc(docs[j]);
+ if (!first_scan) {
+ // Update the documentation in the Script Editor if it is open.
+ ScriptEditor::get_singleton()->update_doc(docs[j].name);
+ }
}
}
}
@@ -1988,6 +2005,25 @@ void EditorFileSystem::_update_script_documentation() {
update_script_paths_documentation.clear();
}
+bool EditorFileSystem::_should_reload_script(const String &p_path) {
+ if (first_scan) {
+ return false;
+ }
+
+ Ref<Script> scr = ResourceCache::get_ref(p_path);
+ if (scr.is_null()) {
+ // Not a script or not already loaded.
+ return false;
+ }
+
+ // Scripts are reloaded via the script editor if they are currently opened.
+ if (ScriptEditor::get_singleton()->get_open_scripts().has(scr)) {
+ return false;
+ }
+
+ return true;
+}
+
void EditorFileSystem::_process_update_pending() {
_update_script_classes();
// Parse documentation second, as it requires the class names to be loaded
@@ -3057,6 +3093,53 @@ void EditorFileSystem::move_group_file(const String &p_path, const String &p_new
}
}
+Error EditorFileSystem::make_dir_recursive(const String &p_path, const String &p_base_path) {
+ Error err;
+ Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
+ if (!p_base_path.is_empty()) {
+ err = da->change_dir(p_base_path);
+ ERR_FAIL_COND_V_MSG(err != OK, err, "Cannot open base directory '" + p_base_path + "'.");
+ }
+
+ if (da->dir_exists(p_path)) {
+ return ERR_ALREADY_EXISTS;
+ }
+
+ err = da->make_dir_recursive(p_path);
+ if (err != OK) {
+ return err;
+ }
+
+ const String path = da->get_current_dir();
+ EditorFileSystemDirectory *parent = get_filesystem_path(path);
+ ERR_FAIL_NULL_V(parent, ERR_FILE_NOT_FOUND);
+
+ const PackedStringArray folders = p_path.trim_prefix(path).trim_suffix("/").split("/");
+ bool first = true;
+
+ for (const String &folder : folders) {
+ const int current = parent->find_dir_index(folder);
+ if (current > -1) {
+ parent = parent->get_subdir(current);
+ continue;
+ }
+
+ EditorFileSystemDirectory *efd = memnew(EditorFileSystemDirectory);
+ efd->parent = parent;
+ efd->name = folder;
+ parent->subdirs.push_back(efd);
+
+ if (first) {
+ parent->subdirs.sort_custom<DirectoryComparator>();
+ first = false;
+ }
+ parent = efd;
+ }
+
+ emit_signal(SNAME("filesystem_changed"));
+ return OK;
+}
+
ResourceUID::ID EditorFileSystem::_resource_saver_get_resource_id_for_path(const String &p_path, bool p_generate) {
if (!p_path.is_resource_file() || p_path.begins_with(ProjectSettings::get_singleton()->get_project_data_path())) {
// Saved externally (configuration file) or internal file, do not assign an ID.