From 2b8fd89fd5e24f290f82f04fc319aa7fe7d07751 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 12 Apr 2023 12:07:30 +0200 Subject: [PATCH 1/2] filechooserentry: Make filtering work again We need to look at the filchooser::filtered-out attribute to know which files the filesystem model has filtered away. Fixes: #5743 --- gtk/gtkfilechooserentry.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/gtk/gtkfilechooserentry.c b/gtk/gtkfilechooserentry.c index 4f3d2f8c7f..6c50524adb 100644 --- a/gtk/gtkfilechooserentry.c +++ b/gtk/gtkfilechooserentry.c @@ -193,28 +193,30 @@ match_func (GtkEntryCompletion *compl, gpointer user_data) { GtkFileChooserEntry *chooser_entry = user_data; + GFileInfo *info; + + gtk_tree_model_get (GTK_TREE_MODEL (chooser_entry->completion_store), + iter, + FILE_INFO_COLUMN, &info, + -1); + + g_assert (info != NULL); + g_object_unref (info); + + if (g_file_info_get_attribute_boolean (info, "filechooser::filtered-out")) + return FALSE; /* If we arrive here, the GtkFileSystemModel's GtkFileFilter already filtered out all * files that don't start with the current prefix, so we manually apply the GtkFileChooser's - * current file filter (e.g. just jpg files) here. */ + * current file filter (e.g. just jpg files) here. + */ if (chooser_entry->current_filter != NULL) { - GFileInfo *info; - - gtk_tree_model_get (GTK_TREE_MODEL (chooser_entry->completion_store), - iter, - FILE_INFO_COLUMN, &info, - -1); - - g_assert (info != NULL); - g_object_unref (info); - /* We always allow navigating into subfolders, so don't ever filter directories */ if (g_file_info_get_file_type (info) != G_FILE_TYPE_REGULAR) return TRUE; g_assert (g_file_info_has_attribute (info, "standard::file")); - return gtk_filter_match (GTK_FILTER (chooser_entry->current_filter), info); } From 4df72732668959ced21f3b0800708f6491e52d53 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 12 Apr 2023 12:08:14 +0200 Subject: [PATCH 2/2] filechooserentry: Plug a memory leak --- gtk/gtkfilechooserentry.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gtk/gtkfilechooserentry.c b/gtk/gtkfilechooserentry.c index 6c50524adb..e10ad94890 100644 --- a/gtk/gtkfilechooserentry.c +++ b/gtk/gtkfilechooserentry.c @@ -600,6 +600,9 @@ model_items_changed_cb (GListModel *model, DISPLAY_NAME_COLUMN, display_name, -1); + g_free (display_name); + g_free (full_path); + g_clear_object (&info); position++;