diff options
author | Ryan Lortie <desrt@desrt.ca> | 2013-07-09 22:37:17 -0400 |
---|---|---|
committer | Ryan Lortie <desrt@desrt.ca> | 2013-10-15 09:24:11 -0400 |
commit | 3f8c235593ec093d84545462d1d36797bcefdc16 (patch) | |
tree | a65f155b3c8cf35d58ef7f5b14d015d6f8a632c0 /gtk/gtkactionobserver.c | |
parent | abcddd3ae08a6bfefec0d4298288adc8f672c924 (diff) | |
download | gtk+-3f8c235593ec093d84545462d1d36797bcefdc16.tar.gz |
GtkActionMuxer: store primary accels
Reuse the existing infrastructure in GtkActionMuxer for propagation of
accelerator information: in particular, what accel label ought to appear
on menu items for a particular action and target.
This is a good idea because we want accels to travel along with the
actions that they're tied to and reusing GtkActionMuxer will allow us to
do that without creating another hierarchy of a different class for the
sole purpose of filling in accel labels on menu items.
Doing it this ways also allows those who copy/paste GtkActionMuxer to
insert the accels for themselves.
Add a new method on the GtkActionObserver interface to report changes.
This patch introduces a new concept: "action and target" notation for
actions. This format looks like so:
"'target'|app.action"
or for non-targeted actions:
"|app.action"
and it is used over a number of possible alternative formats for some
good reasons:
- it's very easy to get a nul-terminated action name out of this format
when we need it, by using strrchr('|') + 1
- we can also get the target out of it using g_variant_parse() because
this function takes a pointer to a 'limit' character that is not
parsed past: we use the '|' for this
- it's extremely easy to hash on this format (just use a normal string
hash) vs. attempting to hash on a string plus a GVariant
A close contender was to use detailed action strings here, but these are
not used for two reasons:
- it's not possible to easily get the action name or target out of the
strings without more work than the "action and target" format
requires
- we still intend to use detailed action strings on API (since they are
a lot nicer to look at) but detailed action strings can be given in
non-canonical forms (eg: 'foo::bar' and 'foo("bar")' are equivalent)
so we'd have to go through a normalisation step anyway. Since we're
doing that already, we may as well convert to a more convenient
internal format.
This new "action and target" format is going to start appearing in a lot
more places as action descriptions are introduced.
I suspect that nobody is using '|' in their action names, but in case I
am proven wrong, we can always switch to using something more exotic as
a separator character (such as '\x01' or '\xff' or the like).
Diffstat (limited to 'gtk/gtkactionobserver.c')
-rw-r--r-- | gtk/gtkactionobserver.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/gtk/gtkactionobserver.c b/gtk/gtkactionobserver.c index cf70b20a3e..3287106b74 100644 --- a/gtk/gtkactionobserver.c +++ b/gtk/gtkactionobserver.c @@ -157,3 +157,33 @@ gtk_action_observer_action_removed (GtkActionObserver *observer, GTK_ACTION_OBSERVER_GET_IFACE (observer) ->action_removed (observer, observable, action_name); } + +/** + * gtk_action_observer_primary_accel_changed: + * @observer: a #GtkActionObserver + * @observable: the source of the event + * @action_name: the name of the action + * @action_and_target: detailed action of the changed accel, in "action and target" format + * + * This function is called when an action that the observer is + * registered to receive events for has one of its accelerators changed. + * + * Accelerator changes are reported for all targets associated with the + * action. The @action_and_target string should be used to check if the + * reported target is the one that the observer is interested in. + */ +void +gtk_action_observer_primary_accel_changed (GtkActionObserver *observer, + GtkActionObservable *observable, + const gchar *action_name, + const gchar *action_and_target) +{ + GtkActionObserverInterface *iface; + + g_return_if_fail (GTK_IS_ACTION_OBSERVER (observer)); + + iface = GTK_ACTION_OBSERVER_GET_IFACE (observer); + + if (iface->primary_accel_changed) + iface->primary_accel_changed (observer, observable, action_name, action_and_target); +} |