diff --git a/editor/gui/editor_file_dialog.cpp b/editor/gui/editor_file_dialog.cpp index 0f9f0ea4322..9b9856cd4fb 100644 --- a/editor/gui/editor_file_dialog.cpp +++ b/editor/gui/editor_file_dialog.cpp @@ -127,21 +127,27 @@ void EditorFileDialog::_native_dialog_cb(bool p_ok, const Vector &p_file emit_signal(SNAME("files_selected"), files); } else { if (mode == FILE_MODE_SAVE_FILE) { - if (p_filter >= 0 && p_filter < filters.size()) { + if (p_filter != 0 && p_filter != filter->get_item_count() - 1) { bool valid = false; - String flt = filters[p_filter].get_slice(";", 0); - 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.matchn(str)) { - valid = true; - break; - } + int idx = p_filter; + if (filters.size() > 1) { + idx--; } + if (idx >= 0 && idx < filters.size()) { + String flt = filters[idx].get_slice(";", 0); + 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)) { + valid = true; + break; + } + } - if (!valid && filter_slice_count > 0) { - String str = (flt.get_slice(",", 0).strip_edges()); - f += str.substr(1, str.length() - 1); + if (!valid && filter_slice_count > 0) { + String str = (flt.get_slice(",", 0).strip_edges()); + f += str.substr(1, str.length() - 1); + } } } emit_signal(SNAME("file_selected"), f); @@ -587,8 +593,8 @@ void EditorFileDialog::_action_pressed() { } if (idx >= 0 && idx < filters.size()) { String flt = filters[idx].get_slice(";", 0); - int filterSliceCount = flt.get_slice_count(","); - for (int j = 0; j < filterSliceCount; j++) { + 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.matchn(str)) { valid = true; @@ -596,7 +602,7 @@ void EditorFileDialog::_action_pressed() { } } - if (!valid && filterSliceCount > 0) { + if (!valid && filter_slice_count > 0) { String str = (flt.get_slice(",", 0).strip_edges()); f += str.substr(1, str.length() - 1); _request_single_thumbnail(get_current_dir().path_join(f.get_file())); diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp index d21ede28e06..7f2f5cd9301 100644 --- a/scene/gui/file_dialog.cpp +++ b/scene/gui/file_dialog.cpp @@ -154,21 +154,27 @@ void FileDialog::_native_dialog_cb_with_options(bool p_ok, const Vector emit_signal(SNAME("files_selected"), files); } else { if (mode == FILE_MODE_SAVE_FILE) { - if (p_filter >= 0 && p_filter < filters.size()) { + if (p_filter != 0 && p_filter != filter->get_item_count() - 1) { bool valid = false; - String flt = filters[p_filter].get_slice(";", 0); - 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.matchn(str)) { - valid = true; - break; - } + int idx = p_filter; + if (filters.size() > 1) { + idx--; } + if (idx >= 0 && idx < filters.size()) { + String flt = filters[idx].get_slice(";", 0); + 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)) { + valid = true; + break; + } + } - if (!valid && filter_slice_count > 0) { - String str = (flt.get_slice(",", 0).strip_edges()); - f += str.substr(1, str.length() - 1); + if (!valid && filter_slice_count > 0) { + String str = (flt.get_slice(",", 0).strip_edges()); + f += str.substr(1, str.length() - 1); + } } } emit_signal(SNAME("file_selected"), f); @@ -509,8 +515,8 @@ void FileDialog::_action_pressed() { } if (idx >= 0 && idx < filters.size()) { String flt = filters[idx].get_slice(";", 0); - int filterSliceCount = flt.get_slice_count(","); - for (int j = 0; j < filterSliceCount; j++) { + 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.matchn(str)) { valid = true; @@ -518,7 +524,7 @@ void FileDialog::_action_pressed() { } } - if (!valid && filterSliceCount > 0) { + 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());