[libadwaita/wip/exalm/combo-row-fixes: 1/2] combo-row: Fix subtitles when the model has 0 items




commit eb8566f38d9caa195c4898cdb82b3ea3178d57b1
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Mon Jun 21 13:29:48 2021 +0500

    combo-row: Fix subtitles when the model has 0 items

 src/adw-combo-row.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
---
diff --git a/src/adw-combo-row.c b/src/adw-combo-row.c
index d1587e71..7702f469 100644
--- a/src/adw-combo-row.c
+++ b/src/adw-combo-row.c
@@ -112,12 +112,16 @@ selection_changed (AdwComboRow *self)
   selected = gtk_single_selection_get_selected (GTK_SINGLE_SELECTION (priv->selection));
 
   if (priv->use_subtitle) {
-    GtkListItem *item = g_list_model_get_item (G_LIST_MODEL (priv->current_selection), 0);
-    g_autofree char *repr = get_item_representation (self, item);
+    if (g_list_model_get_n_items (G_LIST_MODEL (priv->current_selection)) > 0) {
+      GtkListItem *item = g_list_model_get_item (G_LIST_MODEL (priv->current_selection), 0);
+      g_autofree char *repr = get_item_representation (self, item);
 
-    adw_action_row_set_subtitle (ADW_ACTION_ROW (self), repr);
+      adw_action_row_set_subtitle (ADW_ACTION_ROW (self), repr);
 
-    g_object_unref (item);
+      g_object_unref (item);
+    } else {
+      adw_action_row_set_subtitle (ADW_ACTION_ROW (self), NULL);
+    }
   }
 
   gtk_single_selection_set_selected (GTK_SINGLE_SELECTION (priv->popup_selection), selected);


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