mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-16 13:40:31 +00:00
3f8c235593
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).
92 lines
5.6 KiB
C
92 lines
5.6 KiB
C
/*
|
|
* Copyright © 2011 Canonical Limited
|
|
*
|
|
* This library is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Lesser General Public License as
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
* licence or (at your option) any later version.
|
|
*
|
|
* This library is distributed in the hope that it will be useful, but
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
*
|
|
* Authors: Ryan Lortie <desrt@desrt.ca>
|
|
*/
|
|
|
|
#ifndef __GTK_ACTION_OBSERVER_H__
|
|
#define __GTK_ACTION_OBSERVER_H__
|
|
|
|
#include <gio/gio.h>
|
|
|
|
G_BEGIN_DECLS
|
|
|
|
#define GTK_TYPE_ACTION_OBSERVER (gtk_action_observer_get_type ())
|
|
#define GTK_ACTION_OBSERVER(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), \
|
|
GTK_TYPE_ACTION_OBSERVER, GtkActionObserver))
|
|
#define GTK_IS_ACTION_OBSERVER(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), \
|
|
GTK_TYPE_ACTION_OBSERVER))
|
|
#define GTK_ACTION_OBSERVER_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), \
|
|
GTK_TYPE_ACTION_OBSERVER, GtkActionObserverInterface))
|
|
|
|
typedef struct _GtkActionObserverInterface GtkActionObserverInterface;
|
|
typedef struct _GtkActionObservable GtkActionObservable;
|
|
typedef struct _GtkActionObserver GtkActionObserver;
|
|
|
|
struct _GtkActionObserverInterface
|
|
{
|
|
GTypeInterface g_iface;
|
|
|
|
void (* action_added) (GtkActionObserver *observer,
|
|
GtkActionObservable *observable,
|
|
const gchar *action_name,
|
|
const GVariantType *parameter_type,
|
|
gboolean enabled,
|
|
GVariant *state);
|
|
void (* action_enabled_changed) (GtkActionObserver *observer,
|
|
GtkActionObservable *observable,
|
|
const gchar *action_name,
|
|
gboolean enabled);
|
|
void (* action_state_changed) (GtkActionObserver *observer,
|
|
GtkActionObservable *observable,
|
|
const gchar *action_name,
|
|
GVariant *state);
|
|
void (* action_removed) (GtkActionObserver *observer,
|
|
GtkActionObservable *observable,
|
|
const gchar *action_name);
|
|
void (* primary_accel_changed) (GtkActionObserver *observer,
|
|
GtkActionObservable *observable,
|
|
const gchar *action_name,
|
|
const gchar *action_and_target);
|
|
};
|
|
|
|
GType gtk_action_observer_get_type (void);
|
|
void gtk_action_observer_action_added (GtkActionObserver *observer,
|
|
GtkActionObservable *observable,
|
|
const gchar *action_name,
|
|
const GVariantType *parameter_type,
|
|
gboolean enabled,
|
|
GVariant *state);
|
|
void gtk_action_observer_action_enabled_changed (GtkActionObserver *observer,
|
|
GtkActionObservable *observable,
|
|
const gchar *action_name,
|
|
gboolean enabled);
|
|
void gtk_action_observer_action_state_changed (GtkActionObserver *observer,
|
|
GtkActionObservable *observable,
|
|
const gchar *action_name,
|
|
GVariant *state);
|
|
void gtk_action_observer_action_removed (GtkActionObserver *observer,
|
|
GtkActionObservable *observable,
|
|
const gchar *action_name);
|
|
void gtk_action_observer_primary_accel_changed (GtkActionObserver *observer,
|
|
GtkActionObservable *observable,
|
|
const gchar *action_name,
|
|
const gchar *action_and_target);
|
|
|
|
G_END_DECLS
|
|
|
|
#endif /* __GTK_ACTION_OBSERVER_H__ */
|