[gtk/1397-gtknotebook-built-in-popup-menu-listing-tabs-doesn-t-use-tab-label-text-for-the-last-tab] Notebook: Ensure menu_label updates with tab_label



commit 80a3d7090a3dadef15f9c320373758429226525d
Author: Daniel Boles <dboles src gmail com>
Date:   Fri Oct 12 23:12:53 2018 +0100

    Notebook: Ensure menu_label updates with tab_label
    
    This was noticed in Firefox and demonstrated using a GtkBuilder ui file.
    buildable_add_child() calls set_tab_label(), but the latter did nothing
    to update the menu_label corresponding to that tab with the new text.
    Using Builder to populate the tab child, only tabs other than last got
    the right non-default labels, and even that was mostly coincidental, as
    adding the main child called update_labels() via real_insert_page(), so
    it took effect when the 2nd last main child is added, updating the rest
    but leaving the last with the default label, not that given in Builder.
    
    Fix by factoring out the code from child_reordered() to a new helper
    menu_item_recreate() and calling that in set_tab_label(), so that
    whenever the tab_label is updated, so is its corresponding menu_label.
    
    This fixes the reported case and presumably others that we could write.
    
    fixes https://gitlab.gnome.org/GNOME/gtk/issues/1397

 gtk/gtknotebook.c | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)
---
diff --git a/gtk/gtknotebook.c b/gtk/gtknotebook.c
index 363f370d99..0de4281412 100644
--- a/gtk/gtknotebook.c
+++ b/gtk/gtknotebook.c
@@ -562,6 +562,8 @@ static void gtk_notebook_menu_switch_page    (GtkWidget        *widget,
 /*** GtkNotebook Menu Functions ***/
 static void gtk_notebook_menu_item_create    (GtkNotebook      *notebook,
                                               GList            *list);
+static void gtk_notebook_menu_item_recreate  (GtkNotebook      *notebook,
+                                              GList            *list);
 static void gtk_notebook_menu_label_unparent (GtkWidget        *widget,
                                               gpointer          data);
 static void gtk_notebook_menu_detacher       (GtkWidget        *widget,
@@ -6335,6 +6337,7 @@ gtk_notebook_menu_switch_page (GtkWidget       *widget,
 /* Private GtkNotebook Menu Functions:
  *
  * gtk_notebook_menu_item_create
+ * gtk_notebook_menu_item_recreate
  * gtk_notebook_menu_label_unparent
  * gtk_notebook_menu_detacher
  */
@@ -6368,6 +6371,19 @@ gtk_notebook_menu_item_create (GtkNotebook *notebook,
     gtk_widget_show (menu_item);
 }
 
+static void
+gtk_notebook_menu_item_recreate (GtkNotebook *notebook,
+                                 GList       *list)
+{
+  GtkNotebookPrivate *priv = notebook->priv;
+  GtkNotebookPage *page = list->data;
+  GtkWidget *menu_item = gtk_widget_get_parent (page->menu_label);
+
+  gtk_container_remove (GTK_CONTAINER (menu_item), page->menu_label);
+  gtk_container_remove (GTK_CONTAINER (priv->menu), menu_item);
+  gtk_notebook_menu_item_create (notebook, list);
+}
+
 static void
 gtk_notebook_menu_label_unparent (GtkWidget *widget,
                                   gpointer  data)
@@ -7363,7 +7379,6 @@ gtk_notebook_set_tab_label (GtkNotebook *notebook,
   if (page->tab_label == tab_label)
     return;
 
-
   gtk_notebook_remove_tab_label (notebook, page);
 
   if (tab_label)
@@ -7405,6 +7420,9 @@ gtk_notebook_set_tab_label (GtkNotebook *notebook,
       gtk_widget_queue_resize (GTK_WIDGET (notebook));
     }
 
+  if (priv->menu)
+    gtk_notebook_menu_item_recreate (notebook, list);
+
   gtk_widget_child_notify (child, "tab-label");
 }
 
@@ -7610,14 +7628,7 @@ gtk_notebook_child_reordered (GtkNotebook     *notebook,
   list = g_list_find (priv->children, page);
 
   if (priv->menu)
-    {
-      GtkWidget *menu_item;
-
-      menu_item = gtk_widget_get_parent (page->menu_label);
-      gtk_container_remove (GTK_CONTAINER (menu_item), page->menu_label);
-      gtk_container_remove (GTK_CONTAINER (priv->menu), menu_item);
-      gtk_notebook_menu_item_create (notebook, list);
-    }
+    gtk_notebook_menu_item_recreate (notebook, list);
 
   if (list->prev)
     sibling = gtk_css_gadget_get_node (GTK_NOTEBOOK_PAGE (list->prev)->gadget);


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