[gtk+/wip/gmenu: 4/87] First attempt at handling dynamic changes
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/gmenu: 4/87] First attempt at handling dynamic changes
- Date: Sat, 3 Dec 2011 23:48:29 +0000 (UTC)
commit f093f694a23c47c9ce62a6a6d40949cb26f4a4ff
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Nov 1 01:27:49 2011 -0400
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.
tests/testgmenu.c | 44 +++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 43 insertions(+), 1 deletions(-)
---
diff --git a/tests/testgmenu.c b/tests/testgmenu.c
index 9dd3ca4..566ae7c 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;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]