Merge pull request #71868 from YeldhamDev/filediag_invalidate_deferred

Defer invalidation on FileDialog nodes
This commit is contained in:
Yuri Sizov 2023-03-25 19:48:42 +01:00 committed by GitHub
commit 5922b2149e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 22 deletions

View file

@ -593,8 +593,8 @@ void EditorFileDialog::_item_dc_selected(int p_item) {
if (d["dir"]) { if (d["dir"]) {
dir_access->change_dir(d["name"]); dir_access->change_dir(d["name"]);
call_deferred(SNAME("_update_file_list")); callable_mp(this, &EditorFileDialog::update_file_list).call_deferred();
call_deferred(SNAME("_update_dir")); callable_mp(this, &EditorFileDialog::update_dir).call_deferred();
_push_history(); _push_history();
@ -1146,14 +1146,24 @@ void EditorFileDialog::set_access(Access p_access) {
} }
void EditorFileDialog::invalidate() { void EditorFileDialog::invalidate() {
if (is_visible()) { if (!is_visible() || is_invalidating) {
update_file_list(); return;
_update_favorites();
_update_recent();
invalidated = false;
} else {
invalidated = true;
} }
is_invalidating = true;
callable_mp(this, &EditorFileDialog::_invalidate).call_deferred();
}
void EditorFileDialog::_invalidate() {
if (!is_invalidating) {
return;
}
update_file_list();
_update_favorites();
_update_recent();
is_invalidating = false;
} }
EditorFileDialog::Access EditorFileDialog::get_access() const { EditorFileDialog::Access EditorFileDialog::get_access() const {
@ -1599,9 +1609,6 @@ void EditorFileDialog::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_access"), &EditorFileDialog::get_access); ClassDB::bind_method(D_METHOD("get_access"), &EditorFileDialog::get_access);
ClassDB::bind_method(D_METHOD("set_show_hidden_files", "show"), &EditorFileDialog::set_show_hidden_files); ClassDB::bind_method(D_METHOD("set_show_hidden_files", "show"), &EditorFileDialog::set_show_hidden_files);
ClassDB::bind_method(D_METHOD("is_showing_hidden_files"), &EditorFileDialog::is_showing_hidden_files); ClassDB::bind_method(D_METHOD("is_showing_hidden_files"), &EditorFileDialog::is_showing_hidden_files);
ClassDB::bind_method(D_METHOD("_update_file_name"), &EditorFileDialog::update_file_name);
ClassDB::bind_method(D_METHOD("_update_dir"), &EditorFileDialog::update_dir);
ClassDB::bind_method(D_METHOD("_update_file_list"), &EditorFileDialog::update_file_list);
ClassDB::bind_method(D_METHOD("_thumbnail_done"), &EditorFileDialog::_thumbnail_done); ClassDB::bind_method(D_METHOD("_thumbnail_done"), &EditorFileDialog::_thumbnail_done);
ClassDB::bind_method(D_METHOD("set_display_mode", "mode"), &EditorFileDialog::set_display_mode); ClassDB::bind_method(D_METHOD("set_display_mode", "mode"), &EditorFileDialog::set_display_mode);
ClassDB::bind_method(D_METHOD("get_display_mode"), &EditorFileDialog::get_display_mode); ClassDB::bind_method(D_METHOD("get_display_mode"), &EditorFileDialog::get_display_mode);

View file

@ -143,7 +143,7 @@ private:
DisplayMode display_mode; DisplayMode display_mode;
bool disable_overwrite_warning = false; bool disable_overwrite_warning = false;
bool invalidated = true; bool is_invalidating = false;
struct ThemeCache { struct ThemeCache {
Ref<Texture2D> parent_folder; Ref<Texture2D> parent_folder;
@ -216,6 +216,8 @@ private:
void _go_back(); void _go_back();
void _go_forward(); void _go_forward();
void _invalidate();
virtual void _post_popup() override; virtual void _post_popup() override;
void _save_to_recent(); void _save_to_recent();

View file

@ -126,6 +126,8 @@ void FileDialog::_notification(int p_what) {
show_hidden->add_theme_color_override("icon_hover_color", theme_cache.icon_hover_color); show_hidden->add_theme_color_override("icon_hover_color", theme_cache.icon_hover_color);
show_hidden->add_theme_color_override("icon_focus_color", theme_cache.icon_focus_color); show_hidden->add_theme_color_override("icon_focus_color", theme_cache.icon_focus_color);
show_hidden->add_theme_color_override("icon_pressed_color", theme_cache.icon_pressed_color); show_hidden->add_theme_color_override("icon_pressed_color", theme_cache.icon_pressed_color);
invalidate();
} break; } break;
case NOTIFICATION_TRANSLATION_CHANGED: { case NOTIFICATION_TRANSLATION_CHANGED: {
@ -863,12 +865,22 @@ void FileDialog::set_access(Access p_access) {
} }
void FileDialog::invalidate() { void FileDialog::invalidate() {
if (is_visible()) { if (!is_visible() || is_invalidating) {
update_file_list(); return;
invalidated = false;
} else {
invalidated = true;
} }
is_invalidating = true;
callable_mp(this, &FileDialog::_invalidate).call_deferred();
}
void FileDialog::_invalidate() {
if (!is_invalidating) {
return;
}
update_file_list();
is_invalidating = false;
} }
FileDialog::Access FileDialog::get_access() const { FileDialog::Access FileDialog::get_access() const {
@ -966,9 +978,6 @@ void FileDialog::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_root_subfolder"), &FileDialog::get_root_subfolder); ClassDB::bind_method(D_METHOD("get_root_subfolder"), &FileDialog::get_root_subfolder);
ClassDB::bind_method(D_METHOD("set_show_hidden_files", "show"), &FileDialog::set_show_hidden_files); ClassDB::bind_method(D_METHOD("set_show_hidden_files", "show"), &FileDialog::set_show_hidden_files);
ClassDB::bind_method(D_METHOD("is_showing_hidden_files"), &FileDialog::is_showing_hidden_files); ClassDB::bind_method(D_METHOD("is_showing_hidden_files"), &FileDialog::is_showing_hidden_files);
ClassDB::bind_method(D_METHOD("_update_file_name"), &FileDialog::update_file_name);
ClassDB::bind_method(D_METHOD("_update_dir"), &FileDialog::update_dir);
ClassDB::bind_method(D_METHOD("_update_file_list"), &FileDialog::update_file_list);
ClassDB::bind_method(D_METHOD("deselect_all"), &FileDialog::deselect_all); ClassDB::bind_method(D_METHOD("deselect_all"), &FileDialog::deselect_all);
ClassDB::bind_method(D_METHOD("invalidate"), &FileDialog::invalidate); ClassDB::bind_method(D_METHOD("invalidate"), &FileDialog::invalidate);

View file

@ -106,7 +106,7 @@ private:
static bool default_show_hidden_files; static bool default_show_hidden_files;
bool show_hidden_files = false; bool show_hidden_files = false;
bool invalidated = true; bool is_invalidating = false;
struct ThemeCache { struct ThemeCache {
Ref<Texture2D> parent_folder; Ref<Texture2D> parent_folder;
@ -154,6 +154,8 @@ private:
void _change_dir(const String &p_new_dir); void _change_dir(const String &p_new_dir);
void _update_drives(bool p_select = true); void _update_drives(bool p_select = true);
void _invalidate();
virtual void shortcut_input(const Ref<InputEvent> &p_event) override; virtual void shortcut_input(const Ref<InputEvent> &p_event) override;
bool _is_open_should_be_disabled(); bool _is_open_should_be_disabled();