GTK4 file chooser ignores file filters in SELECT_FOLDER mode
Steps to reproduce
Self-contained example:
// gcc -o bug bug.c $(pkg-config --cflags --libs gtk4)
#include <gtk/gtk.h>
static void response(GtkFileChooser *dlg, int id, GApplication *app) {
gtk_native_dialog_hide(GTK_NATIVE_DIALOG(dlg));
g_autoptr(GFile) file = gtk_file_chooser_get_file(dlg);
g_autofree char *path = file ? g_file_get_path(file) : g_strdup("(none)");
g_message("%s", path);
g_object_unref(dlg);
g_application_quit(app);
}
static void activate(GApplication *app) {
GtkFileChooserNative* dlg = gtk_file_chooser_native_new("Choose Folder", NULL,
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, NULL, NULL);
GtkFileFilter* filter1 = gtk_file_filter_new();
gtk_file_filter_set_name(filter1, "Test Filter (*.d)");
gtk_file_filter_add_pattern(filter1, "*.d");
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dlg), filter1);
GtkFileFilter* filter2 = gtk_file_filter_new();
gtk_file_filter_set_name(filter2, "All Files");
gtk_file_filter_add_pattern(filter2, "*");
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dlg), filter2);
g_signal_connect(dlg, "response", G_CALLBACK(response), app);
g_application_hold(app);
gtk_native_dialog_show(GTK_NATIVE_DIALOG(dlg));
}
int main(int argc, char *argv[]) {
g_autoptr(GtkApplication) app = gtk_application_new("name.ptomato.Test", 0);
g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
return g_application_run(G_APPLICATION(app), argc, argv);
}
(note, same code as #7036, but compiled with GTK 4 instead of GTK 3)
To reproduce:
- Create a folder nested somewhere named
test.d
. e.g.mkdir -p ~/Downloads/test/test.d
- Run the example program, not sandboxed so you don't get the portal version of the dialog.
- Click on a folder whose name doesn't end in
.d
. - Click "Open".
Current behavior
The dialog's response
signal is emitted, the path to the folder not ending in .d
is printed, and the program ends.
Expected outcome
You should only be able to select (i.e. get a response from the dialog for) folders ending in .d
. The "Open" button should not be sensitive for folders that don't match the file filter. The program should only end if you either cancel the dialog or navigate to ~/Downloads/test/test.d
and select it.
Version information
GTK 4.14.4 Fedora Toolbox 40
Additional information
None.