[gtk+] Statusbar: Remove matching messages before popping



commit e853007cd0186e141559b967af852156477092b3
Author: Phillip Wood <phillip wood dunelm org uk>
Date:   Wed Feb 12 15:56:11 2014 +0000

    Statusbar: Remove matching messages before popping
    
    gtk_statusbar_remove_all() was popping the top message if its
    context_id matched before removing other matching messages from the
    stack. This meant that if the context_id of the second top message
    matched it was still displayed when the top message was popped and
    then removed from the list of messages without updating the display.
    Fix this by removing all the matching messages below the top one
    before popping it if it matches.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=724281

 gtk/gtkstatusbar.c |   42 ++++++++++++++++--------------------------
 1 files changed, 16 insertions(+), 26 deletions(-)
---
diff --git a/gtk/gtkstatusbar.c b/gtk/gtkstatusbar.c
index a49457f..18f974e 100644
--- a/gtk/gtkstatusbar.c
+++ b/gtk/gtkstatusbar.c
@@ -456,21 +456,13 @@ gtk_statusbar_remove_all (GtkStatusbar *statusbar,
   if (priv->messages == NULL)
     return;
 
-  msg = priv->messages->data;
-
-  /* care about signal emission if the topmost item is removed */
-  if (msg->context_id == context_id)
-    {
-      gtk_statusbar_pop (statusbar, context_id);
-
-      prev = NULL;
-      list = priv->messages;
-    }
-  else
-    {
-      prev = priv->messages;
-      list = prev->next;
-    }
+  /* We special-case the topmost message at the bottom of this
+   * function:
+   * If we need to pop it, we have to update various state and we want
+   * an up-to-date list of remaining messages in that case.
+   */
+  prev = priv->messages;
+  list = prev->next;
 
   while (list != NULL)
     {
@@ -478,21 +470,12 @@ gtk_statusbar_remove_all (GtkStatusbar *statusbar,
 
       if (msg->context_id == context_id)
         {
-          if (prev == NULL)
-            priv->messages = list->next;
-          else
-            prev->next = list->next;
+          prev->next = list->next;
 
           gtk_statusbar_msg_free (msg);
           g_slist_free_1 (list);
 
-          if (prev == NULL)
-            prev = priv->messages;
-
-          if (prev)
-            list = prev->next;
-          else
-            list = NULL;
+          list = prev->next;
         }
       else
         {
@@ -500,6 +483,13 @@ gtk_statusbar_remove_all (GtkStatusbar *statusbar,
           list = prev->next;
         }
     }
+
+  /* Treat topmost message here */
+  msg = priv->messages->data;
+  if (msg->context_id == context_id)
+    {
+      gtk_statusbar_pop (statusbar, context_id);
+    }
 }
 
 /**


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