diff options
author | Matthias Clasen <mclasen@redhat.com> | 2011-11-01 01:27:49 -0400 |
---|---|---|
committer | Ryan Lortie <desrt@desrt.ca> | 2011-12-19 12:45:50 -0500 |
commit | 519c75a606f775e1bac65a2f7ff591d156f1d844 (patch) | |
tree | 353dc5c57bad2d09219d4688b311fd214967b22b /tests/testgmenu.c | |
parent | c62ed7e3a32b025c8ab96812df64f106c2a05161 (diff) | |
download | gtk+-519c75a606f775e1bac65a2f7ff591d156f1d844.tar.gz |
First attempt at handling dynamic changes
We need to connect to items-changed on _every_ menu
model, which is somewhat icky. For some reason, this
works fine with a local model, but not with D-Bus in
between. Debugging needed.
Diffstat (limited to 'tests/testgmenu.c')
-rw-r--r-- | tests/testgmenu.c | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/tests/testgmenu.c b/tests/testgmenu.c index 9dd3ca463d..566ae7ce94 100644 --- a/tests/testgmenu.c +++ b/tests/testgmenu.c @@ -733,9 +733,49 @@ items_changed (GMenuModel *model, gint added, GtkButton *button) { + g_print ("Received GMenuModel::items-changed\n"); g_object_set_data (G_OBJECT (button), "menu", NULL); } +static void +action_added (GActionGroup *group, + const gchar *name, + gpointer data) +{ + g_print ("Received GActionGroup::action-added\n"); +} + +static void +action_removed (GActionGroup *group, + const gchar *name, + gpointer data) +{ + g_print ("Received GActionGroup::action-removed\n"); +} + +static void +recursively_connect_to_items_changed (GMenuModel *model, + GCallback callback, + gpointer data) +{ + gint i; + GMenuModel *m; + GMenuLinkIter *iter; + + g_signal_connect (model, "items-changed", callback, data); + for (i = 0; i < g_menu_model_get_n_items (model); i++) + { + iter = g_menu_model_iterate_item_links (model, i); + while (g_menu_link_iter_next (iter)) + { + m = g_menu_link_iter_get_value (iter); + recursively_connect_to_items_changed (m, callback, data); + g_object_unref (m); + } + g_object_unref (iter); + } +} + static GtkWidget * create_menu_button (GMenuModel *model, GActionGroup *group) { @@ -746,7 +786,9 @@ create_menu_button (GMenuModel *model, GActionGroup *group) g_object_set_data (G_OBJECT (button), "group", group); g_signal_connect (button, "clicked", G_CALLBACK (button_clicked), NULL); - g_signal_connect (model, "items-changed", G_CALLBACK (items_changed), button); + recursively_connect_to_items_changed (model, G_CALLBACK (items_changed), button); + g_signal_connect (group, "action-added", G_CALLBACK (action_added), NULL); + g_signal_connect (group, "action-removed", G_CALLBACK (action_removed), NULL); return button; } |