filesystemmodel: Always set standard::file attribute
authorGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>
Sun, 9 Oct 2022 21:50:23 +0000 (18:50 -0300)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 21 Oct 2022 02:34:40 +0000 (22:34 -0400)
This will help us greatly when porting GtkFileSystemModel to
GtkDirectoryList.

gtk/gtkfilechooserentry.c
gtk/gtkfilesystemmodel.c

index 84916500bee1903f00cf45cef993ca1bb8cbf138..5621e7b6253718a7d0d9333319d1e6ab671e84c5 100644 (file)
@@ -197,7 +197,6 @@ match_func (GtkEntryCompletion *compl,
    * current file filter (e.g. just jpg files) here. */
   if (chooser_entry->current_filter != NULL)
     {
-      GFile *file;
       GFileInfo *info;
 
       file = _gtk_file_system_model_get_file (GTK_FILE_SYSTEM_MODEL (chooser_entry->completion_store),
@@ -209,8 +208,7 @@ match_func (GtkEntryCompletion *compl,
       if (g_file_info_get_file_type (info) != G_FILE_TYPE_REGULAR)
         return TRUE;
 
-      if (!g_file_info_has_attribute (info, "standard::file"))
-        g_file_info_set_attribute_object (info, "standard::file", G_OBJECT (file));
+      g_assert (g_file_info_has_attribute (info, "standard::file"));
 
       return gtk_filter_match (GTK_FILTER (chooser_entry->current_filter), info);
     }
index 06fa65808a6174e510ed1619640a1eaf72736cca..9989c235343a57fa4653c8163c050f73ab83356e 100644 (file)
@@ -366,8 +366,7 @@ node_should_be_filtered_out (GtkFileSystemModel *model, guint id)
   if (model->filter == NULL)
     return FALSE;
 
-  if (!g_file_info_has_attribute (node->info, "standard::file"))
-    g_file_info_set_attribute_object (node->info, "standard::file", G_OBJECT (node->file));
+  g_assert (g_file_info_has_attribute (node->info, "standard::file"));
 
   return !gtk_filter_match (GTK_FILTER (model->filter), node->info);
 }
@@ -1612,7 +1611,10 @@ add_file (GtkFileSystemModel *model,
   node = g_slice_alloc0 (model->node_size);
   node->file = g_object_ref (file);
   if (info)
-    node->info = g_object_ref (info);
+    {
+      g_file_info_set_attribute_object (info, "standard::file", G_OBJECT (file));
+      node->info = g_object_ref (info);
+    }
   node->frozen_add = model->frozen ? TRUE : FALSE;
 
   g_array_append_vals (model->files, node, 1);
@@ -1722,6 +1724,8 @@ _gtk_file_system_model_update_file (GtkFileSystemModel *model,
         g_value_unset (&node->values[i]);
     }
 
+  g_file_info_set_attribute_object (info, "standard::file", G_OBJECT (file));
+
   if (node->visible)
     emit_row_changed_for_node (model, id);
 }