Skip to content

Commit 0dfd18c

Browse files
[DisplayServer] Add feature flag for native file dialog access to user/res and options
1 parent 8004c75 commit 0dfd18c

File tree

12 files changed

+39
-10
lines changed

12 files changed

+39
-10
lines changed

doc/classes/DisplayServer.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@
166166
- [code]"values"[/code] - [PackedStringArray] of values. If empty, boolean option (check box) is used.
167167
- [code]"default"[/code] - default selected option index ([int]) or default boolean value ([bool]).
168168
Callbacks have the following arguments: [code]status: bool, selected_paths: PackedStringArray, selected_filter_index: int, selected_option: Dictionary[/code].
169-
[b]Note:[/b] This method is implemented if the display server has the [constant FEATURE_NATIVE_DIALOG_FILE] feature. Supported platforms include Linux (X11/Wayland), Windows, and macOS.
169+
[b]Note:[/b] This method is implemented if the display server has the [constant FEATURE_NATIVE_DIALOG_FILE_EXTRA] feature. Supported platforms include Linux (X11/Wayland), Windows, and macOS.
170170
[b]Note:[/b] [param current_directory] might be ignored.
171171
[b]Note:[/b] On Linux (X11), [param show_hidden] is ignored.
172172
[b]Note:[/b] On macOS, native file dialogs have no title.
@@ -1889,7 +1889,10 @@
18891889
Display server supports spawning text input dialogs using the operating system's native look-and-feel. See [method dialog_input_text]. [b]Windows, macOS[/b]
18901890
</constant>
18911891
<constant name="FEATURE_NATIVE_DIALOG_FILE" value="25" enum="Feature">
1892-
Display server supports spawning dialogs for selecting files or directories using the operating system's native look-and-feel. See [method file_dialog_show] and [method file_dialog_with_options_show]. [b]Windows, macOS, Linux (X11/Wayland)[/b]
1892+
Display server supports spawning dialogs for selecting files or directories using the operating system's native look-and-feel. See [method file_dialog_show]. [b]Windows, macOS, Linux (X11/Wayland)[/b]
1893+
</constant>
1894+
<constant name="FEATURE_NATIVE_DIALOG_FILE_EXTRA" value="26" enum="Feature">
1895+
The display server supports all features of [constant FEATURE_NATIVE_DIALOG_FILE], with the added functionality of Options and native dialog file access to [code]res://[/code] and [code]user://[/code] paths. See [method file_dialog_show] and [method file_dialog_with_options_show]. [b]Windows, macOS, Linux (X11/Wayland)[/b]
18931896
</constant>
18941897
<constant name="MOUSE_MODE_VISIBLE" value="0" enum="MouseMode">
18951898
Makes the mouse cursor visible if it is hidden.

