[gtk/gbsneto/filechooser-column-view] filechooser: Add show-time property



commit ccbfcccc45bdc0c6bb2025392cd705982b3e2e6a
Author: Corey Berla <corey berla me>
Date:   Wed Oct 19 12:42:56 2022 -0700

    filechooser: Add show-time property
    
    The "Show Time" setting does not take immediate effect (only after
    changing folders) because it's set as a single call to
    column_view_get_time_visible() on the FileChooserCell creation.
    Instead create a bind a show-time property that gets updated
    as the setting is changed.

 gtk/gtkfilechoosercell.c       | 30 ++++++++++++++++++++++++++++++
 gtk/gtkfilechooserwidget.c     | 27 ++++++++++++---------------
 gtk/ui/gtkfilechooserwidget.ui |  6 ++----
 3 files changed, 44 insertions(+), 19 deletions(-)
---
diff --git a/gtk/gtkfilechoosercell.c b/gtk/gtkfilechoosercell.c
index cb81322234..655f54c46f 100644
--- a/gtk/gtkfilechoosercell.c
+++ b/gtk/gtkfilechoosercell.c
@@ -40,6 +40,8 @@ struct _GtkFileChooserCell
   GFileInfo *item;
   gboolean selected;
   guint position;
+
+  gboolean show_time;
 };
 
 struct _GtkFileChooserCellClass
@@ -54,6 +56,7 @@ enum
   PROP_POSITION = 1,
   PROP_SELECTED,
   PROP_ITEM,
+  PROP_SHOW_TIME,
 };
 
 #define ICON_SIZE 16
@@ -144,6 +147,18 @@ drag_prepare_cb (GtkDragSource *source,
   return provider;
 }
 
+static void
+gtk_file_chooser_cell_realize (GtkWidget *widget)
+{
+  GtkFileChooserCell *self = GTK_FILE_CHOOSER_CELL (widget);
+  GtkFileChooserWidget *impl;
+
+  impl = GTK_FILE_CHOOSER_WIDGET (gtk_widget_get_ancestor (GTK_WIDGET (self),
+                                                           GTK_TYPE_FILE_CHOOSER_WIDGET));
+
+  g_object_bind_property (impl, "show-time", self, "show-time", G_BINDING_SYNC_CREATE);
+}
+
 static void
 gtk_file_chooser_cell_init (GtkFileChooserCell *self)
 {
@@ -161,6 +176,8 @@ gtk_file_chooser_cell_init (GtkFileChooserCell *self)
   drag_source = gtk_drag_source_new ();
   gtk_widget_add_controller (GTK_WIDGET (self), GTK_EVENT_CONTROLLER (drag_source));
   g_signal_connect (drag_source, "prepare", G_CALLBACK (drag_prepare_cb), self);
+
+  g_signal_connect (self, "realize", G_CALLBACK (gtk_file_chooser_cell_realize), NULL);
 }
 
 static void
@@ -196,6 +213,10 @@ gtk_file_chooser_cell_set_property (GObject      *object,
       self->item = g_value_get_object (value);
       break;
 
+    case PROP_SHOW_TIME:
+      self->show_time = g_value_get_boolean (value);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -224,6 +245,10 @@ gtk_file_chooser_cell_get_property (GObject    *object,
       g_value_set_object (value, self->item);
       break;
 
+    case PROP_SHOW_TIME:
+      g_value_set_boolean (value, self->show_time);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -256,6 +281,11 @@ gtk_file_chooser_cell_class_init (GtkFileChooserCellClass *klass)
                                                         G_TYPE_FILE_INFO,
                                                         GTK_PARAM_READWRITE));
 
+  g_object_class_install_property (object_class, PROP_SHOW_TIME,
+                                   g_param_spec_boolean ("show-time", NULL, NULL,
+                                                         FALSE,
+                                                         GTK_PARAM_READWRITE));
+
   gtk_widget_class_set_css_name (widget_class, I_("filelistcell"));
   gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
 }
diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c
index 78599f024c..8308d1a3c9 100644
--- a/gtk/gtkfilechooserwidget.c
+++ b/gtk/gtkfilechooserwidget.c
@@ -121,7 +121,8 @@ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
 
 enum {
   PROP_SEARCH_MODE = 1,
-  PROP_SUBTITLE
+  PROP_SUBTITLE,
+  PROP_SHOW_TIME,
 };
 
 typedef enum {
@@ -1480,6 +1481,7 @@ change_show_time_state (GSimpleAction *action,
 
   g_simple_action_set_state (action, state);
   impl->show_time = g_variant_get_boolean (state);
+  g_object_notify (G_OBJECT (impl), "show-time");
 }
 
 /* Shows an error dialog about not being able to select a dragged file */
@@ -2006,19 +2008,6 @@ column_view_get_size (GtkListItem *item,
     return NULL;
 }
 
-static gboolean
-column_view_get_time_visible (GtkListItem *item)
-{
-  GtkFileChooserWidget *impl;
-
-  impl = GTK_FILE_CHOOSER_WIDGET (gtk_widget_get_ancestor (gtk_list_item_get_child (item),
-                                                           GTK_TYPE_FILE_CHOOSER_WIDGET));
-  if (!impl)
-    return FALSE;
-
-  return impl->show_time;
-}
-
 static char *
 column_view_get_tooltip_text (GtkListItem *list_item,
                               GFileInfo   *info)
@@ -2959,6 +2948,10 @@ gtk_file_chooser_widget_get_property (GObject    *object,
       g_value_take_string (value, gtk_file_chooser_widget_get_subtitle (impl));
       break;
 
+    case PROP_SHOW_TIME:
+      g_value_set_boolean (value, impl->show_time);
+      break;
+
     case GTK_FILE_CHOOSER_PROP_ACTION:
       g_value_set_enum (value, impl->action);
       break;
@@ -6651,6 +6644,11 @@ gtk_file_chooser_widget_class_init (GtkFileChooserWidgetClass *class)
                                                         "",
                                                         GTK_PARAM_READABLE));
 
+  g_object_class_install_property (gobject_class, PROP_SHOW_TIME,
+                                   g_param_spec_boolean ("show-time", NULL, NULL,
+                                                         FALSE,
+                                                         GTK_PARAM_READABLE));
+
   _gtk_file_chooser_install_properties (gobject_class);
 
   /* Bind class to template */
@@ -6713,7 +6711,6 @@ gtk_file_chooser_widget_class_init (GtkFileChooserWidgetClass *class)
   gtk_widget_class_bind_template_callback (widget_class, column_view_get_file_type);
   gtk_widget_class_bind_template_callback (widget_class, column_view_get_location);
   gtk_widget_class_bind_template_callback (widget_class, column_view_get_size);
-  gtk_widget_class_bind_template_callback (widget_class, column_view_get_time_visible);
   gtk_widget_class_bind_template_callback (widget_class, column_view_get_tooltip_text);
   gtk_widget_class_bind_template_callback (widget_class, column_view_row_activated_cb);
 
diff --git a/gtk/ui/gtkfilechooserwidget.ui b/gtk/ui/gtkfilechooserwidget.ui
index 5a12539965..703c956a3c 100644
--- a/gtk/ui/gtkfilechooserwidget.ui
+++ b/gtk/ui/gtkfilechooserwidget.ui
@@ -360,7 +360,7 @@
 <interface>
   <template class="GtkListItem">
     <property name="child">
-      <object class="GtkFileChooserCell">
+      <object class="GtkFileChooserCell" id="file_chooser_cell">
         <binding name="position">
           <lookup name="position">GtkListItem</lookup>
         </binding>
@@ -389,9 +389,7 @@
             </child>
             <child>
               <object class="GtkLabel">
-                <binding name="visible">
-                  <closure type="gboolean" function="column_view_get_time_visible" />
-                </binding>
+                <property name="visible" bind-source="file_chooser_cell" bind-property="show-time" 
bind-flags="sync-create"/>
                 <binding name="label">
                   <closure type="gchararray" function="column_view_get_file_time">
                     <lookup name="item">GtkListItem</lookup>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]