diff options
author | Ted Gould <ted@gould.cx> | 2011-04-15 14:38:28 -0500 |
---|---|---|
committer | Ted Gould <ted@gould.cx> | 2011-04-15 14:38:28 -0500 |
commit | d6e3ac7ddd67f862db0fc7b8cf71d015326b1eac (patch) | |
tree | 54ed323791f6c1f6ca8dff58144ac51a1e7a086b /libdbusmenu-gtk/parser.c | |
parent | 172d807186f6ca422105018d55d25710040bc8f4 (diff) | |
parent | c6f266a166a1ab7bf312ccfd9aa56d23fe85ae76 (diff) | |
download | libdbusmenu-d6e3ac7ddd67f862db0fc7b8cf71d015326b1eac.tar.gz libdbusmenu-d6e3ac7ddd67f862db0fc7b8cf71d015326b1eac.tar.bz2 libdbusmenu-d6e3ac7ddd67f862db0fc7b8cf71d015326b1eac.zip |
Activating new entries the same as originally parsed ones
Diffstat (limited to 'libdbusmenu-gtk/parser.c')
-rw-r--r-- | libdbusmenu-gtk/parser.c | 58 |
1 files changed, 34 insertions, 24 deletions
diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 2342b37..4708a64 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -288,6 +288,33 @@ watch_submenu(DbusmenuMenuitem * mi, GtkWidget * menu) } static void +activate_toplevel_item (GtkWidget * item) +{ + /* 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(item)) { + return; + } + + /* 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(item)) == NULL) { + return; + } + + GtkWidget * shell = gtk_widget_get_parent (item); + if (!GTK_IS_MENU_BAR (shell)) { + return; + } + + gtk_menu_shell_activate_item (GTK_MENU_SHELL (shell), + item, + TRUE); +} + +static void parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) { /* If this is a shell, then let's handle the items in it. */ @@ -303,30 +330,9 @@ parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) * Note that this will not force menuitems in submenus to be updated as well. */ if (recurse->parent == NULL && GTK_IS_MENU_BAR(widget)) { - GList *children = gtk_container_get_children (GTK_CONTAINER (widget)); - 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); - } - - g_list_free (children); + gtk_container_foreach (GTK_CONTAINER (widget), + (GtkCallback)activate_toplevel_item, + NULL); } if (recurse->parent == NULL) { @@ -1117,6 +1123,10 @@ child_added_cb (GtkContainer *menu, GtkWidget *widget, gpointer data) recurse.toplevel = gtk_widget_get_toplevel(GTK_WIDGET(menu)); recurse.parent = menuitem; + if (GTK_IS_MENU_BAR(menu)) { + activate_toplevel_item (widget); + } + parse_menu_structure_helper(widget, &recurse); } |