Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FileDialog] Make set_visible compatible with native dialogs. #82552

Merged
merged 1 commit into from
Sep 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions scene/gui/file_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> &p_files) {
if (p_ok) {
if (p_files.size() > 0) {
Expand Down
1 change: 1 addition & 0 deletions scene/gui/file_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion scene/main/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down