platform/android/display_server_android.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ bool DisplayServerAndroid::has_feature(Feature p_feature) const {
7373
//case FEATURE_NATIVE_DIALOG:
7474
case FEATURE_NATIVE_DIALOG_INPUT:
7575
//case FEATURE_NATIVE_DIALOG_FILE:
76+
//case FEATURE_NATIVE_DIALOG_FILE_EXTRA:
7677
//case FEATURE_NATIVE_ICON:
7778
//case FEATURE_WINDOW_TRANSPARENCY:
7879
case FEATURE_CLIPBOARD:

platform/ios/display_server_ios.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@
370370
// case FEATURE_NATIVE_DIALOG:
371371
// case FEATURE_NATIVE_DIALOG_INPUT:
372372
// case FEATURE_NATIVE_DIALOG_FILE:
373+
// case FEATURE_NATIVE_DIALOG_FILE_EXTRA:
373374
// case FEATURE_NATIVE_ICON:
374375
// case FEATURE_WINDOW_TRANSPARENCY:
375376
case FEATURE_CLIPBOARD:

platform/linuxbsd/wayland/display_server_wayland.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ bool DisplayServerWayland::has_feature(Feature p_feature) const {
216216
//case FEATURE_NATIVE_DIALOG:
217217
//case FEATURE_NATIVE_DIALOG_INPUT:
218218
#ifdef DBUS_ENABLED
219-
case FEATURE_NATIVE_DIALOG_FILE: {
219+
case FEATURE_NATIVE_DIALOG_FILE:
220+
case FEATURE_NATIVE_DIALOG_FILE_EXTRA: {
220221
return true;
221222
} break;
222223
#endif

platform/linuxbsd/x11/display_server_x11.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ bool DisplayServerX11::has_feature(Feature p_feature) const {
129129
case FEATURE_ICON:
130130
#ifdef DBUS_ENABLED
131131
case FEATURE_NATIVE_DIALOG_FILE:
132+
case FEATURE_NATIVE_DIALOG_FILE_EXTRA:
132133
#endif
133134
//case FEATURE_NATIVE_DIALOG:
134135
//case FEATURE_NATIVE_DIALOG_INPUT:

platform/macos/display_server_macos.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,7 @@
752752
case FEATURE_NATIVE_DIALOG:
753753
case FEATURE_NATIVE_DIALOG_INPUT:
754754
case FEATURE_NATIVE_DIALOG_FILE:
755+
case FEATURE_NATIVE_DIALOG_FILE_EXTRA:
755756
case FEATURE_IME:
756757
case FEATURE_WINDOW_TRANSPARENCY:
757758
case FEATURE_HIDPI:

platform/web/display_server_web.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,7 @@ bool DisplayServerWeb::has_feature(Feature p_feature) const {
11331133
//case FEATURE_NATIVE_DIALOG:
11341134
//case FEATURE_NATIVE_DIALOG_INPUT:
11351135
//case FEATURE_NATIVE_DIALOG_FILE:
1136+
//case FEATURE_NATIVE_DIALOG_FILE_EXTRA:
11361137
//case FEATURE_NATIVE_ICON:
11371138
//case FEATURE_WINDOW_TRANSPARENCY:
11381139
//case FEATURE_KEEP_SCREEN_ON:

platform/windows/display_server_windows.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ bool DisplayServerWindows::has_feature(Feature p_feature) const {
129129
case FEATURE_NATIVE_DIALOG:
130130
case FEATURE_NATIVE_DIALOG_INPUT:
131131
case FEATURE_NATIVE_DIALOG_FILE:
132+
case FEATURE_NATIVE_DIALOG_FILE_EXTRA:
132133
case FEATURE_SWAP_BUFFERS:
133134
case FEATURE_KEEP_SCREEN_ON:
134135
case FEATURE_TEXT_TO_SPEECH:

scene/gui/file_dialog.cpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,18 @@ void FileDialog::_native_popup() {
6767
} else if (access == ACCESS_USERDATA) {
6868
root = OS::get_singleton()->get_user_data_dir();
6969
}
70-
DisplayServer::get_singleton()->file_dialog_with_options_show(get_title(), ProjectSettings::get_singleton()->globalize_path(dir->get_text()), root, file->get_text().get_file(), show_hidden_files, DisplayServer::FileDialogMode(mode), filters, _get_options(), callable_mp(this, &FileDialog::_native_dialog_cb));
70+
if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_NATIVE_DIALOG_FILE_EXTRA)) {
71+
DisplayServer::get_singleton()->file_dialog_with_options_show(get_title(), ProjectSettings::get_singleton()->globalize_path(dir->get_text()), root, file->get_text().get_file(), show_hidden_files, DisplayServer::FileDialogMode(mode), filters, _get_options(), callable_mp(this, &FileDialog::_native_dialog_cb_with_options));
72+
} else {
73+
DisplayServer::get_singleton()->file_dialog_show(get_title(), ProjectSettings::get_singleton()->globalize_path(dir->get_text()), file->get_text().get_file(), show_hidden_files, DisplayServer::FileDialogMode(mode), filters, callable_mp(this, &FileDialog::_native_dialog_cb));
74+
}
75+
}
76+
77+
bool FileDialog::_can_use_native_popup() {
78+
if (access == ACCESS_RESOURCES || access == ACCESS_USERDATA || options.size() > 0) {
79+
return DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_NATIVE_DIALOG_FILE_EXTRA);
80+
}
81+
return DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_NATIVE_DIALOG_FILE);
7182
}
7283

7384
void FileDialog::popup(const Rect2i &p_rect) {
@@ -80,7 +91,7 @@ void FileDialog::popup(const Rect2i &p_rect) {
8091
}
8192
#endif
8293

83-
if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_NATIVE_DIALOG_FILE) && (use_native_dialog || OS::get_singleton()->is_sandboxed())) {
94+
if (_can_use_native_popup() && (use_native_dialog || OS::get_singleton()->is_sandboxed())) {
8495
_native_popup();
8596
} else {
8697
ConfirmationDialog::popup(p_rect);
@@ -99,7 +110,7 @@ void FileDialog::set_visible(bool p_visible) {
99110
}
100111
#endif
101112

102-
if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_NATIVE_DIALOG_FILE) && (use_native_dialog || OS::get_singleton()->is_sandboxed())) {
113+
if (_can_use_native_popup() && (use_native_dialog || OS::get_singleton()->is_sandboxed())) {
103114
if (p_visible) {
104115
_native_popup();
105116
}
@@ -108,7 +119,11 @@ void FileDialog::set_visible(bool p_visible) {
108119
}
109120
}
110121

111-
void FileDialog::_native_dialog_cb(bool p_ok, const Vector<String> &p_files, int p_filter, const Dictionary &p_selected_options) {
122+
void FileDialog::_native_dialog_cb(bool p_ok, const Vector<String> &p_files, int p_filter) {
123+
_native_dialog_cb_with_options(p_ok, p_files, p_filter, Dictionary());
124+
}
125+
126+
void FileDialog::_native_dialog_cb_with_options(bool p_ok, const Vector<String> &p_files, int p_filter, const Dictionary &p_selected_options) {
112127
if (!p_ok) {
113128
file->set_text("");
114129
emit_signal(SNAME("canceled"));
@@ -182,7 +197,7 @@ void FileDialog::_notification(int p_what) {
182197
#endif
183198

184199
// Replace the built-in dialog with the native one if it started visible.
185-
if (is_visible() && DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_NATIVE_DIALOG_FILE) && (use_native_dialog || OS::get_singleton()->is_sandboxed())) {
200+
if (is_visible() && _can_use_native_popup() && (use_native_dialog || OS::get_singleton()->is_sandboxed())) {
186201
ConfirmationDialog::set_visible(false);
187202
_native_popup();
188203
}
@@ -1487,7 +1502,7 @@ void FileDialog::set_use_native_dialog(bool p_native) {
14871502
#endif
14881503

14891504
// Replace the built-in dialog with the native one if it's currently visible.
1490-
if (is_inside_tree() && is_visible() && DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_NATIVE_DIALOG_FILE) && (use_native_dialog || OS::get_singleton()->is_sandboxed())) {
1505+
if (is_inside_tree() && is_visible() && _can_use_native_popup() && (use_native_dialog || OS::get_singleton()->is_sandboxed())) {
14911506
ConfirmationDialog::set_visible(false);
14921507
_native_popup();
14931508
}

scene/gui/file_dialog.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,10 @@ class FileDialog : public ConfirmationDialog {
188188

189189
virtual void shortcut_input(const Ref<InputEvent> &p_event) override;
190190

191+
bool _can_use_native_popup();
191192
void _native_popup();
192-
void _native_dialog_cb(bool p_ok, const Vector<String> &p_files, int p_filter, const Dictionary &p_selected_options);
193+
void _native_dialog_cb(bool p_ok, const Vector<String> &p_files, int p_filter);
194+
void _native_dialog_cb_with_options(bool p_ok, const Vector<String> &p_files, int p_filter, const Dictionary &p_selected_options);
193195

194196
bool _is_open_should_be_disabled();
195197

0 commit comments

Comments
 (0)