From 5ff8f21ff3c9767666fc289fadeeee65e35840d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A3=8E=E9=9D=92=E5=B1=B1?= Date: Thu, 4 Dec 2025 10:36:39 +0800 Subject: [PATCH] Fix the issue of no scan after dir creation and/or deletion When `EditorFileDialog` creates/deletes a directory during interactive operation, it needs to notify `EditorFileSystem` to scan and detect the filesystem change. --- editor/gui/editor_file_dialog.cpp | 21 +++++++++++++++++++++ editor/gui/editor_file_dialog.h | 1 + scene/gui/file_dialog.cpp | 8 ++++++-- scene/gui/file_dialog.h | 1 + 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/editor/gui/editor_file_dialog.cpp b/editor/gui/editor_file_dialog.cpp index fe7ab8b5b3d..8cf5bbb7a4e 100644 --- a/editor/gui/editor_file_dialog.cpp +++ b/editor/gui/editor_file_dialog.cpp @@ -30,6 +30,7 @@ #include "editor_file_dialog.h" +#include "core/config/project_settings.h" #include "editor/docks/filesystem_dock.h" #include "editor/file_system/dependency_editor.h" #include "editor/settings/editor_settings.h" @@ -92,6 +93,26 @@ void EditorFileDialog::_validate_property(PropertyInfo &p_property) const { } } +void EditorFileDialog::_dir_contents_changed() { + bool scan_required = false; + switch (get_access()) { + case FileDialog::ACCESS_RESOURCES: { + scan_required = true; + } break; + case FileDialog::ACCESS_USERDATA: { + // Directories within the project dir are unlikely to be accessed. + } break; + case FileDialog::ACCESS_FILESYSTEM: { + // Directories within the project dir may still be accessed. + const String localized_path = ProjectSettings::get_singleton()->localize_path(get_current_dir()); + scan_required = localized_path.is_resource_file(); + } break; + } + if (scan_required) { + EditorFileSystem::get_singleton()->scan_changes(); + } +} + void EditorFileDialog::_notification(int p_what) { switch (p_what) { case NOTIFICATION_VISIBILITY_CHANGED: { diff --git a/editor/gui/editor_file_dialog.h b/editor/gui/editor_file_dialog.h index b8e21974520..12c2129d63a 100644 --- a/editor/gui/editor_file_dialog.h +++ b/editor/gui/editor_file_dialog.h @@ -41,6 +41,7 @@ class EditorFileDialog : public FileDialog { protected: virtual void _item_menu_id_pressed(int p_option) override; + virtual void _dir_contents_changed() override; virtual bool _should_use_native_popup() const override; virtual bool _should_hide_file(const String &p_file) const override; diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp index 53df067f089..f011aef71b5 100644 --- a/scene/gui/file_dialog.cpp +++ b/scene/gui/file_dialog.cpp @@ -1064,8 +1064,11 @@ void FileDialog::_file_list_select_first() { } void FileDialog::_delete_confirm() { - OS::get_singleton()->move_to_trash(_get_item_path(_get_selected_file_idx())); - invalidate(); + Error err = OS::get_singleton()->move_to_trash(_get_item_path(_get_selected_file_idx())); + if (err == OK) { + invalidate(); + _dir_contents_changed(); + } } void FileDialog::_filename_filter_selected() { @@ -1537,6 +1540,7 @@ FileDialog::Access FileDialog::get_access() const { void FileDialog::_make_dir_confirm() { Error err = dir_access->make_dir(new_dir_name->get_text().strip_edges()); if (err == OK) { + _dir_contents_changed(); _change_dir(new_dir_name->get_text().strip_edges()); update_filters(); _push_history(); diff --git a/scene/gui/file_dialog.h b/scene/gui/file_dialog.h index 89f1a5b0175..c2acbb5d325 100644 --- a/scene/gui/file_dialog.h +++ b/scene/gui/file_dialog.h @@ -368,6 +368,7 @@ protected: bool _can_use_native_popup() const; virtual void _item_menu_id_pressed(int p_option); + virtual void _dir_contents_changed() {} virtual bool _should_use_native_popup() const; virtual bool _should_hide_file(const String &p_file) const { return false; }