diff options
author | Michael Terry <mike@mterry.name> | 2011-04-15 15:26:38 -0400 |
---|---|---|
committer | Michael Terry <mike@mterry.name> | 2011-04-15 15:26:38 -0400 |
commit | 65258ccaba141816a7ff071a6944b6e9cad3c0dc (patch) | |
tree | 9ca671fa47d80f5c92f0a0629eeb886d44d2711a | |
parent | 199c68f1e85dec4fefb56c6e64fc93ac2616f334 (diff) | |
parent | 172d807186f6ca422105018d55d25710040bc8f4 (diff) | |
download | libdbusmenu-65258ccaba141816a7ff071a6944b6e9cad3c0dc.tar.gz libdbusmenu-65258ccaba141816a7ff071a6944b6e9cad3c0dc.tar.bz2 libdbusmenu-65258ccaba141816a7ff071a6944b6e9cad3c0dc.zip |
merge from trunk
-rw-r--r-- | libdbusmenu-gtk/parser.c | 57 |
1 files changed, 34 insertions, 23 deletions
diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 79153d5..4bc7f69 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -271,6 +271,23 @@ new_menuitem (GtkWidget * widget) } static void +watch_submenu(DbusmenuMenuitem * mi, GtkWidget * menu) +{ + ParserData *pdata = (ParserData *)g_object_get_data(G_OBJECT(mi), PARSER_DATA); + + pdata->shell = menu; + g_signal_connect (G_OBJECT (menu), + "child-added", + G_CALLBACK (child_added_cb), + mi); + g_signal_connect (G_OBJECT (menu), + "child-removed", + G_CALLBACK (child_removed_cb), + mi); + g_object_add_weak_pointer(G_OBJECT (menu), (gpointer*)&pdata->shell); +} + +static void parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) { /* If this is a shell, then let's handle the items in it. */ @@ -290,6 +307,20 @@ parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) GList *iter; for (iter = children; iter != NULL; iter = iter->next) { + /* Make sure that we have a menu item before we start calling + functions that depend on it. This should almost always be + the case. */ + if (!GTK_IS_MENU_ITEM(iter->data)) { + continue; + } + + /* If the item is not opening a submenu we don't want to activate + it as that'd cause an action. Like opening a preferences dialog + to the user. That's not a good idea. */ + if (gtk_menu_item_get_submenu(GTK_MENU_ITEM(iter->data)) == NULL) { + continue; + } + gtk_menu_shell_activate_item (GTK_MENU_SHELL (widget), iter->data, TRUE); @@ -300,19 +331,7 @@ parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) if (recurse->parent == NULL) { recurse->parent = new_menuitem(widget); - - ParserData *pdata = (ParserData *)g_object_get_data(G_OBJECT(recurse->parent), PARSER_DATA); - - pdata->shell = widget; - g_signal_connect (G_OBJECT (widget), - "child-added", - G_CALLBACK (child_added_cb), - recurse->parent); - g_signal_connect (G_OBJECT (widget), - "child-removed", - G_CALLBACK (child_removed_cb), - recurse->parent); - g_object_add_weak_pointer(G_OBJECT (widget), (gpointer*)&pdata->shell); + watch_submenu(recurse->parent, widget); } gtk_container_foreach (GTK_CONTAINER (widget), @@ -561,16 +580,7 @@ construct_dbusmenu_for_widget (GtkWidget * widget) GtkWidget *submenu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(widget)); if (submenu) { - pdata->shell = submenu; - g_signal_connect (G_OBJECT (submenu), - "child-added", - G_CALLBACK (child_added_cb), - mi); - g_signal_connect (G_OBJECT (submenu), - "child-removed", - G_CALLBACK (child_removed_cb), - mi); - g_object_add_weak_pointer(G_OBJECT(submenu), (gpointer*)&pdata->shell); + watch_submenu(mi, submenu); } if (!g_object_get_data (G_OBJECT (widget), "gtk-empty-menu-item") && !GTK_IS_TEAROFF_MENU_ITEM (widget)) @@ -1077,6 +1087,7 @@ widget_notify_cb (GtkWidget *widget, if (item != NULL) { GtkWidget * menu = GTK_WIDGET (g_value_get_object (&prop_value)); parse_menu_structure_helper(menu, &recurse); + watch_submenu(item, menu); } else { /* Note: it would be really odd that we wouldn't have a cached item, but we should handle that appropriately. */ |