From 7793f21d2ac3f9e796475619e4876d72cea6d99f Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Mon, 13 May 2013 15:52:21 -0400 Subject: [PATCH] gtkmenutrackeritem: Simplify the submenu opening API Instead of making clients inspect the submenu action and decide what to do based upon that, always request the submenu open and let the tracker decide what to do. --- gtk/gtkmenutrackeritem.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/gtk/gtkmenutrackeritem.c b/gtk/gtkmenutrackeritem.c index 1755f6ed2f..2d712a1c1b 100644 --- a/gtk/gtkmenutrackeritem.c +++ b/gtk/gtkmenutrackeritem.c @@ -585,7 +585,6 @@ gtk_menu_tracker_item_get_submenu_shown (GtkMenuTrackerItem *self) return self->submenu_shown; } -/* only called from the opener, internally */ static void gtk_menu_tracker_item_set_submenu_shown (GtkMenuTrackerItem *self, gboolean submenu_shown) @@ -762,22 +761,28 @@ gtk_menu_tracker_item_request_submenu_shown (GtkMenuTrackerItem *self, gboolean shown) { const gchar *submenu_action; - gboolean okay; + gboolean has_submenu_action; if (shown == self->submenu_requested) return; - /* Should not be getting called unless we have submenu-action. - */ - okay = g_menu_item_get_attribute (self->item, "submenu-action", "&s", &submenu_action); - g_assert (okay); + has_submenu_action = g_menu_item_get_attribute (self->item, "submenu-action", "&s", &submenu_action); self->submenu_requested = shown; - if (shown) - g_object_set_data_full (G_OBJECT (self), "submenu-opener", - gtk_menu_tracker_opener_new (self, submenu_action), - gtk_menu_tracker_opener_free); + /* If we have a submenu action, start a submenu opener and wait + * for the reply from the client. Otherwise, simply open the + * submenu immediately. + */ + if (has_submenu_action) + { + if (shown) + g_object_set_data_full (G_OBJECT (self), "submenu-opener", + gtk_menu_tracker_opener_new (self, submenu_action), + gtk_menu_tracker_opener_free); + else + g_object_set_data (G_OBJECT (self), "submenu-opener", NULL); + } else - g_object_set_data (G_OBJECT (self), "submenu-opener", NULL); + gtk_menu_tracker_item_set_submenu_shown (self, shown); }