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 704392 - Improve GtkAction deprecation notices
Improve GtkAction deprecation notices
Status: RESOLVED OBSOLETE
Product: gtk+
Classification: Platform
Component: Documentation
3.9.x
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2013-07-17 13:03 UTC by David King
Modified: 2018-04-15 00:28 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
improve GtkAction deprecation notices (18.78 KB, patch)
2013-07-17 13:05 UTC, David King
committed Details | Review
test_gmenu_radio_strings.c (4.01 KB, text/x-csrc)
2013-07-30 20:31 UTC, Murray Cumming
  Details
test_gmenu_radio_int32.c (3.98 KB, text/x-csrc)
2013-07-30 20:32 UTC, Murray Cumming
  Details

Description David King 2013-07-17 13:03:49 UTC
GtkAction was deprecated recently, but the deprecation notices could be a bit more helpful, pointing out some of the replacements in GAction, GMenuModel and so on.
Comment 1 David King 2013-07-17 13:05:23 UTC
Created attachment 249400 [details] [review]
improve GtkAction deprecation notices

First try at improving the deprecation notices for GtkAction. There is plenty to disagree over, so comments welcome.
Comment 2 Matthias Clasen 2013-07-17 15:11:24 UTC
I think we probably want to add a section to the migration guide about this, actually.

But sure, this looks like an improvement
Comment 3 William Jon McCann 2013-07-17 16:15:44 UTC
Looks fine to me.
Comment 4 Murray Cumming 2013-07-25 09:31:03 UTC
This is a big improvement. Thanks, David.

Can we add anything to GtkToggleAction to suggest how to achieve the same thing with GAction? It seems to involve GAction::state and the state-changed signal. It seems to need rather lengthy code for a simple boolean check item, such as:

GSimpleAction *action =
  g_simple_action_new_stateful("somename", G_VARIANT_TYPE_BOOLEAN, g_variant_new_boolean (TRUE));

and later:

g_action_change_state (action, g_variant_new_boolean (FALSE));

and

GVariant *state = g_action_get_state (action);
gboolean active = g_variant_get_boolean (state);
g_variant_unref (state);


