1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-08 12:40:44 +00:00

Sync native and embedded dialog missing extension handling.

This commit is contained in:
bruvzg
2025-02-13 09:26:07 +02:00
committed by Pāvels Nadtočajevs
parent 1a0bf54677
commit 1bdf84b31c
2 changed files with 70 additions and 10 deletions

View File

@@ -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;
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,8 +165,20 @@ 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)) {
@@ -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++) {

View File

@@ -153,8 +153,26 @@ void FileDialog::_native_dialog_cb_with_options(bool p_ok, const Vector<String>
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;
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--;
@@ -164,7 +182,7 @@ void FileDialog::_native_dialog_cb_with_options(bool p_ok, const Vector<String>
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;
}
@@ -173,8 +191,20 @@ void FileDialog::_native_dialog_cb_with_options(bool p_ok, const Vector<String>
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)) {
@@ -501,9 +531,9 @@ void FileDialog::_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++) {