|
@@ -127,8 +127,26 @@ void EditorFileDialog::_native_dialog_cb(bool p_ok, const Vector<String> &p_file
|
|
|
emit_signal(SNAME("files_selected"), files);
|
|
|
} else {
|
|
|
if (mode == FILE_MODE_SAVE_FILE) {
|
|
|
- if (p_filter != 0 && p_filter != filter->get_item_count() - 1) {
|
|
|
- bool valid = false;
|
|
|
+ bool valid = false;
|
|
|
+
|
|
|
+ if (p_filter == filter->get_item_count() - 1) {
|
|
|
+ valid = true; // Match none.
|
|
|
+ } else if (filters.size() > 1 && p_filter == 0) {
|
|
|
+ // Match all filters.
|
|
|
+ for (int i = 0; i < filters.size(); i++) {
|
|
|
+ String flt = filters[i].get_slice(";", 0);
|
|
|
+ for (int j = 0; j < flt.get_slice_count(","); j++) {
|
|
|
+ String str = flt.get_slice(",", j).strip_edges();
|
|
|
+ if (f.matchn(str)) {
|
|
|
+ valid = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (valid) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
int idx = p_filter;
|
|
|
if (filters.size() > 1) {
|
|
|
idx--;
|
|
@@ -138,7 +156,7 @@ void EditorFileDialog::_native_dialog_cb(bool p_ok, const Vector<String> &p_file
|
|
|
int filter_slice_count = flt.get_slice_count(",");
|
|
|
for (int j = 0; j < filter_slice_count; j++) {
|
|
|
String str = (flt.get_slice(",", j).strip_edges());
|
|
|
- if (f.match(str)) {
|
|
|
+ if (f.matchn(str)) {
|
|
|
valid = true;
|
|
|
break;
|
|
|
}
|
|
@@ -147,9 +165,21 @@ void EditorFileDialog::_native_dialog_cb(bool p_ok, const Vector<String> &p_file
|
|
|
if (!valid && filter_slice_count > 0) {
|
|
|
String str = (flt.get_slice(",", 0).strip_edges());
|
|
|
f += str.substr(1, str.length() - 1);
|
|
|
+ file->set_text(f.get_file());
|
|
|
+ valid = true;
|
|
|
}
|
|
|
+ } else {
|
|
|
+ valid = true;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // Add first extension of filter if no valid extension is found.
|
|
|
+ if (!valid) {
|
|
|
+ int idx = p_filter;
|
|
|
+ String flt = filters[idx].get_slice(";", 0);
|
|
|
+ String ext = flt.get_slice(",", 0).strip_edges().get_extension();
|
|
|
+ f += "." + ext;
|
|
|
+ }
|
|
|
emit_signal(SNAME("file_selected"), f);
|
|
|
} else if ((mode == FILE_MODE_OPEN_ANY || mode == FILE_MODE_OPEN_FILE) && dir_access->file_exists(f)) {
|
|
|
emit_signal(SNAME("file_selected"), f);
|
|
@@ -578,9 +608,9 @@ void EditorFileDialog::_action_pressed() {
|
|
|
bool valid = false;
|
|
|
|
|
|
if (filter->get_selected() == filter->get_item_count() - 1) {
|
|
|
- valid = true; // match none
|
|
|
+ valid = true; // Match none.
|
|
|
} else if (filters.size() > 1 && filter->get_selected() == 0) {
|
|
|
- // match all filters
|
|
|
+ // Match all filters.
|
|
|
for (int i = 0; i < filters.size(); i++) {
|
|
|
String flt = filters[i].get_slice(";", 0);
|
|
|
for (int j = 0; j < flt.get_slice_count(","); j++) {
|