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.
This commit is contained in:
Ryan Lortie 2013-06-24 17:59:52 -04:00
parent d498e9b588
commit c79a21e1dd

View File

@ -2091,12 +2091,24 @@ gtk_menu_shell_tracker_insert_func (GtkMenuTrackerItem *item,
if (gtk_menu_tracker_item_get_is_separator (item)) if (gtk_menu_tracker_item_get_is_separator (item))
{ {
const gchar *label;
widget = gtk_separator_menu_item_new (); widget = gtk_separator_menu_item_new ();
/* For separators, we bind to the "label" property in case there /* For separators, we may have a section heading, so check the
* is a section heading. * "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)) else if (gtk_menu_tracker_item_get_has_submenu (item))
{ {