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 722503 - GSimpleAction: add default activate handler
GSimpleAction: add default activate handler
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gapplication
unspecified
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2014-01-18 18:30 UTC by Allison Karlitskaya (desrt)
Modified: 2014-01-21 20:15 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
GSimpleAction: add default activate handler (3.16 KB, patch)
2014-01-18 18:30 UTC, Allison Karlitskaya (desrt)
committed Details | Review
test default GSimpleAction activation (2.22 KB, patch)
2014-01-18 19:30 UTC, Allison Karlitskaya (desrt)
committed Details | Review

Description Allison Karlitskaya (desrt) 2014-01-18 18:30:40 UTC
If the action is stateful and the user doesn't have their own activate handler
then do some reasonable things for ourselves.

After a lot of experience using stateful GSimpleAction it turns out that
people almost always end up using it in the same ways:

A boolean-typed stateful action with no parameter is most likely going
to want to be toggled.  Any other type of action that has the parameter
type equal to the state type probably intends for activation to
represent a request to change the state.

This patch implements those two cases.  This will let people stop
writing their own trivial handlers over and over.
Comment 1 Allison Karlitskaya (desrt) 2014-01-18 18:30:42 UTC
Created attachment 266618 [details] [review]
GSimpleAction: add default activate handler
Comment 2 Matthias Clasen 2014-01-18 19:03:22 UTC
Review of attachment 266618 [details] [review]:

Looks fine to me, given that we already use g_signal_has_handler_pending for change-state. Would be great to a) update some of our examples to use this, and b) add tests that trigger the default handling

::: gio/gsimpleaction.c
@@ +367,3 @@
+   * Since GLib 2.40, if no handler is connected to this signal then the
+   * default behaviour for boolean-stated actions with a %NULL parameter
+   * type is to toggle them via the change-action signal.  For stateful

#GSimpleAction::change-state,you mean ?

@@ +369,3 @@
+   * type is to toggle them via the change-action signal.  For stateful
+   * actions where the state type is equal to the parameter type, the
+   * default is to forward them directly to change-action.  This should

And here too
Comment 3 Allison Karlitskaya (desrt) 2014-01-18 19:20:36 UTC
Comment on attachment 266618 [details] [review]
GSimpleAction: add default activate handler

Attachment 266618 [details] pushed as 1ec7114 - GSimpleAction: add default activate handler
Comment 4 Allison Karlitskaya (desrt) 2014-01-18 19:30:03 UTC
Created attachment 266626 [details] [review]
test default GSimpleAction activation

Test the default handling of the "activate" signal on GSimpleAction.
Comment 5 Matthias Clasen 2014-01-19 03:55:13 UTC
Review of attachment 266626 [details] [review]:

looks good
Comment 6 Allison Karlitskaya (desrt) 2014-01-21 20:15:54 UTC
Attachment 266626 [details] pushed as 829464a - test default GSimpleAction activation