[gtk+] menu model: set separator label conditionally



commit c79a21e1ddda961be43813daa9179505af89adb7
Author: Ryan Lortie <desrt desrt ca>
Date:   Mon Jun 24 17:59:52 2013 -0400

    menu model: set separator label conditionally
    
    When creating separators we were binding the "label" property on the
    tracker to the "label" property on the GtkSeparatorMenuItem.
    
    This was problematic for two reasons.
    
    First, it was pointless.  The section header label will never change.
    
    Second, it was causing problems: doing the binding caused the value to
    be initially synced up, even if it was NULL.  Doing this caused
    GtkMenuItem to create a GtkAccelLabel and add it as a child, which
    prevented the separator from being shown normally.
    
    Change the code a bit so that we just call gtk_menu_item_set_label()
    when creating the item, if we find the label to be non-NULL.
    
    Also, show() the separator item at first.  GtkMenu manages visibility of
    separators internally, but it seems "more correct" to show it ourselves
    at first.

 gtk/gtkmenushell.c |   18 +++++++++++++++---
 1 files changed, 15 insertions(+), 3 deletions(-)
---
diff --git a/gtk/gtkmenushell.c b/gtk/gtkmenushell.c
index b82d33b..2318a4e 100644
--- a/gtk/gtkmenushell.c
+++ b/gtk/gtkmenushell.c
@@ -2091,12 +2091,24 @@ gtk_menu_shell_tracker_insert_func (GtkMenuTrackerItem *item,
 
   if (gtk_menu_tracker_item_get_is_separator (item))
     {
+      const gchar *label;
+
       widget = gtk_separator_menu_item_new ();
 
-      /* For separators, we bind to the "label" property in case there
-       * is a section heading.
+      /* For separators, we may have a section heading, so check the
+       * "label" property.
+       *
+       * Note: we only do this once, and we only do it if the label is
+       * non-NULL because even setting a NULL label on the separator
+       * will be enough to create a GtkLabel and add it, changing the
+       * appearance in the process.
        */
-      g_object_bind_property (item, "label", widget, "label", G_BINDING_SYNC_CREATE);
+
+      label = gtk_menu_tracker_item_get_label (item);
+      if (label)
+        gtk_menu_item_set_label (GTK_MENU_ITEM (widget), label);
+
+      gtk_widget_show (widget);
     }
   else if (gtk_menu_tracker_item_get_has_submenu (item))
     {


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