[libhandy] combo-row: Special case single item models



commit 40912a5f8ec8f551b4e461edd83820f471868ab6
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Thu Aug 6 15:47:29 2020 +0200

    combo-row: Special case single item models
    
    Don't show the arrow and don't make the row activatable when the model
    only contains a single item.
    
    Fixes https://gitlab.gnome.org/GNOME/libhandy/-/issues/269

 src/hdy-combo-row.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)
---
diff --git a/src/hdy-combo-row.c b/src/hdy-combo-row.c
index 0b85953e..e9cc6bf4 100644
--- a/src/hdy-combo-row.c
+++ b/src/hdy-combo-row.c
@@ -178,20 +178,22 @@ update (HdyComboRow *self)
   g_autoptr(GObject) item = NULL;
   g_autofree gchar *name = NULL;
   GtkWidget *widget;
+  guint n_items = priv->bound_model ? g_list_model_get_n_items (priv->bound_model) : 0;
 
   gtk_widget_set_visible (GTK_WIDGET (priv->current), !priv->use_subtitle);
   gtk_container_foreach (GTK_CONTAINER (priv->current), (GtkCallback) gtk_widget_destroy, NULL);
 
-  if (priv->bound_model == NULL || g_list_model_get_n_items (priv->bound_model) == 0) {
-    gtk_widget_set_sensitive (GTK_WIDGET (self), FALSE);
+  gtk_widget_set_sensitive (GTK_WIDGET (self), n_items > 0);
+  gtk_widget_set_visible (GTK_WIDGET (priv->image), n_items > 1);
+  gtk_list_box_row_set_activatable (GTK_LIST_BOX_ROW (self), n_items > 1);
+
+  if (n_items == 0) {
     g_assert (priv->selected_index == -1);
 
     return;
   }
 
-  g_assert (priv->selected_index >= 0 && priv->selected_index <= g_list_model_get_n_items 
(priv->bound_model));
-
-  gtk_widget_set_sensitive (GTK_WIDGET (self), TRUE);
+  g_assert (priv->selected_index >= 0 && priv->selected_index <= n_items);
 
   {
     g_autoptr (GList) rows = gtk_container_get_children (GTK_CONTAINER (priv->list));
@@ -264,7 +266,8 @@ hdy_combo_row_activate (HdyActionRow *row)
   HdyComboRow *self = HDY_COMBO_ROW (row);
   HdyComboRowPrivate *priv = hdy_combo_row_get_instance_private (self);
 
-  gtk_popover_popup (priv->popover);
+  if (gtk_widget_get_visible (GTK_WIDGET (priv->image)))
+    gtk_popover_popup (priv->popover);
 }
 
 static void
@@ -287,8 +290,6 @@ destroy_model (HdyComboRow *self)
   priv->create_current_widget_func = NULL;
   priv->create_widget_func_data = NULL;
   priv->create_widget_func_data_free_func = NULL;
-
-  gtk_list_box_row_set_activatable (GTK_LIST_BOX_ROW (self), FALSE);
 }
 
 static void
@@ -563,8 +564,6 @@ hdy_combo_row_bind_model (HdyComboRow                *self,
 
   gtk_list_box_bind_model (priv->list, model, create_list_widget, self, create_list_widget_data_free);
 
-  gtk_list_box_row_set_activatable (GTK_LIST_BOX_ROW (self), TRUE);
-
   update (self);
 
   g_object_notify_by_pspec (G_OBJECT (self), props[PROP_SELECTED_INDEX]);


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