Skip to content

Commit 5ff8f21

Browse files
committed
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.
1 parent fbc9539 commit 5ff8f21

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

editor/gui/editor_file_dialog.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include "editor_file_dialog.h"
3232

33+
#include "core/config/project_settings.h"
3334
#include "editor/docks/filesystem_dock.h"
3435
#include "editor/file_system/dependency_editor.h"
3536
#include "editor/settings/editor_settings.h"
@@ -92,6 +93,26 @@ void EditorFileDialog::_validate_property(PropertyInfo &p_property) const {
9293
}
9394
}
9495

96+
void EditorFileDialog::_dir_contents_changed() {
97+
bool scan_required = false;
98+
switch (get_access()) {
99+
case FileDialog::ACCESS_RESOURCES: {
100+
scan_required = true;
101+
} break;
102+
case FileDialog::ACCESS_USERDATA: {
103+
// Directories within the project dir are unlikely to be accessed.
104+
} break;
105+
case FileDialog::ACCESS_FILESYSTEM: {
106+
// Directories within the project dir may still be accessed.
107+
const String localized_path = ProjectSettings::get_singleton()->localize_path(get_current_dir());
108+
scan_required = localized_path.is_resource_file();
109+
} break;
110+
}
111+
if (scan_required) {
112+
EditorFileSystem::get_singleton()->scan_changes();
113+
}
114+
}
115+
95116
void EditorFileDialog::_notification(int p_what) {
96117
switch (p_what) {
97118
case NOTIFICATION_VISIBILITY_CHANGED: {

editor/gui/editor_file_dialog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class EditorFileDialog : public FileDialog {
4141

4242
protected:
4343
virtual void _item_menu_id_pressed(int p_option) override;
44+
virtual void _dir_contents_changed() override;
4445

4546
virtual bool _should_use_native_popup() const override;
4647
virtual bool _should_hide_file(const String &p_file) const override;

scene/gui/file_dialog.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,8 +1064,11 @@ void FileDialog::_file_list_select_first() {
10641064
}
10651065

10661066
void FileDialog::_delete_confirm() {
1067-
OS::get_singleton()->move_to_trash(_get_item_path(_get_selected_file_idx()));
1068-
invalidate();
1067+
Error err = OS::get_singleton()->move_to_trash(_get_item_path(_get_selected_file_idx()));
1068+
if (err == OK) {
1069+
invalidate();
1070+
_dir_contents_changed();
1071+
}
10691072
}
10701073

10711074
void FileDialog::_filename_filter_selected() {
@@ -1537,6 +1540,7 @@ FileDialog::Access FileDialog::get_access() const {
15371540
void FileDialog::_make_dir_confirm() {
15381541
Error err = dir_access->make_dir(new_dir_name->get_text().strip_edges());
15391542
if (err == OK) {
1543+
_dir_contents_changed();
15401544
_change_dir(new_dir_name->get_text().strip_edges());
15411545
update_filters();
15421546
_push_history();

scene/gui/file_dialog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ class FileDialog : public ConfirmationDialog {
368368

369369
bool _can_use_native_popup() const;
370370
virtual void _item_menu_id_pressed(int p_option);
371+
virtual void _dir_contents_changed() {}
371372

372373
virtual bool _should_use_native_popup() const;
373374
virtual bool _should_hide_file(const String &p_file) const { return false; }

0 commit comments

Comments
 (0)