summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPāvels Nadtočajevs <7645683+bruvzg@users.noreply.github.com>2024-11-15 08:43:07 +0200
committerPāvels Nadtočajevs <7645683+bruvzg@users.noreply.github.com>2024-11-15 12:08:33 +0200
commitf5fad7592f1f54cab03a5f04667f4254e6c39c40 (patch)
tree5184b047771cd967ccb8c7a7701e1e6c9a06fd12
parent673f396677654220d7e1d5b6fb5ed3b50126b4e6 (diff)
downloadredot-engine-f5fad7592f1f54cab03a5f04667f4254e6c39c40.tar.gz
Use processed filter list for native dialogs.
-rw-r--r--editor/gui/editor_file_dialog.cpp31
-rw-r--r--editor/gui/editor_file_dialog.h1
-rw-r--r--platform/linuxbsd/freedesktop_portal_desktop.cpp4
-rw-r--r--platform/macos/godot_open_save_delegate.mm2
-rw-r--r--platform/windows/display_server_windows.cpp2
-rw-r--r--scene/gui/file_dialog.cpp33
-rw-r--r--scene/gui/file_dialog.h1
7 files changed, 55 insertions, 19 deletions
diff --git a/editor/gui/editor_file_dialog.cpp b/editor/gui/editor_file_dialog.cpp
index b2eeeebd7a..12f00b7a57 100644
--- a/editor/gui/editor_file_dialog.cpp
+++ b/editor/gui/editor_file_dialog.cpp
@@ -65,7 +65,7 @@ void EditorFileDialog::_native_popup() {
} else if (access == ACCESS_USERDATA) {
root = OS::get_singleton()->get_user_data_dir();
}
- DisplayServer::get_singleton()->file_dialog_with_options_show(get_translated_title(), ProjectSettings::get_singleton()->globalize_path(dir->get_text()), root, file->get_text().get_file(), show_hidden_files, DisplayServer::FileDialogMode(mode), filters, _get_options(), callable_mp(this, &EditorFileDialog::_native_dialog_cb));
+ DisplayServer::get_singleton()->file_dialog_with_options_show(get_translated_title(), ProjectSettings::get_singleton()->globalize_path(dir->get_text()), root, file->get_text().get_file(), show_hidden_files, DisplayServer::FileDialogMode(mode), processed_filters, _get_options(), callable_mp(this, &EditorFileDialog::_native_dialog_cb));
}
void EditorFileDialog::popup(const Rect2i &p_rect) {
@@ -1148,37 +1148,54 @@ void EditorFileDialog::_filter_selected(int) {
void EditorFileDialog::update_filters() {
filter->clear();
+ processed_filters.clear();
if (filters.size() > 1) {
String all_filters;
+ String all_filters_full;
const int max_filters = 5;
for (int i = 0; i < MIN(max_filters, filters.size()); i++) {
- String flt = filters[i].get_slice(";", 0).strip_edges();
+ String flt = filters[i].get_slicec(';', 0).strip_edges();
if (i > 0) {
all_filters += ", ";
}
all_filters += flt;
}
+ for (int i = 0; i < filters.size(); i++) {
+ String flt = filters[i].get_slicec(';', 0).strip_edges();
+ if (i > 0) {
+ all_filters_full += ",";
+ }
+ all_filters_full += flt;
+ }
if (max_filters < filters.size()) {
all_filters += ", ...";
}
- filter->add_item(TTR("All Recognized") + " (" + all_filters + ")");
+ String f = TTR("All Recognized") + " (" + all_filters + ")";
+ filter->add_item(f);
+ processed_filters.push_back(all_filters_full + ";" + f);
}
for (int i = 0; i < filters.size(); i++) {
- String flt = filters[i].get_slice(";", 0).strip_edges();
+ String flt = filters[i].get_slicec(';', 0).strip_edges();
String desc = filters[i].get_slice(";", 1).strip_edges();
if (desc.length()) {
- filter->add_item(desc + " (" + flt + ")");
+ String f = desc + " (" + flt + ")";
+ filter->add_item(f);
+ processed_filters.push_back(flt + ";" + f);
} else {
- filter->add_item("(" + flt + ")");
+ String f = "(" + flt + ")";
+ filter->add_item(f);
+ processed_filters.push_back(flt + ";" + f);
}
}
- filter->add_item(TTR("All Files (*)"));
+ String f = TTR("All Files (*)");
+ filter->add_item(f);
+ processed_filters.push_back("*.*;" + f);
}
void EditorFileDialog::clear_filters() {
diff --git a/editor/gui/editor_file_dialog.h b/editor/gui/editor_file_dialog.h
index 1922155133..7a928a6188 100644
--- a/editor/gui/editor_file_dialog.h
+++ b/editor/gui/editor_file_dialog.h
@@ -145,6 +145,7 @@ private:
void _push_history();
Vector<String> filters;
+ Vector<String> processed_filters;
bool previews_enabled = true;
bool preview_waiting = false;
diff --git a/platform/linuxbsd/freedesktop_portal_desktop.cpp b/platform/linuxbsd/freedesktop_portal_desktop.cpp
index 94a748e414..63eed41cd3 100644
--- a/platform/linuxbsd/freedesktop_portal_desktop.cpp
+++ b/platform/linuxbsd/freedesktop_portal_desktop.cpp
@@ -394,7 +394,7 @@ Error FreeDesktopPortalDesktop::file_dialog_show(DisplayServer::WindowID p_windo
} else {
if (flt == "*.*") {
filter_exts.push_back("*");
- filter_names.push_back(RTR("All Files"));
+ filter_names.push_back(RTR("All Files") + " (*)");
} else {
filter_exts.push_back(flt);
filter_names.push_back(flt);
@@ -405,7 +405,7 @@ Error FreeDesktopPortalDesktop::file_dialog_show(DisplayServer::WindowID p_windo
}
if (filter_names.is_empty()) {
filter_exts.push_back("*");
- filter_names.push_back(RTR("All Files"));
+ filter_names.push_back(RTR("All Files") + " (*)");
}
DBusError err;
diff --git a/platform/macos/godot_open_save_delegate.mm b/platform/macos/godot_open_save_delegate.mm
index 6ffd939545..0d6bfa0c53 100644
--- a/platform/macos/godot_open_save_delegate.mm
+++ b/platform/macos/godot_open_save_delegate.mm
@@ -130,7 +130,7 @@
}
if ([type_filters count] > 0) {
- NSString *name_str = [NSString stringWithUTF8String:((tokens.size() == 1) ? tokens[0] : vformat("%s (%s)", tokens[1].strip_edges(), tokens[0].strip_edges())).utf8().get_data()];
+ NSString *name_str = [NSString stringWithUTF8String:((tokens.size() == 1) ? tokens[0] : tokens[1].strip_edges()).utf8().get_data()];
[new_allowed_types addObject:type_filters];
[popup addItemWithTitle:name_str];
}
diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp
index 26dad095ad..467873ee7c 100644
--- a/platform/windows/display_server_windows.cpp
+++ b/platform/windows/display_server_windows.cpp
@@ -505,7 +505,7 @@ void DisplayServerWindows::_thread_fd_monitor(void *p_ud) {
}
if (filter_names.is_empty()) {
filter_exts.push_back(String("*.*").utf16());
- filter_names.push_back(RTR("All Files").utf16());
+ filter_names.push_back((RTR("All Files") + " (*)").utf16());
}
Vector<COMDLG_FILTERSPEC> filters;
diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp
index c364888502..158155a51c 100644
--- a/scene/gui/file_dialog.cpp
+++ b/scene/gui/file_dialog.cpp
@@ -68,9 +68,9 @@ void FileDialog::_native_popup() {
root = OS::get_singleton()->get_user_data_dir();
}
if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_NATIVE_DIALOG_FILE_EXTRA)) {
- DisplayServer::get_singleton()->file_dialog_with_options_show(get_translated_title(), ProjectSettings::get_singleton()->globalize_path(dir->get_text()), root, file->get_text().get_file(), show_hidden_files, DisplayServer::FileDialogMode(mode), filters, _get_options(), callable_mp(this, &FileDialog::_native_dialog_cb_with_options));
+ DisplayServer::get_singleton()->file_dialog_with_options_show(get_translated_title(), ProjectSettings::get_singleton()->globalize_path(dir->get_text()), root, file->get_text().get_file(), show_hidden_files, DisplayServer::FileDialogMode(mode), processed_filters, _get_options(), callable_mp(this, &FileDialog::_native_dialog_cb_with_options));
} else {
- DisplayServer::get_singleton()->file_dialog_show(get_translated_title(), ProjectSettings::get_singleton()->globalize_path(dir->get_text()), file->get_text().get_file(), show_hidden_files, DisplayServer::FileDialogMode(mode), filters, callable_mp(this, &FileDialog::_native_dialog_cb));
+ DisplayServer::get_singleton()->file_dialog_show(get_translated_title(), ProjectSettings::get_singleton()->globalize_path(dir->get_text()), file->get_text().get_file(), show_hidden_files, DisplayServer::FileDialogMode(mode), processed_filters, callable_mp(this, &FileDialog::_native_dialog_cb));
}
}
@@ -851,37 +851,54 @@ void FileDialog::_filename_filter_selected() {
void FileDialog::update_filters() {
filter->clear();
+ processed_filters.clear();
if (filters.size() > 1) {
String all_filters;
+ String all_filters_full;
const int max_filters = 5;
for (int i = 0; i < MIN(max_filters, filters.size()); i++) {
- String flt = filters[i].get_slice(";", 0).strip_edges();
+ String flt = filters[i].get_slicec(';', 0).strip_edges();
if (i > 0) {
all_filters += ", ";
}
all_filters += flt;
}
+ for (int i = 0; i < filters.size(); i++) {
+ String flt = filters[i].get_slicec(';', 0).strip_edges();
+ if (i > 0) {
+ all_filters_full += ",";
+ }
+ all_filters_full += flt;
+ }
if (max_filters < filters.size()) {
all_filters += ", ...";
}
- filter->add_item(atr(ETR("All Recognized")) + " (" + all_filters + ")");
+ String f = atr(ETR("All Recognized")) + " (" + all_filters + ")";
+ filter->add_item(f);
+ processed_filters.push_back(all_filters_full + ";" + f);
}
for (int i = 0; i < filters.size(); i++) {
- String flt = filters[i].get_slice(";", 0).strip_edges();
+ String flt = filters[i].get_slicec(';', 0).strip_edges();
String desc = filters[i].get_slice(";", 1).strip_edges();
if (desc.length()) {
- filter->add_item(String(tr(desc)) + " (" + flt + ")");
+ String f = atr(desc) + " (" + flt + ")";
+ filter->add_item(f);
+ processed_filters.push_back(flt + ";" + f);
} else {
- filter->add_item("(" + flt + ")");
+ String f = "(" + flt + ")";
+ filter->add_item(f);
+ processed_filters.push_back(flt + ";" + f);
}
}
- filter->add_item(atr(ETR("All Files")) + " (*)");
+ String f = atr(ETR("All Files")) + " (*)";
+ filter->add_item(f);
+ processed_filters.push_back("*.*;" + f);
}
void FileDialog::clear_filename_filter() {
diff --git a/scene/gui/file_dialog.h b/scene/gui/file_dialog.h
index 28978dbed3..82067ac534 100644
--- a/scene/gui/file_dialog.h
+++ b/scene/gui/file_dialog.h
@@ -101,6 +101,7 @@ private:
Button *show_filename_filter_button = nullptr;
Vector<String> filters;
+ Vector<String> processed_filters;
String file_name_filter;
bool show_filename_filter = false;