filechoosercell: Store type_format in filechoosercell
authorCorey Berla <corey@berla.me>
Mon, 10 Apr 2023 22:14:42 +0000 (15:14 -0700)
committerCorey Berla <corey@berla.me>
Tue, 11 Apr 2023 01:02:35 +0000 (18:02 -0700)
The format of the type column depends on the the type_format, which
is stored in the filechooserwidget.  We get that setting by looking
for the filechooserwidget ancestor, which no longer works after recent
changes to the list views (it was fragile to begin with).  At one point,
the setting appears to have been dynamic, but now it is only loading
from GSettings, so let's simply do the same within FileChooserCell.

gtk/gtkfilechoosercell.c
gtk/gtkfilechoosercellprivate.h
gtk/gtkfilechooserwidget.c

index ee97002d6c17d8d6f2b5c929ce88203a9dff4da4..090d17d1ee2f81228a7a69e7b79bfc197cbe912b 100644 (file)
@@ -39,6 +39,8 @@ struct _GtkFileChooserCell
   GFileInfo *item;
   GtkColumnViewCell *list_item;
 
+  guint type_format;
+
   gboolean show_time;
 };
 
@@ -59,6 +61,12 @@ enum
 
 #define ICON_SIZE 16
 
+guint
+gtk_file_chooser_cell_get_type_format (GtkFileChooserCell *self)
+{
+  return self->type_format;
+}
+
 static void
 popup_menu (GtkFileChooserCell *self,
             double              x,
@@ -167,6 +175,11 @@ gtk_file_chooser_cell_init (GtkFileChooserCell *self)
 {
   GtkGesture *gesture;
   GtkDragSource *drag_source;
+  GSettings *settings;
+
+  settings = _gtk_file_chooser_get_settings_for_widget (GTK_WIDGET (self));
+
+  self->type_format = g_settings_get_enum (settings, SETTINGS_KEY_TYPE_FORMAT);
 
   gesture = gtk_gesture_click_new ();
   gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), GDK_BUTTON_SECONDARY);
index 55c52e9c46d8ff8c5f5923bde44202a5302619ec..dfe9792e7cf63953a3bd2069d78d8de1c7a15420 100644 (file)
@@ -31,5 +31,7 @@ G_DECLARE_FINAL_TYPE (GtkFileChooserCell, gtk_file_chooser_cell, GTK, FILE_CHOOS
 
 GtkFileChooserCell * gtk_file_chooser_cell_new (void);
 
+guint                gtk_file_chooser_cell_get_type_format (GtkFileChooserCell *self);
+
 G_END_DECLS
 
index ab368fc92609cb7d633b9fa9ab5cac7367a8c01f..92ec6c7ad23df6fd7a50303de5b1f8dbbe82e076 100644 (file)
@@ -505,8 +505,8 @@ static void     set_model_filter             (GtkFileChooserWidget *impl,
 static void     switch_to_home_dir           (GtkFileChooserWidget *impl);
 static void     set_show_hidden              (GtkFileChooserWidget *impl,
                                               gboolean              show_hidden);
-static char *   get_type_information         (GtkFileChooserWidget *impl,
-                                              GFileInfo            *info);
+static char *   get_type_information         (TypeFormat type_format,
+                                              GFileInfo *info);
 static char *   my_g_format_date_for_display (GtkFileChooserWidget *impl,
                                               glong                 secs);
 static char *   my_g_format_time_for_display (GtkFileChooserWidget *impl,
@@ -2011,17 +2011,17 @@ static char *
 column_view_get_file_type (GtkColumnViewCell *cell,
                            GFileInfo        *info)
 {
-  GtkFileChooserWidget *impl;
+  GtkFileChooserCell *child;
 
   if (!info || _gtk_file_info_consider_as_directory (info))
     return NULL;
 
-  impl = GTK_FILE_CHOOSER_WIDGET (gtk_widget_get_ancestor (gtk_list_item_get_child (item),
-                                                           GTK_TYPE_FILE_CHOOSER_WIDGET));
-  if (!impl)
+  child = GTK_FILE_CHOOSER_CELL (gtk_column_view_cell_get_child (cell));
+
+  if (!child)
     return NULL;
 
-  return get_type_information (impl, info);
+  return get_type_information (gtk_file_chooser_cell_get_type_format (child), info);
 }
 
 static void
@@ -3284,7 +3284,6 @@ settings_save (GtkFileChooserWidget *impl)
   g_settings_set_int (settings, SETTINGS_KEY_SIDEBAR_WIDTH,
                       gtk_paned_get_position (GTK_PANED (impl->browse_widgets_hpaned)));
   g_settings_set_enum (settings, SETTINGS_KEY_DATE_FORMAT, impl->show_time ? DATE_FORMAT_WITH_TIME : DATE_FORMAT_REGULAR);
-  g_settings_set_enum (settings, SETTINGS_KEY_TYPE_FORMAT, impl->type_format);
   g_settings_set_enum (settings, SETTINGS_KEY_VIEW_TYPE, impl->view_type);
 
   /* Now apply the settings */
@@ -3947,8 +3946,8 @@ get_category_from_content_type (const char *content_type)
 }
 
 static char *
-get_type_information (GtkFileChooserWidget *impl,
-                      GFileInfo            *info)
+get_type_information (TypeFormat type_format,
+                      GFileInfo *info)
 {
   const char *content_type;
   char *mime_type;
@@ -3960,7 +3959,7 @@ get_type_information (GtkFileChooserWidget *impl,
   if (!content_type)
     goto end;
 
-  switch (impl->type_format)
+  switch (type_format)
     {
     case TYPE_FORMAT_MIME:
       mime_type = g_content_type_get_mime_type (content_type);
@@ -7085,8 +7084,8 @@ type_sort_func (gconstpointer a,
   GtkOrdering result;
 
   /* FIXME: use sortkeys for these */
-  key_a = get_type_information (impl, (GFileInfo *)a);
-  key_b = get_type_information (impl, (GFileInfo *)b);
+  key_a = get_type_information (impl->type_format, (GFileInfo *)a);
+  key_b = get_type_information (impl->type_format, (GFileInfo *)b);
 
   result = g_strcmp0 (key_a, key_b);