summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2024-09-16 13:34:09 +0200
committerRémi Verschelde <rverschelde@gmail.com>2024-09-16 13:34:09 +0200
commit5b2eececfdf32508ca83539b5cb4b15d214750e2 (patch)
treec71eab30ac121ad8a318e37a61dba6964731b7e9
parent8c6210a3ebdfe14cd60620a3cf202e53ed963bad (diff)
parentc981e8b76554ba322aa36d756032d8d9131bc0bd (diff)
downloadredot-engine-5b2eececfdf32508ca83539b5cb4b15d214750e2.tar.gz
Merge pull request #93372 from KoBeWi/instant_folders,_like_instant_noodles,_but_for_storing_files
Don't rescan filesystem when adding new directory
-rw-r--r--editor/editor_file_system.cpp29
-rw-r--r--editor/editor_file_system.h8
-rw-r--r--editor/filesystem_dock.cpp11
-rw-r--r--editor/filesystem_dock.h1
4 files changed, 48 insertions, 1 deletions
diff --git a/editor/editor_file_system.cpp b/editor/editor_file_system.cpp
index b1b64b5d60..0cb50cee8f 100644
--- a/editor/editor_file_system.cpp
+++ b/editor/editor_file_system.cpp
@@ -3057,6 +3057,35 @@ void EditorFileSystem::move_group_file(const String &p_path, const String &p_new
}
}
+void EditorFileSystem::add_new_directory(const String &p_path) {
+ String path = p_path.get_base_dir();
+ EditorFileSystemDirectory *parent = filesystem;
+ int base = p_path.count("/");
+ int max_bit = base + 1;
+
+ while (path != "res://") {
+ EditorFileSystemDirectory *dir = get_filesystem_path(path);
+ if (dir) {
+ parent = dir;
+ break;
+ }
+ path = path.get_base_dir();
+ base--;
+ }
+
+ for (int i = base; i < max_bit; i++) {
+ EditorFileSystemDirectory *efd = memnew(EditorFileSystemDirectory);
+ efd->parent = parent;
+ efd->name = p_path.get_slice("/", i);
+ parent->subdirs.push_back(efd);
+
+ if (i == base) {
+ parent->subdirs.sort_custom<DirectoryComparator>();
+ }
+ parent = efd;
+ }
+}
+
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.
diff --git a/editor/editor_file_system.h b/editor/editor_file_system.h
index 9adab1ed24..be299800d8 100644
--- a/editor/editor_file_system.h
+++ b/editor/editor_file_system.h
@@ -224,6 +224,12 @@ class EditorFileSystem : public Node {
void increment();
};
+ struct DirectoryComparator {
+ bool operator()(const EditorFileSystemDirectory *p_a, const EditorFileSystemDirectory *p_b) const {
+ return p_a->name.filenocasecmp_to(p_b->name) < 0;
+ }
+ };
+
void _save_filesystem_cache();
void _save_filesystem_cache(EditorFileSystemDirectory *p_dir, Ref<FileAccess> p_file);
@@ -364,6 +370,8 @@ public:
bool is_group_file(const String &p_path) const;
void move_group_file(const String &p_path, const String &p_new_path);
+ void add_new_directory(const String &p_path);
+
static bool _should_skip_directory(const String &p_path);
void add_import_format_support_query(Ref<EditorFileSystemImportFormatSupportQuery> p_query);
diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp
index 25725635e3..faaab4aeec 100644
--- a/editor/filesystem_dock.cpp
+++ b/editor/filesystem_dock.cpp
@@ -1318,6 +1318,15 @@ void FileSystemDock::_fs_changed() {
set_process(false);
}
+void FileSystemDock::_directory_created(const String &p_path) {
+ if (!DirAccess::exists(p_path)) {
+ return;
+ }
+ EditorFileSystem::get_singleton()->add_new_directory(p_path);
+ _update_tree(get_uncollapsed_paths());
+ _update_file_list(true);
+}
+
void FileSystemDock::_set_scanning_mode() {
button_hist_prev->set_disabled(true);
button_hist_next->set_disabled(true);
@@ -4175,7 +4184,7 @@ FileSystemDock::FileSystemDock() {
make_dir_dialog = memnew(DirectoryCreateDialog);
add_child(make_dir_dialog);
- make_dir_dialog->connect("dir_created", callable_mp(this, &FileSystemDock::_rescan).unbind(1));
+ make_dir_dialog->connect("dir_created", callable_mp(this, &FileSystemDock::_directory_created));
make_scene_dialog = memnew(SceneCreateDialog);
add_child(make_scene_dialog);
diff --git a/editor/filesystem_dock.h b/editor/filesystem_dock.h
index 2f54cb91db..907f843523 100644
--- a/editor/filesystem_dock.h
+++ b/editor/filesystem_dock.h
@@ -260,6 +260,7 @@ private:
void _toggle_file_display();
void _set_file_display(bool p_active);
void _fs_changed();
+ void _directory_created(const String &p_path);
void _select_file(const String &p_path, bool p_select_in_favorites = false);
void _tree_activate_file();