You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
Merge pull request #111439 from bruvzg/fd_filt_add
Add MIME argument to the `FileDialog.add_filter`.
This commit is contained in:
41
scene/gui/file_dialog.compat.inc
Normal file
41
scene/gui/file_dialog.compat.inc
Normal file
@@ -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
|
||||
@@ -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);
|
||||
|
||||
@@ -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<String> &p_filters);
|
||||
Vector<String> get_filters() const;
|
||||
void clear_filename_filter();
|
||||
|
||||
Reference in New Issue
Block a user