diff --git a/doc/classes/DisplayServer.xml b/doc/classes/DisplayServer.xml index d3d25e8ee88..a7cc0669816 100644 --- a/doc/classes/DisplayServer.xml +++ b/doc/classes/DisplayServer.xml @@ -784,7 +784,7 @@ Callbacks have the following arguments: [code]status: bool, selected_paths: PackedStringArray, selected_filter_index: int[/code]. [b]On Android,[/b] the third callback argument ([code]selected_filter_index[/code]) is always [code]0[/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, macOS, and Android (API level 29+). [b]Note:[/b] [param current_directory] might be ignored. - [b]Note:[/b] Embedded file dialog and Windows file dialog support only file extensions, while Android, Linux, and macOS file dialogs also support MIME types. + [b]Note:[/b] Embedded file dialogs and Windows file dialogs support only file extensions, while Android, Linux, and macOS file dialogs also support MIME types. [b]Note:[/b] On Android and Linux, [param show_hidden] is ignored. [b]Note:[/b] On Android and macOS, native file dialogs have no title. [b]Note:[/b] On macOS, sandboxed apps will save security-scoped bookmarks to retain access to the opened folders across multiple sessions. Use [method OS.get_granted_permissions] to get a list of saved bookmarks. @@ -812,7 +812,7 @@ 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_EXTRA] feature. Supported platforms include Linux (X11/Wayland), Windows, and macOS. [b]Note:[/b] [param current_directory] might be ignored. - [b]Note:[/b] Embedded file dialog and Windows file dialog support only file extensions, while Android, Linux, and macOS file dialogs also support MIME types. + [b]Note:[/b] Embedded file dialogs and Windows file dialogs support only file extensions, while Android, Linux, and macOS file dialogs also support MIME types. [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, sandboxed apps will save security-scoped bookmarks to retain access to the opened folders across multiple sessions. Use [method OS.get_granted_permissions] to get a list of saved bookmarks. diff --git a/doc/classes/FileDialog.xml b/doc/classes/FileDialog.xml index b1cefac7e2d..35bb73c3c81 100644 --- a/doc/classes/FileDialog.xml +++ b/doc/classes/FileDialog.xml @@ -13,10 +13,12 @@ + - Adds a comma-separated file name [param filter] option to the [FileDialog] with an optional [param description], which restricts what files can be picked. + Adds a comma-separated file extension [param filter] and comma-separated MIME type [param mime_type] option to the [FileDialog] with an optional [param description], which restricts what files can be picked. A [param filter] should be of the form [code]"filename.extension"[/code], where filename and extension can be [code]*[/code] to match any string. Filters starting with [code].[/code] (i.e. empty filenames) are not allowed. - For example, a [param filter] of [code]"*.png, *.jpg"[/code] and a [param description] of [code]"Images"[/code] results in filter text "Images (*.png, *.jpg)". + For example, a [param filter] of [code]"*.png, *.jpg"[/code], a [param mime_type] of [code]image/png, image/jpeg[/code], and a [param description] of [code]"Images"[/code] results in filter text "Images (*.png, *.jpg)". + [b]Note:[/b] Embedded file dialogs and Windows file dialogs support only file extensions, while Android, Linux, and macOS file dialogs also support MIME types. @@ -232,7 +234,7 @@ The available file type filters. Each filter string in the array should be formatted like this: [code]*.png,*.jpg,*.jpeg;Image Files;image/png,image/jpeg[/code]. The description text of the filter is optional and can be omitted. Both file extensions and MIME type should be always set. - [b]Note:[/b] Embedded file dialog and Windows file dialog support only file extensions, while Android, Linux, and macOS file dialogs also support MIME types. + [b]Note:[/b] Embedded file dialogs and Windows file dialogs support only file extensions, while Android, Linux, and macOS file dialogs also support MIME types. If [code]true[/code], shows the button for creating new directories (when using [constant FILE_MODE_OPEN_DIR], [constant FILE_MODE_OPEN_ANY], or [constant FILE_MODE_SAVE_FILE]), and the context menu will have the "New Folder..." option. diff --git a/misc/extension_api_validation/4.5-stable.expected b/misc/extension_api_validation/4.5-stable.expected index ed009c16236..10389196aa1 100644 --- a/misc/extension_api_validation/4.5-stable.expected +++ b/misc/extension_api_validation/4.5-stable.expected @@ -54,3 +54,10 @@ Validate extension JSON: Error: Field 'classes/AnimationPlayer/methods/set_curre Validate extension JSON: Error: Field 'classes/AnimationPlayer/signals/current_animation_changed/arguments/0': type changed value in new API, from "String" to "StringName". Return types and parameters changed to StringName to improve performance. Compatibility methods registered; No compatibility system for signal arguments. + + +GH-111439 +--------- +Validate extension JSON: Error: Field 'classes/FileDialog/methods/add_filter/arguments': size changed value in new API, from 2 to 3. + +Optional argument added. Compatibility method registered. diff --git a/scene/gui/file_dialog.compat.inc b/scene/gui/file_dialog.compat.inc new file mode 100644 index 00000000000..c8da18f7a17 --- /dev/null +++ b/scene/gui/file_dialog.compat.inc @@ -0,0 +1,41 @@ +/**************************************************************************/ +/* file_dialog.compat.inc */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#ifndef DISABLE_DEPRECATED + +void FileDialog::_add_filter_bind_compat_111439(const String &p_filter, const String &p_description) { + add_filter(p_filter, p_description, ""); +} + +void FileDialog::_bind_compatibility_methods() { + ClassDB::bind_compatibility_method(D_METHOD("add_filter", "filter", "description"), &FileDialog::_add_filter_bind_compat_111439, DEFVAL("")); +} + +#endif diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp index 343f267b72a..dc7c0df7e3e 100644 --- a/scene/gui/file_dialog.cpp +++ b/scene/gui/file_dialog.cpp @@ -29,6 +29,7 @@ /**************************************************************************/ #include "file_dialog.h" +#include "file_dialog.compat.inc" #include "core/config/project_settings.h" #include "core/io/dir_access.h" @@ -1213,12 +1214,14 @@ void FileDialog::clear_filters() { invalidate(); } -void FileDialog::add_filter(const String &p_filter, const String &p_description) { +void FileDialog::add_filter(const String &p_filter, const String &p_description, const String &p_mime) { ERR_FAIL_COND_MSG(p_filter.begins_with("."), "Filter must be \"filename.extension\", can't start with dot."); - if (p_description.is_empty()) { + if (p_description.is_empty() && p_mime.is_empty()) { filters.push_back(p_filter); - } else { + } else if (p_mime.is_empty()) { filters.push_back(vformat("%s ; %s", p_filter, p_description)); + } else { + filters.push_back(vformat("%s ; %s ; %s", p_filter, p_description, p_mime)); } update_filters(); invalidate(); @@ -2001,7 +2004,7 @@ void FileDialog::_bind_methods() { ClassDB::bind_method(D_METHOD("_cancel_pressed"), &FileDialog::_cancel_pressed); ClassDB::bind_method(D_METHOD("clear_filters"), &FileDialog::clear_filters); - ClassDB::bind_method(D_METHOD("add_filter", "filter", "description"), &FileDialog::add_filter, DEFVAL("")); + ClassDB::bind_method(D_METHOD("add_filter", "filter", "description", "mime_type"), &FileDialog::add_filter, DEFVAL(""), DEFVAL("")); ClassDB::bind_method(D_METHOD("set_filters", "filters"), &FileDialog::set_filters); ClassDB::bind_method(D_METHOD("get_filters"), &FileDialog::get_filters); ClassDB::bind_method(D_METHOD("clear_filename_filter"), &FileDialog::clear_filename_filter); diff --git a/scene/gui/file_dialog.h b/scene/gui/file_dialog.h index b8832eb6aea..b01bd241364 100644 --- a/scene/gui/file_dialog.h +++ b/scene/gui/file_dialog.h @@ -377,13 +377,19 @@ protected: bool _property_get_revert(const StringName &p_name, Variant &r_property) const { return property_helper.property_get_revert(p_name, r_property); } static void _bind_methods(); +#ifndef DISABLE_DEPRECATED + void _add_filter_bind_compat_111439(const String &p_filter, const String &p_description = ""); + + static void _bind_compatibility_methods(); +#endif + public: virtual void set_visible(bool p_visible) override; virtual void popup(const Rect2i &p_rect = Rect2i()) override; void popup_file_dialog(); void clear_filters(); - void add_filter(const String &p_filter, const String &p_description = ""); + void add_filter(const String &p_filter, const String &p_description = "", const String &p_mime = ""); void set_filters(const Vector &p_filters); Vector get_filters() const; void clear_filename_filter();