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 705133 - GAction toggle (bool) menu items do not toggle automatically
GAction toggle (bool) menu items do not toggle automatically
Status: RESOLVED NOTABUG
Product: gtk+
Classification: Platform
Component: Widget: GtkMenu
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2013-07-30 11:00 UTC by Murray Cumming
Modified: 2013-07-30 14:02 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
test_gmenu_toggle.c (3.74 KB, text/plain)
2013-07-30 11:00 UTC, Murray Cumming
Details

Description Murray Cumming 2013-07-30 11:00:31 UTC
Created attachment 250446 [details]
test_gmenu_toggle.c

Although the GAction wiki page (I'd prefer if that was in the API docs)
  https://wiki.gnome.org/HowDoI/GAction
says 
  "If your action is stateful and you do not connect a handler for the change-state signal then the default is that all state change requests will always change the state to the requested value."
that doesn't seem to be the case, or at least the UI is not updated.

This example code creates a couple of normal actions and one bool-state (toggle) action. Though I can see the tick mark at the left of the toggle menu item when changing the initial state from FALSE to TRUE, it does not change when I select the menu item in the UI.
Comment 1 Matthias Clasen 2013-07-30 11:23:56 UTC
 "If your action is stateful and you do not connect a handler for the
change-state signal then the default is that all state change requests will
always change the state to the requested value."

What this means is that you don't have to write your own state_changed handler to make "activate (boolean-action, TRUE)" and "activate (boolean-action, FALSE)"
do what what you expect (change the state to the given parameter).

What that HowDoI page means by 'toggle action' is an action which has boolean state, where each activation toggles the state. Both GSettingsAction and GPropertyAction implement toggle-on-activate if their state type is boolean. GSimpleAction doesn't, so you have to do that yourself.
Comment 2 Murray Cumming 2013-07-30 11:34:10 UTC
Ah, thanks. Maybe that sentence could be made clearer to say that, and it could state that GSimpleAction doesn't automatically change the state when activated.

This also feels like another reason to have a real G(Simple)ToggleAction that makes this all simpler. Right now it feels like using something overly generic.
Comment 3 Murray Cumming 2013-07-30 11:39:39 UTC
Also, if you are saying that the boolean state will be passed as the parameter to the activate signal, that's something else that I don't see mentioned in the documentation, thought the bloatpad.c example assumes it:
"
static void
activate_radio (GSimpleAction *action,
                GVariant      *parameter,
                gpointer       user_data)
{
  g_action_change_state (G_ACTION (action), parameter);
}
"

That seems to be contradicting by this sentence from
  https://wiki.gnome.org/HowDoI/GAction#Action_state_and_parameters
"By convention, toggle actions have no parameter type for activation: activating the action always toggles the state."
which also suggest some default behaviour that isn't there.
Comment 4 Matthias Clasen 2013-07-30 11:47:37 UTC
Sorry, I was unclear.

These are actually two separate things: the state type (the type of the actions state) is not necessarily the same as the parameter type (the type of the parameter that activate requires).

For 'regular' boolean actions, you'd expect state type == parameter type == boolean
For toggle actions, you'd expect state type == boolean, parameter type = none
Comment 5 Murray Cumming 2013-07-30 13:54:42 UTC
By 'regular' boolean actions, I guess you mean, for instance, two mutually-exclusive radio items, right?
Comment 6 Matthias Clasen 2013-07-30 14:00:30 UTC
Just any boolean where you don't want toggling but instead want to explicitly set the value to TRUE or FALSE. 

Radio actions are usually modeled a little different with GAction. You have a single action, with a state that can have as many values as you have radio options - one value for each option. If you click on a radio item backed by such an action, it will set the state of the action to 'its' value. The radio items know that they need to appear unselected when the actions state is different from their value, so setting the state to a new value automatically makes the previously selected item to become unselected.
Comment 7 Matthias Clasen 2013-07-30 14:02:04 UTC
But I guess you are right - if your radio group has just two members, you can use a boolean state and have the one item use TRUE, and the other use FALSE as its value.