[gtk/stack-fixes] stack switcher: Handle unselection robustly



commit cd3c71cb03989197ca3f2db7d73a07d297e0e74a
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Feb 9 20:09:32 2019 -0500

    stack switcher: Handle unselection robustly
    
    When item are removed, we sometimes get ::selection-changed
    notification for an item that is already gone. If this happens,
    the button is already removed anyway, so we can just ignore it.

 gtk/gtkstackswitcher.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
---
diff --git a/gtk/gtkstackswitcher.c b/gtk/gtkstackswitcher.c
index e7e8e8353e..fa9b94459d 100644
--- a/gtk/gtkstackswitcher.c
+++ b/gtk/gtkstackswitcher.c
@@ -382,23 +382,19 @@ selection_changed_cb (GtkSelectionModel *model,
 {
   GtkStackSwitcherPrivate *priv = gtk_stack_switcher_get_instance_private (switcher);
   guint i;
+  guint end;
 
-  for (i = position; i < position + n_items; i++)
+  end = MIN (position + n_items, g_list_model_get_n_items (G_LIST_MODEL (model)));
+  for (i = position; i < end; i++)
     {
       GtkWidget *child;
       GtkWidget *button;
       gboolean selected;
 
       child = g_list_model_get_item (G_LIST_MODEL (priv->pages), i);
-      if (child == NULL)
-        continue;
-
       button = g_hash_table_lookup (priv->buttons, child);
-      if (button)
-        {
-          selected = gtk_selection_model_is_selected (priv->pages, i);
-          gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), selected);
-        }
+      selected = gtk_selection_model_is_selected (priv->pages, i);
+      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), selected);
       g_object_unref (child);
     }
 }


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