GNOME Bugzilla – Bug 705133
GAction toggle (bool) menu items do not toggle automatically
Last modified: 2013-07-30 14:02:04 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.
"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.
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.
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.
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
By 'regular' boolean actions, I guess you mean, for instance, two mutually-exclusive radio items, right?
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.
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.