filechooser: Set selectability for list items
authorMatthias Clasen <mclasen@redhat.com>
Fri, 10 Mar 2023 14:18:26 +0000 (15:18 +0100)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 10 Mar 2023 14:40:43 +0000 (15:40 +0100)
We propagate this from the list items to the
GtkListItems. Twisty!

gtk/gtkfilechoosercell.c
gtk/ui/gtkfilechooserwidget.ui

index 901e94d7b402ed0fd1f10c8216420f500220cb1c..dd003bf93dde1a3ae35e46d159562b277b006a52 100644 (file)
@@ -31,6 +31,7 @@
 #include "gtkselectionmodel.h"
 #include "gtkfilechooserutils.h"
 #include "gtkfilechooserwidgetprivate.h"
+#include "gtklistitem.h"
 
 struct _GtkFileChooserCell
 {
@@ -39,6 +40,7 @@ struct _GtkFileChooserCell
   GFileInfo *item;
   gboolean selected;
   guint position;
+  GtkListItem *list_item;
 
   gboolean show_time;
 };
@@ -56,6 +58,7 @@ enum
   PROP_SELECTED,
   PROP_ITEM,
   PROP_SHOW_TIME,
+  PROP_LIST_ITEM,
 };
 
 #define ICON_SIZE 16
@@ -206,6 +209,13 @@ get_selectable (GtkFileChooserCell *self)
   return TRUE;
 }
 
+static void
+update_list_item (GtkFileChooserCell *self)
+{
+  if (self->list_item)
+    gtk_list_item_set_selectable (self->list_item, get_selectable (self));
+}
+
 static void
 gtk_file_chooser_cell_set_property (GObject      *object,
                                     guint         prop_id,
@@ -231,12 +241,20 @@ gtk_file_chooser_cell_set_property (GObject      *object,
         gtk_widget_remove_css_class (GTK_WIDGET (self), "dim-label");
       else
         gtk_widget_add_css_class (GTK_WIDGET (self), "dim-label");
+
+      update_list_item (self);
       break;
 
     case PROP_SHOW_TIME:
       self->show_time = g_value_get_boolean (value);
       break;
 
+    case PROP_LIST_ITEM:
+      self->list_item = g_value_get_object (value);
+
+      update_list_item (self);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -306,6 +324,11 @@ gtk_file_chooser_cell_class_init (GtkFileChooserCellClass *klass)
                                                          FALSE,
                                                          GTK_PARAM_READWRITE));
 
+  g_object_class_install_property (object_class, PROP_LIST_ITEM,
+                                   g_param_spec_object ("list-item", NULL, NULL,
+                                                        GTK_TYPE_LIST_ITEM,
+                                                        GTK_PARAM_WRITABLE));
+
   gtk_widget_class_set_css_name (widget_class, I_("filelistcell"));
   gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
 }
index f7a7c9a5ec628824e2ef768a4b8ff625206a2f29..a5e4d3ca5d2f22fa01e503c2adbb6541434cc834 100644 (file)
         <binding name="selected">
           <lookup name="selected">GtkListItem</lookup>
         </binding>
+        <property name="list-item">GtkListItem</property>
         <child>
           <object class="GtkBox">
             <binding name="tooltip-text">
         <binding name="selected">
           <lookup name="selected">GtkListItem</lookup>
         </binding>
+        <property name="list-item">GtkListItem</property>
         <child>
           <object class="GtkInscription">
             <property name="hexpand">1</property>
         <binding name="selected">
           <lookup name="selected">GtkListItem</lookup>
         </binding>
+        <property name="list-item">GtkListItem</property>
         <child>
           <object class="GtkLabel">
             <property name="hexpand">1</property>
         <binding name="selected">
           <lookup name="selected">GtkListItem</lookup>
         </binding>
+        <property name="list-item">GtkListItem</property>
         <child>
           <object class="GtkLabel">
             <property name="hexpand">1</property>
         <binding name="selected">
           <lookup name="selected">GtkListItem</lookup>
         </binding>
+        <property name="list-item">GtkListItem</property>
         <child>
           <object class="GtkBox">
             <property name="spacing">6</property>
         <binding name="selected">
           <lookup name="selected">GtkListItem</lookup>
         </binding>
+        <property name="list-item">GtkListItem</property>
         <child>
           <object class="GtkBox">
             <property name="orientation">vertical</property>