From c52db6190cb121a65c0251b3143730292d9024e5 Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Sat, 30 Sep 2023 00:40:49 +0300 Subject: [PATCH] [FileDialog] Make set_visible compatible with native dialogs. --- scene/gui/file_dialog.cpp | 10 ++++++++++ scene/gui/file_dialog.h | 1 + scene/main/window.h | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp index 7af7b2cf7ee3..3857281a66ca 100644 --- a/scene/gui/file_dialog.cpp +++ b/scene/gui/file_dialog.cpp @@ -63,6 +63,16 @@ void FileDialog::popup(const Rect2i &p_rect) { } } +void FileDialog::set_visible(bool p_visible) { + if (access == ACCESS_FILESYSTEM && DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_NATIVE_DIALOG) && (use_native_dialog || OS::get_singleton()->is_sandboxed())) { + if (p_visible) { + DisplayServer::get_singleton()->file_dialog_show(get_title(), dir->get_text(), file->get_text().get_file(), show_hidden_files, DisplayServer::FileDialogMode(mode), filters, callable_mp(this, &FileDialog::_native_dialog_cb)); + } + } else { + ConfirmationDialog::set_visible(p_visible); + } +} + void FileDialog::_native_dialog_cb(bool p_ok, const Vector &p_files) { if (p_ok) { if (p_files.size() > 0) { diff --git a/scene/gui/file_dialog.h b/scene/gui/file_dialog.h index 739cb3e31aff..1a87b79fdda2 100644 --- a/scene/gui/file_dialog.h +++ b/scene/gui/file_dialog.h @@ -171,6 +171,7 @@ class FileDialog : public ConfirmationDialog { static void _bind_methods(); public: + virtual void set_visible(bool p_visible) override; virtual void popup(const Rect2i &p_rect = Rect2i()) override; void popup_file_dialog(); diff --git a/scene/main/window.h b/scene/main/window.h index 11b986239e2b..c1a7ed2e0ba4 100644 --- a/scene/main/window.h +++ b/scene/main/window.h @@ -293,7 +293,7 @@ class Window : public Viewport { void request_attention(); void move_to_foreground(); - void set_visible(bool p_visible); + virtual void set_visible(bool p_visible); bool is_visible() const; void update_mouse_cursor_state() override;