After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 682630 - GMenuModel attribute for an action to toggle on submenu open/close
GMenuModel attribute for an action to toggle on submenu open/close
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Class: GtkApplication
unspecified
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2012-08-24 18:15 UTC by Allison Karlitskaya (desrt)
Modified: 2012-09-17 16:34 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
GtkModelMenuItem: first pass at submenu actions (7.36 KB, patch)
2012-08-24 18:15 UTC, Allison Karlitskaya (desrt)
reviewed Details | Review

Description Allison Karlitskaya (desrt) 2012-08-24 18:15:26 UTC
See patch.
Comment 1 Allison Karlitskaya (desrt) 2012-08-24 18:15:28 UTC
Created attachment 222358 [details] [review]
GtkModelMenuItem: first pass at submenu actions

Add support for a stateful action associated with a submenu.  The action
state is set to TRUE when the menu is shown and FALSE when it is
unshown.

This is useful to avoid unnecessary processing for menus that have
frequently-changing content.

A possible future feature is to add support for asynchronously filling
the initial state of the menu by waiting until the action actually emits
its state-change signal to TRUE before showing the menu.

A silly example has been added to Bloatpad to demonstrate the new
feature.
Comment 2 Matthias Clasen 2012-08-24 23:36:28 UTC
Would be nice to have an g_menu_item_set () here, instead of recreating the entire submenu
Comment 3 Allison Karlitskaya (desrt) 2012-08-25 06:14:04 UTC
We do have g_menu_item_set_attribute(), but that only modifies a GMenuItem.

Once the item is in a GMenuModel, it's immutable...
Comment 4 Lars Karlitski 2012-08-25 10:32:52 UTC
Review of attachment 222358 [details] [review]:

Looks good.

Should we check whether an action with the right type exists before calling g_action_group_change_action_state?  GSimpleActionGroup's implementation of change_action_state ignores unknown actions, but the interface documentation says "the action must be stateful and must be of the correct type".

::: gtk/gtkmodelmenuitem.c
@@ +153,3 @@
         gtk_actionable_set_action_target_value (GTK_ACTIONABLE (item), value);
 
+      else if (g_str_equal (key, "submenu-action") && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))

Is there a reason you put this here instead of into the "if ((submenu = ..." block above, where the submenu is actually created?
Comment 5 Allison Karlitskaya (desrt) 2012-08-27 12:44:03 UTC
Mostly because this is the point at which the attributes are being iterated...

I guess I could just do a one-off above, though.  We certainly do it for a few other items...
Comment 6 Matthias Clasen 2012-09-12 03:33:56 UTC
Review of attachment 222358 [details] [review]:

::: examples/bloatpad.c
@@ +258,3 @@
+  g_menu_append (bloatpad->time, time, NULL);
+  g_date_time_unref (now);
+  g_free (time);

Still think it is a little sad that we recreate the entire menu every second, when we really just want to update the label. Price to pay for immutability, I guess...
Comment 7 Allison Karlitskaya (desrt) 2012-09-13 19:03:11 UTC
(In reply to comment #6)
> Still think it is a little sad that we recreate the entire menu every second,
> when we really just want to update the label. Price to pay for immutability, I
> guess...

The sadness here is only how contrived the example is.  Where else do you know that we actually want to change the entire text of a menuitem once per second?