It would be nice to have convenience API for that if none exists already.
Comment 5 Murray Cumming 2013-07-25 19:28:28 UTC
It might also be nice to state, as I think is true, that the activate signal will be emitted whenever the state changes, so for a simple toggle menu item it would be enough to just handle the "activate" signal and ignore the "change-state" signal, assuming that you don't want to prevent toggling in some cases.
Comment 6 Murray Cumming 2013-07-27 21:03:11 UTC
And I have no clue how to implement radio menu items. This suggests that it should be implemented by one action having n possible states:
https://wiki.gnome.org/HowDoI/GAction
But I don't see how to specify the human-readable text to be used for those states.
Comment 7 Matthias Clasen 2013-07-28 03:44:35 UTC
(In reply to comment #6)
> And I have no clue how to implement radio menu items. This suggests that it
> should be implemented by one action having n possible states:
> https://wiki.gnome.org/HowDoI/GAction
> But I don't see how to specify the human-readable text to be used for those
> states.

You use one action with multiple states, indeed. And you specify the human-readable text on the n menuitems, one for each state:

static GActionEntry win_entries[] = {
  { "justify", activate_radio, "s", "'left'", change_justify_state }
}

<menu>
  <section>
    <item>
      <attribute name='label'>Justify left</attribute>
      <attribute name='action'>win.justify</attribute>
      <attribute name='target'>left</attribute>
    </item>
    <item>
      <attribute name='label'>Justify right</attribute>
      <attribute name='action'>win.justify</attribute>
      <attribute name='target'>right</attribute>
    </item>
...
Comment 8 Murray Cumming 2013-07-28 18:27:36 UTC
Thanks. Can I use anything other than a string for the target/state? For instance, it would be nice to use an enum value directly rather than creating a string representation of it just for this.
Comment 9 Matthias Clasen 2013-07-28 20:14:35 UTC
it is a serialized variant, the type of which is specified by the state-type property of the action.
Comment 10 Murray Cumming 2013-07-29 07:14:47 UTC
Yes, thanks, but, the target in the GtkBuilder XML seems to only be able to represent a string. If we are meant to enter a GVariant serialization string there, we'll need more hints about what that might look like. 

By the way, the documentation uses the British/Canadian serialisation spelling of serialization.
Comment 11 Murray Cumming 2013-07-29 20:24:23 UTC
(In reply to comment #10)
> Yes, thanks, but, the target in the GtkBuilder XML seems to only be able to
> represent a string.
> If we are meant to enter a GVariant serialization string
> there, we'll need more hints about what that might look like. 

OK, now I see that the format is quite simple, so a simple decimal number will be interpreted as that:
https://developer.gnome.org/glib/unstable/gvariant-text.html

This link is also useful:
https://developer.gnome.org/glib/unstable/gvariant-format-strings.html


I've also learned that radio items have a parameter and state that are equal "by convention", though I don't really know if that's a convention that the app must maintain, or one that glib or gtk+ will maintain for me.
https://wiki.gnome.org/HowDoI/GAction#Action_state_and_parameters


In general, this use of both the parameter and the state confuses the API for radio items, with the "target value" concept introducing yet a third thing:
- My GtkBuilder <menu> XML specifies a _target_ value that is the _parameter_ value that my callback will receive
- I g_action_activate() the action with the _parameter_ value (though maybe g_action_change_state() with the state would work too.)
- and I (think I) have to get the action's _state_ to discover which value is currently selected.


I know this isn't the best place to gripe about this, sorry, but I feel like I'm making progress at least.
Comment 12 Murray Cumming 2013-07-30 20:31:58 UTC
Created attachment 250505 [details]
test_gmenu_radio_strings.c

This works.
Comment 13 Murray Cumming 2013-07-30 20:32:39 UTC
Created attachment 250506 [details]
test_gmenu_radio_int32.c

This doesn't work.
Comment 14 Allison Karlitskaya (desrt) 2013-08-05 08:50:16 UTC
If you want to use non-string target values you need to use the type= attribute with a GVariant type string, like so:


<attribute name='target' type='i'>100</attribute>


Admittedly, this is utterly undocumented.... anywhere, as far as I know.  We should really fix that.
Comment 15 Murray Cumming 2013-08-08 08:00:27 UTC
(In reply to comment #4)
> It would be nice to have convenience API for that if none exists already.

I've filed that suggestion as bug #705655 .
Comment 16 Murray Cumming 2013-08-08 08:04:03 UTC
GtkRecentAction also need improved deprecation documentation comments, though the main problem is that there is no replacement yet. I've filed that as bug #705656.
Comment 17 Murray Cumming 2013-09-03 21:02:55 UTC
(In reply to comment #16)
> GtkRecentAction also need improved deprecation documentation comments, though
> the main problem is that there is no replacement yet. I've filed that as bug
> #705656.

Sorry, I mean bug #707422 .
Comment 18 Matthias Clasen 2018-02-10 05:22:32 UTC
We're moving to gitlab! As part of this move, we are moving bugs to NEEDINFO if they haven't seen activity in more than a year. If this issue is still important to you and still relevant with GTK+ 3.22 or master, please reopen it and we will migrate it to gitlab.
Comment 19 Matthias Clasen 2018-04-15 00:28:33 UTC
As announced a while ago, we are migrating to gitlab, and bugs that haven't seen activity in the last year or so will be not be migrated, but closed out in bugzilla.

If this bug is still relevant to you, you can open a new issue describing the symptoms and how to reproduce it with gtk 3.22.x or master in gitlab:

https://gitlab.gnome.org/GNOME/gtk/issues/new