mirror of
https://github.com/godotengine/godot.git
synced 2024-11-21 11:32:13 +00:00
[DisplayServer] Add feature flag for native file dialog access to user/res
and options
This commit is contained in:
parent
8004c7524f
commit
0dfd18c84b
@ -166,7 +166,7 @@
|
|||||||
- [code]"values"[/code] - [PackedStringArray] of values. If empty, boolean option (check box) is used.
|
- [code]"values"[/code] - [PackedStringArray] of values. If empty, boolean option (check box) is used.
|
||||||
- [code]"default"[/code] - default selected option index ([int]) or default boolean value ([bool]).
|
- [code]"default"[/code] - default selected option index ([int]) or default boolean value ([bool]).
|
||||||
Callbacks have the following arguments: [code]status: bool, selected_paths: PackedStringArray, selected_filter_index: int, selected_option: Dictionary[/code].
|
Callbacks have the following arguments: [code]status: bool, selected_paths: PackedStringArray, selected_filter_index: int, selected_option: Dictionary[/code].
|
||||||
[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.
|
[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.
|
||||||
[b]Note:[/b] [param current_directory] might be ignored.
|
[b]Note:[/b] [param current_directory] might be ignored.
|
||||||
[b]Note:[/b] On Linux (X11), [param show_hidden] is ignored.
|
[b]Note:[/b] On Linux (X11), [param show_hidden] is ignored.
|
||||||
[b]Note:[/b] On macOS, native file dialogs have no title.
|
[b]Note:[/b] On macOS, native file dialogs have no title.
|
||||||
@ -1889,7 +1889,10 @@
|
|||||||
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]
|
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]
|
||||||
</constant>
|
</constant>
|
||||||
<constant name="FEATURE_NATIVE_DIALOG_FILE" value="25" enum="Feature">
|
<constant name="FEATURE_NATIVE_DIALOG_FILE" value="25" enum="Feature">
|
||||||
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]
|
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]
|
||||||
|
</constant>
|
||||||
|
<constant name="FEATURE_NATIVE_DIALOG_FILE_EXTRA" value="26" enum="Feature">
|
||||||
|
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]
|
||||||
</constant>
|
</constant>
|
||||||
<constant name="MOUSE_MODE_VISIBLE" value="0" enum="MouseMode">
|
<constant name="MOUSE_MODE_VISIBLE" value="0" enum="MouseMode">
|
||||||
Makes the mouse cursor visible if it is hidden.
|
Makes the mouse cursor visible if it is hidden.
|
||||||
|
@ -73,6 +73,7 @@ bool DisplayServerAndroid::has_feature(Feature p_feature) const {
|
|||||||
//case FEATURE_NATIVE_DIALOG:
|
//case FEATURE_NATIVE_DIALOG:
|
||||||
case FEATURE_NATIVE_DIALOG_INPUT:
|
case FEATURE_NATIVE_DIALOG_INPUT:
|
||||||
//case FEATURE_NATIVE_DIALOG_FILE:
|
//case FEATURE_NATIVE_DIALOG_FILE:
|
||||||
|
//case FEATURE_NATIVE_DIALOG_FILE_EXTRA:
|
||||||
//case FEATURE_NATIVE_ICON:
|
//case FEATURE_NATIVE_ICON:
|
||||||
//case FEATURE_WINDOW_TRANSPARENCY:
|
//case FEATURE_WINDOW_TRANSPARENCY:
|
||||||
case FEATURE_CLIPBOARD:
|
case FEATURE_CLIPBOARD:
|
||||||
|
@ -370,6 +370,7 @@ bool DisplayServerIOS::has_feature(Feature p_feature) const {
|
|||||||
// case FEATURE_NATIVE_DIALOG:
|
// case FEATURE_NATIVE_DIALOG:
|
||||||
// case FEATURE_NATIVE_DIALOG_INPUT:
|
// case FEATURE_NATIVE_DIALOG_INPUT:
|
||||||
// case FEATURE_NATIVE_DIALOG_FILE:
|
// case FEATURE_NATIVE_DIALOG_FILE:
|
||||||
|
// case FEATURE_NATIVE_DIALOG_FILE_EXTRA:
|
||||||
// case FEATURE_NATIVE_ICON:
|
// case FEATURE_NATIVE_ICON:
|
||||||
// case FEATURE_WINDOW_TRANSPARENCY:
|
// case FEATURE_WINDOW_TRANSPARENCY:
|
||||||
case FEATURE_CLIPBOARD:
|
case FEATURE_CLIPBOARD:
|
||||||
|
@ -216,7 +216,8 @@ bool DisplayServerWayland::has_feature(Feature p_feature) const {
|
|||||||
//case FEATURE_NATIVE_DIALOG:
|
//case FEATURE_NATIVE_DIALOG:
|
||||||
//case FEATURE_NATIVE_DIALOG_INPUT:
|
//case FEATURE_NATIVE_DIALOG_INPUT:
|
||||||
#ifdef DBUS_ENABLED
|
#ifdef DBUS_ENABLED
|
||||||
case FEATURE_NATIVE_DIALOG_FILE: {
|
case FEATURE_NATIVE_DIALOG_FILE:
|
||||||
|
case FEATURE_NATIVE_DIALOG_FILE_EXTRA: {
|
||||||
return true;
|
return true;
|
||||||
} break;
|
} break;
|
||||||
#endif
|
#endif
|
||||||
|
@ -129,6 +129,7 @@ bool DisplayServerX11::has_feature(Feature p_feature) const {
|
|||||||
case FEATURE_ICON:
|
case FEATURE_ICON:
|
||||||
#ifdef DBUS_ENABLED
|
#ifdef DBUS_ENABLED
|
||||||
case FEATURE_NATIVE_DIALOG_FILE:
|
case FEATURE_NATIVE_DIALOG_FILE:
|
||||||
|
case FEATURE_NATIVE_DIALOG_FILE_EXTRA:
|
||||||
#endif
|
#endif
|
||||||
//case FEATURE_NATIVE_DIALOG:
|
//case FEATURE_NATIVE_DIALOG:
|
||||||
//case FEATURE_NATIVE_DIALOG_INPUT:
|
//case FEATURE_NATIVE_DIALOG_INPUT:
|
||||||
|
@ -752,6 +752,7 @@ bool DisplayServerMacOS::has_feature(Feature p_feature) const {
|
|||||||
case FEATURE_NATIVE_DIALOG:
|
case FEATURE_NATIVE_DIALOG:
|
||||||
case FEATURE_NATIVE_DIALOG_INPUT:
|
case FEATURE_NATIVE_DIALOG_INPUT:
|
||||||
case FEATURE_NATIVE_DIALOG_FILE:
|
case FEATURE_NATIVE_DIALOG_FILE:
|
||||||
|
case FEATURE_NATIVE_DIALOG_FILE_EXTRA:
|
||||||
case FEATURE_IME:
|
case FEATURE_IME:
|
||||||
case FEATURE_WINDOW_TRANSPARENCY:
|
case FEATURE_WINDOW_TRANSPARENCY:
|
||||||
case FEATURE_HIDPI:
|
case FEATURE_HIDPI:
|
||||||
|
@ -1133,6 +1133,7 @@ bool DisplayServerWeb::has_feature(Feature p_feature) const {
|
|||||||
//case FEATURE_NATIVE_DIALOG:
|
//case FEATURE_NATIVE_DIALOG:
|
||||||
//case FEATURE_NATIVE_DIALOG_INPUT:
|
//case FEATURE_NATIVE_DIALOG_INPUT:
|
||||||
//case FEATURE_NATIVE_DIALOG_FILE:
|
//case FEATURE_NATIVE_DIALOG_FILE:
|
||||||
|
//case FEATURE_NATIVE_DIALOG_FILE_EXTRA:
|
||||||
//case FEATURE_NATIVE_ICON:
|
//case FEATURE_NATIVE_ICON:
|
||||||
//case FEATURE_WINDOW_TRANSPARENCY:
|
//case FEATURE_WINDOW_TRANSPARENCY:
|
||||||
//case FEATURE_KEEP_SCREEN_ON:
|
//case FEATURE_KEEP_SCREEN_ON:
|
||||||
|
@ -129,6 +129,7 @@ bool DisplayServerWindows::has_feature(Feature p_feature) const {
|
|||||||
case FEATURE_NATIVE_DIALOG:
|
case FEATURE_NATIVE_DIALOG:
|
||||||
case FEATURE_NATIVE_DIALOG_INPUT:
|
case FEATURE_NATIVE_DIALOG_INPUT:
|
||||||
case FEATURE_NATIVE_DIALOG_FILE:
|
case FEATURE_NATIVE_DIALOG_FILE:
|
||||||
|
case FEATURE_NATIVE_DIALOG_FILE_EXTRA:
|
||||||
case FEATURE_SWAP_BUFFERS:
|
case FEATURE_SWAP_BUFFERS:
|
||||||
case FEATURE_KEEP_SCREEN_ON:
|
case FEATURE_KEEP_SCREEN_ON:
|
||||||
case FEATURE_TEXT_TO_SPEECH:
|
case FEATURE_TEXT_TO_SPEECH:
|
||||||
|
@ -67,7 +67,18 @@ void FileDialog::_native_popup() {
|
|||||||
} else if (access == ACCESS_USERDATA) {
|
} else if (access == ACCESS_USERDATA) {
|
||||||
root = OS::get_singleton()->get_user_data_dir();
|
root = OS::get_singleton()->get_user_data_dir();
|
||||||
}
|
}
|
||||||
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));
|
if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_NATIVE_DIALOG_FILE_EXTRA)) {
|
||||||
|
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));
|
||||||
|
} else {
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FileDialog::_can_use_native_popup() {
|
||||||
|
if (access == ACCESS_RESOURCES || access == ACCESS_USERDATA || options.size() > 0) {
|
||||||
|
return DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_NATIVE_DIALOG_FILE_EXTRA);
|
||||||
|
}
|
||||||
|
return DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_NATIVE_DIALOG_FILE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileDialog::popup(const Rect2i &p_rect) {
|
void FileDialog::popup(const Rect2i &p_rect) {
|
||||||
@ -80,7 +91,7 @@ void FileDialog::popup(const Rect2i &p_rect) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_NATIVE_DIALOG_FILE) && (use_native_dialog || OS::get_singleton()->is_sandboxed())) {
|
if (_can_use_native_popup() && (use_native_dialog || OS::get_singleton()->is_sandboxed())) {
|
||||||
_native_popup();
|
_native_popup();
|
||||||
} else {
|
} else {
|
||||||
ConfirmationDialog::popup(p_rect);
|
ConfirmationDialog::popup(p_rect);
|
||||||
@ -99,7 +110,7 @@ void FileDialog::set_visible(bool p_visible) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_NATIVE_DIALOG_FILE) && (use_native_dialog || OS::get_singleton()->is_sandboxed())) {
|
if (_can_use_native_popup() && (use_native_dialog || OS::get_singleton()->is_sandboxed())) {
|
||||||
if (p_visible) {
|
if (p_visible) {
|
||||||
_native_popup();
|
_native_popup();
|
||||||
}
|
}
|
||||||
@ -108,7 +119,11 @@ void FileDialog::set_visible(bool p_visible) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileDialog::_native_dialog_cb(bool p_ok, const Vector<String> &p_files, int p_filter, const Dictionary &p_selected_options) {
|
void FileDialog::_native_dialog_cb(bool p_ok, const Vector<String> &p_files, int p_filter) {
|
||||||
|
_native_dialog_cb_with_options(p_ok, p_files, p_filter, Dictionary());
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileDialog::_native_dialog_cb_with_options(bool p_ok, const Vector<String> &p_files, int p_filter, const Dictionary &p_selected_options) {
|
||||||
if (!p_ok) {
|
if (!p_ok) {
|
||||||
file->set_text("");
|
file->set_text("");
|
||||||
emit_signal(SNAME("canceled"));
|
emit_signal(SNAME("canceled"));
|
||||||
@ -182,7 +197,7 @@ void FileDialog::_notification(int p_what) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Replace the built-in dialog with the native one if it started visible.
|
// Replace the built-in dialog with the native one if it started visible.
|
||||||
if (is_visible() && DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_NATIVE_DIALOG_FILE) && (use_native_dialog || OS::get_singleton()->is_sandboxed())) {
|
if (is_visible() && _can_use_native_popup() && (use_native_dialog || OS::get_singleton()->is_sandboxed())) {
|
||||||
ConfirmationDialog::set_visible(false);
|
ConfirmationDialog::set_visible(false);
|
||||||
_native_popup();
|
_native_popup();
|
||||||
}
|
}
|
||||||
@ -1487,7 +1502,7 @@ void FileDialog::set_use_native_dialog(bool p_native) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Replace the built-in dialog with the native one if it's currently visible.
|
// Replace the built-in dialog with the native one if it's currently visible.
|
||||||
if (is_inside_tree() && is_visible() && DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_NATIVE_DIALOG_FILE) && (use_native_dialog || OS::get_singleton()->is_sandboxed())) {
|
if (is_inside_tree() && is_visible() && _can_use_native_popup() && (use_native_dialog || OS::get_singleton()->is_sandboxed())) {
|
||||||
ConfirmationDialog::set_visible(false);
|
ConfirmationDialog::set_visible(false);
|
||||||
_native_popup();
|
_native_popup();
|
||||||
}
|
}
|
||||||
|
@ -188,8 +188,10 @@ private:
|
|||||||
|
|
||||||
virtual void shortcut_input(const Ref<InputEvent> &p_event) override;
|
virtual void shortcut_input(const Ref<InputEvent> &p_event) override;
|
||||||
|
|
||||||
|
bool _can_use_native_popup();
|
||||||
void _native_popup();
|
void _native_popup();
|
||||||
void _native_dialog_cb(bool p_ok, const Vector<String> &p_files, int p_filter, const Dictionary &p_selected_options);
|
void _native_dialog_cb(bool p_ok, const Vector<String> &p_files, int p_filter);
|
||||||
|
void _native_dialog_cb_with_options(bool p_ok, const Vector<String> &p_files, int p_filter, const Dictionary &p_selected_options);
|
||||||
|
|
||||||
bool _is_open_should_be_disabled();
|
bool _is_open_should_be_disabled();
|
||||||
|
|
||||||
|
@ -1056,6 +1056,7 @@ void DisplayServer::_bind_methods() {
|
|||||||
BIND_ENUM_CONSTANT(FEATURE_NATIVE_HELP);
|
BIND_ENUM_CONSTANT(FEATURE_NATIVE_HELP);
|
||||||
BIND_ENUM_CONSTANT(FEATURE_NATIVE_DIALOG_INPUT);
|
BIND_ENUM_CONSTANT(FEATURE_NATIVE_DIALOG_INPUT);
|
||||||
BIND_ENUM_CONSTANT(FEATURE_NATIVE_DIALOG_FILE);
|
BIND_ENUM_CONSTANT(FEATURE_NATIVE_DIALOG_FILE);
|
||||||
|
BIND_ENUM_CONSTANT(FEATURE_NATIVE_DIALOG_FILE_EXTRA);
|
||||||
|
|
||||||
BIND_ENUM_CONSTANT(MOUSE_MODE_VISIBLE);
|
BIND_ENUM_CONSTANT(MOUSE_MODE_VISIBLE);
|
||||||
BIND_ENUM_CONSTANT(MOUSE_MODE_HIDDEN);
|
BIND_ENUM_CONSTANT(MOUSE_MODE_HIDDEN);
|
||||||
|
@ -152,6 +152,7 @@ public:
|
|||||||
FEATURE_NATIVE_HELP,
|
FEATURE_NATIVE_HELP,
|
||||||
FEATURE_NATIVE_DIALOG_INPUT,
|
FEATURE_NATIVE_DIALOG_INPUT,
|
||||||
FEATURE_NATIVE_DIALOG_FILE,
|
FEATURE_NATIVE_DIALOG_FILE,
|
||||||
|
FEATURE_NATIVE_DIALOG_FILE_EXTRA,
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual bool has_feature(Feature p_feature) const = 0;
|
virtual bool has_feature(Feature p_feature) const = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user