2011-11-30 14:33:03 +00:00
|
|
|
/*
|
|
|
|
* 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
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2011-11-30 14:33:03 +00:00
|
|
|
*
|
|
|
|
* Author: Ryan Lortie <desrt@desrt.ca>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2013-05-09 18:15:51 +00:00
|
|
|
#include "gtkactionmuxer.h"
|
2011-11-30 14:33:03 +00:00
|
|
|
|
2013-05-09 18:15:51 +00:00
|
|
|
#include "gtkactionobservable.h"
|
|
|
|
#include "gtkactionobserver.h"
|
2011-11-30 14:33:03 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2013-05-09 19:28:57 +00:00
|
|
|
/**
|
2013-05-09 18:15:51 +00:00
|
|
|
* SECTION:gtkactionmuxer
|
2011-11-30 14:33:03 +00:00
|
|
|
* @short_description: Aggregate and monitor several action groups
|
|
|
|
*
|
2013-05-09 18:15:51 +00:00
|
|
|
* #GtkActionMuxer is a #GActionGroup and #GtkActionObservable that is
|
2011-11-30 14:33:03 +00:00
|
|
|
* capable of containing other #GActionGroup instances.
|
|
|
|
*
|
2011-12-16 03:20:42 +00:00
|
|
|
* The typical use is aggregating all of the actions applicable to a
|
2011-11-30 14:33:03 +00:00
|
|
|
* particular context into a single action group, with namespacing.
|
|
|
|
*
|
|
|
|
* Consider the case of two action groups -- one containing actions
|
|
|
|
* applicable to an entire application (such as 'quit') and one
|
|
|
|
* containing actions applicable to a particular window in the
|
|
|
|
* application (such as 'fullscreen').
|
|
|
|
*
|
|
|
|
* In this case, each of these action groups could be added to a
|
2013-05-09 18:15:51 +00:00
|
|
|
* #GtkActionMuxer with the prefixes "app" and "win", respectively. This
|
2011-11-30 14:33:03 +00:00
|
|
|
* would expose the actions as "app.quit" and "win.fullscreen" on the
|
2013-05-09 18:15:51 +00:00
|
|
|
* #GActionGroup interface presented by the #GtkActionMuxer.
|
2011-11-30 14:33:03 +00:00
|
|
|
*
|
2013-05-09 18:15:51 +00:00
|
|
|
* Activations and state change requests on the #GtkActionMuxer are wired
|
2011-11-30 14:33:03 +00:00
|
|
|
* through to the underlying action group in the expected way.
|
|
|
|
*
|
|
|
|
* This class is typically only used at the site of "consumption" of
|
|
|
|
* actions (eg: when displaying a menu that contains many actions on
|
|
|
|
* different objects).
|
2011-12-01 11:30:10 +00:00
|
|
|
*/
|
2011-11-30 14:33:03 +00:00
|
|
|
|
2013-05-09 18:15:51 +00:00
|
|
|
static void gtk_action_muxer_group_iface_init (GActionGroupInterface *iface);
|
|
|
|
static void gtk_action_muxer_observable_iface_init (GtkActionObservableInterface *iface);
|
2011-11-30 14:33:03 +00:00
|
|
|
|
2013-05-09 18:15:51 +00:00
|
|
|
typedef GObjectClass GtkActionMuxerClass;
|
2011-11-30 14:33:03 +00:00
|
|
|
|
2013-05-09 18:15:51 +00:00
|
|
|
struct _GtkActionMuxer
|
2011-11-30 14:33:03 +00:00
|
|
|
{
|
|
|
|
GObject parent_instance;
|
|
|
|
|
2012-08-17 17:16:51 +00:00
|
|
|
GHashTable *observed_actions;
|
2011-11-30 14:33:03 +00:00
|
|
|
GHashTable *groups;
|
2013-07-10 02:37:17 +00:00
|
|
|
GHashTable *primary_accels;
|
2013-05-09 18:15:51 +00:00
|
|
|
GtkActionMuxer *parent;
|
2011-11-30 14:33:03 +00:00
|
|
|
};
|
|
|
|
|
2013-05-09 18:15:51 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkActionMuxer, gtk_action_muxer, G_TYPE_OBJECT,
|
|
|
|
G_IMPLEMENT_INTERFACE (G_TYPE_ACTION_GROUP, gtk_action_muxer_group_iface_init)
|
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTION_OBSERVABLE, gtk_action_muxer_observable_iface_init))
|
2011-11-30 14:33:03 +00:00
|
|
|
|
2012-08-17 17:16:51 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_PARENT,
|
|
|
|
NUM_PROPERTIES
|
|
|
|
};
|
|
|
|
|
|
|
|
static GParamSpec *properties[NUM_PROPERTIES];
|
|
|
|
|
2013-07-10 02:37:17 +00:00
|
|
|
guint accel_signal;
|
|
|
|
|
2011-11-30 14:33:03 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2013-05-09 18:15:51 +00:00
|
|
|
GtkActionMuxer *muxer;
|
2011-11-30 14:33:03 +00:00
|
|
|
GSList *watchers;
|
|
|
|
gchar *fullname;
|
|
|
|
} Action;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2013-05-09 18:15:51 +00:00
|
|
|
GtkActionMuxer *muxer;
|
2011-11-30 14:33:03 +00:00
|
|
|
GActionGroup *group;
|
|
|
|
gchar *prefix;
|
|
|
|
gulong handler_ids[4];
|
|
|
|
} Group;
|
|
|
|
|
2012-08-17 17:16:51 +00:00
|
|
|
static void
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_append_group_actions (gpointer key,
|
|
|
|
gpointer value,
|
|
|
|
gpointer user_data)
|
2012-08-17 17:16:51 +00:00
|
|
|
{
|
|
|
|
const gchar *prefix = key;
|
|
|
|
Group *group = value;
|
|
|
|
GArray *actions = user_data;
|
|
|
|
gchar **group_actions;
|
|
|
|
gchar **action;
|
|
|
|
|
|
|
|
group_actions = g_action_group_list_actions (group->group);
|
|
|
|
for (action = group_actions; *action; action++)
|
|
|
|
{
|
|
|
|
gchar *fullname;
|
|
|
|
|
|
|
|
fullname = g_strconcat (prefix, ".", *action, NULL);
|
|
|
|
g_array_append_val (actions, fullname);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_strfreev (group_actions);
|
|
|
|
}
|
|
|
|
|
2011-11-30 14:33:03 +00:00
|
|
|
static gchar **
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_list_actions (GActionGroup *action_group)
|
2011-11-30 14:33:03 +00:00
|
|
|
{
|
2013-05-09 18:15:51 +00:00
|
|
|
GtkActionMuxer *muxer = GTK_ACTION_MUXER (action_group);
|
2012-08-17 17:16:51 +00:00
|
|
|
GArray *actions;
|
2011-11-30 14:33:03 +00:00
|
|
|
|
2012-08-17 17:16:51 +00:00
|
|
|
actions = g_array_new (TRUE, FALSE, sizeof (gchar *));
|
2012-03-30 18:05:46 +00:00
|
|
|
|
2012-08-17 17:16:51 +00:00
|
|
|
for ( ; muxer != NULL; muxer = muxer->parent)
|
|
|
|
{
|
|
|
|
g_hash_table_foreach (muxer->groups,
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_append_group_actions,
|
2012-08-17 17:16:51 +00:00
|
|
|
actions);
|
|
|
|
}
|
2012-03-30 18:05:46 +00:00
|
|
|
|
2012-08-17 17:16:51 +00:00
|
|
|
return (gchar **) g_array_free (actions, FALSE);
|
2011-11-30 14:33:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static Group *
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_find_group (GtkActionMuxer *muxer,
|
|
|
|
const gchar *full_name,
|
|
|
|
const gchar **action_name)
|
2011-11-30 14:33:03 +00:00
|
|
|
{
|
|
|
|
const gchar *dot;
|
|
|
|
gchar *prefix;
|
|
|
|
Group *group;
|
|
|
|
|
2012-08-17 17:16:51 +00:00
|
|
|
dot = strchr (full_name, '.');
|
2011-11-30 14:33:03 +00:00
|
|
|
|
|
|
|
if (!dot)
|
|
|
|
return NULL;
|
|
|
|
|
2012-08-17 17:16:51 +00:00
|
|
|
prefix = g_strndup (full_name, dot - full_name);
|
2011-11-30 14:33:03 +00:00
|
|
|
group = g_hash_table_lookup (muxer->groups, prefix);
|
|
|
|
g_free (prefix);
|
|
|
|
|
2012-08-17 17:16:51 +00:00
|
|
|
if (action_name)
|
|
|
|
*action_name = dot + 1;
|
2011-11-30 14:33:03 +00:00
|
|
|
|
|
|
|
return group;
|
|
|
|
}
|
|
|
|
|
2012-08-17 17:16:51 +00:00
|
|
|
static void
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_action_enabled_changed (GtkActionMuxer *muxer,
|
|
|
|
const gchar *action_name,
|
|
|
|
gboolean enabled)
|
2011-11-30 14:33:03 +00:00
|
|
|
{
|
|
|
|
Action *action;
|
2012-08-17 17:16:51 +00:00
|
|
|
GSList *node;
|
2011-11-30 14:33:03 +00:00
|
|
|
|
2012-08-17 17:16:51 +00:00
|
|
|
action = g_hash_table_lookup (muxer->observed_actions, action_name);
|
|
|
|
for (node = action ? action->watchers : NULL; node; node = node->next)
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_observer_action_enabled_changed (node->data, GTK_ACTION_OBSERVABLE (muxer), action_name, enabled);
|
2012-08-17 17:16:51 +00:00
|
|
|
g_action_group_action_enabled_changed (G_ACTION_GROUP (muxer), action_name, enabled);
|
2011-11-30 14:33:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_group_action_enabled_changed (GActionGroup *action_group,
|
|
|
|
const gchar *action_name,
|
|
|
|
gboolean enabled,
|
|
|
|
gpointer user_data)
|
2011-11-30 14:33:03 +00:00
|
|
|
{
|
|
|
|
Group *group = user_data;
|
|
|
|
gchar *fullname;
|
|
|
|
|
2012-08-17 17:16:51 +00:00
|
|
|
fullname = g_strconcat (group->prefix, ".", action_name, NULL);
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_action_enabled_changed (group->muxer, fullname, enabled);
|
2012-08-17 17:16:51 +00:00
|
|
|
|
2011-11-30 14:33:03 +00:00
|
|
|
g_free (fullname);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_parent_action_enabled_changed (GActionGroup *action_group,
|
|
|
|
const gchar *action_name,
|
|
|
|
gboolean enabled,
|
|
|
|
gpointer user_data)
|
2012-08-17 17:16:51 +00:00
|
|
|
{
|
2013-05-09 18:15:51 +00:00
|
|
|
GtkActionMuxer *muxer = user_data;
|
2012-08-17 17:16:51 +00:00
|
|
|
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_action_enabled_changed (muxer, action_name, enabled);
|
2012-08-17 17:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_action_state_changed (GtkActionMuxer *muxer,
|
|
|
|
const gchar *action_name,
|
|
|
|
GVariant *state)
|
2011-11-30 14:33:03 +00:00
|
|
|
{
|
|
|
|
Action *action;
|
|
|
|
GSList *node;
|
|
|
|
|
2012-08-17 17:16:51 +00:00
|
|
|
action = g_hash_table_lookup (muxer->observed_actions, action_name);
|
2011-11-30 14:33:03 +00:00
|
|
|
for (node = action ? action->watchers : NULL; node; node = node->next)
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_observer_action_state_changed (node->data, GTK_ACTION_OBSERVABLE (muxer), action_name, state);
|
2012-08-17 17:16:51 +00:00
|
|
|
g_action_group_action_state_changed (G_ACTION_GROUP (muxer), action_name, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_group_action_state_changed (GActionGroup *action_group,
|
|
|
|
const gchar *action_name,
|
|
|
|
GVariant *state,
|
|
|
|
gpointer user_data)
|
2012-08-17 17:16:51 +00:00
|
|
|
{
|
|
|
|
Group *group = user_data;
|
|
|
|
gchar *fullname;
|
|
|
|
|
|
|
|
fullname = g_strconcat (group->prefix, ".", action_name, NULL);
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_action_state_changed (group->muxer, fullname, state);
|
2012-08-17 17:16:51 +00:00
|
|
|
|
2011-11-30 14:33:03 +00:00
|
|
|
g_free (fullname);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_parent_action_state_changed (GActionGroup *action_group,
|
|
|
|
const gchar *action_name,
|
|
|
|
GVariant *state,
|
|
|
|
gpointer user_data)
|
2012-08-17 17:16:51 +00:00
|
|
|
{
|
2013-05-09 18:15:51 +00:00
|
|
|
GtkActionMuxer *muxer = user_data;
|
2012-08-17 17:16:51 +00:00
|
|
|
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_action_state_changed (muxer, action_name, state);
|
2012-08-17 17:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_action_added (GtkActionMuxer *muxer,
|
|
|
|
const gchar *action_name,
|
|
|
|
GActionGroup *original_group,
|
|
|
|
const gchar *orignal_action_name)
|
2011-11-30 14:33:03 +00:00
|
|
|
{
|
|
|
|
const GVariantType *parameter_type;
|
|
|
|
gboolean enabled;
|
|
|
|
GVariant *state;
|
2012-08-17 17:16:51 +00:00
|
|
|
Action *action;
|
2011-11-30 14:33:03 +00:00
|
|
|
|
2012-08-17 17:16:51 +00:00
|
|
|
action = g_hash_table_lookup (muxer->observed_actions, action_name);
|
|
|
|
|
|
|
|
if (action && action->watchers &&
|
|
|
|
g_action_group_query_action (original_group, orignal_action_name,
|
|
|
|
&enabled, ¶meter_type, NULL, NULL, &state))
|
2011-11-30 14:33:03 +00:00
|
|
|
{
|
|
|
|
GSList *node;
|
|
|
|
|
2012-08-17 17:16:51 +00:00
|
|
|
for (node = action->watchers; node; node = node->next)
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_observer_action_added (node->data,
|
|
|
|
GTK_ACTION_OBSERVABLE (muxer),
|
2012-08-17 17:16:51 +00:00
|
|
|
action_name, parameter_type, enabled, state);
|
2011-11-30 14:33:03 +00:00
|
|
|
|
|
|
|
if (state)
|
|
|
|
g_variant_unref (state);
|
|
|
|
}
|
2012-08-17 17:16:51 +00:00
|
|
|
|
|
|
|
g_action_group_action_added (G_ACTION_GROUP (muxer), action_name);
|
2011-11-30 14:33:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_action_added_to_group (GActionGroup *action_group,
|
|
|
|
const gchar *action_name,
|
|
|
|
gpointer user_data)
|
2011-11-30 14:33:03 +00:00
|
|
|
{
|
|
|
|
Group *group = user_data;
|
|
|
|
gchar *fullname;
|
2012-08-17 17:16:51 +00:00
|
|
|
|
|
|
|
fullname = g_strconcat (group->prefix, ".", action_name, NULL);
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_action_added (group->muxer, fullname, action_group, action_name);
|
2012-08-17 17:16:51 +00:00
|
|
|
|
|
|
|
g_free (fullname);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_action_added_to_parent (GActionGroup *action_group,
|
|
|
|
const gchar *action_name,
|
|
|
|
gpointer user_data)
|
2012-08-17 17:16:51 +00:00
|
|
|
{
|
2013-05-09 18:15:51 +00:00
|
|
|
GtkActionMuxer *muxer = user_data;
|
2012-08-17 17:16:51 +00:00
|
|
|
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_action_added (muxer, action_name, action_group, action_name);
|
2012-08-17 17:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_action_removed (GtkActionMuxer *muxer,
|
|
|
|
const gchar *action_name)
|
2012-08-17 17:16:51 +00:00
|
|
|
{
|
2011-11-30 14:33:03 +00:00
|
|
|
Action *action;
|
|
|
|
GSList *node;
|
|
|
|
|
2012-08-17 17:16:51 +00:00
|
|
|
action = g_hash_table_lookup (muxer->observed_actions, action_name);
|
2011-11-30 14:33:03 +00:00
|
|
|
for (node = action ? action->watchers : NULL; node; node = node->next)
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_observer_action_removed (node->data, GTK_ACTION_OBSERVABLE (muxer), action_name);
|
2012-08-17 17:16:51 +00:00
|
|
|
g_action_group_action_removed (G_ACTION_GROUP (muxer), action_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_action_removed_from_group (GActionGroup *action_group,
|
|
|
|
const gchar *action_name,
|
|
|
|
gpointer user_data)
|
2012-08-17 17:16:51 +00:00
|
|
|
{
|
|
|
|
Group *group = user_data;
|
|
|
|
gchar *fullname;
|
|
|
|
|
|
|
|
fullname = g_strconcat (group->prefix, ".", action_name, NULL);
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_action_removed (group->muxer, fullname);
|
2012-08-17 17:16:51 +00:00
|
|
|
|
2011-11-30 14:33:03 +00:00
|
|
|
g_free (fullname);
|
|
|
|
}
|
|
|
|
|
2012-08-17 17:16:51 +00:00
|
|
|
static void
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_action_removed_from_parent (GActionGroup *action_group,
|
|
|
|
const gchar *action_name,
|
|
|
|
gpointer user_data)
|
2012-08-17 17:16:51 +00:00
|
|
|
{
|
2013-05-09 18:15:51 +00:00
|
|
|
GtkActionMuxer *muxer = user_data;
|
2012-08-17 17:16:51 +00:00
|
|
|
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_action_removed (muxer, action_name);
|
2012-08-17 17:16:51 +00:00
|
|
|
}
|
|
|
|
|
2013-07-10 02:37:17 +00:00
|
|
|
static void
|
|
|
|
gtk_action_muxer_primary_accel_changed (GtkActionMuxer *muxer,
|
|
|
|
const gchar *action_name,
|
|
|
|
const gchar *action_and_target)
|
|
|
|
{
|
|
|
|
Action *action;
|
|
|
|
GSList *node;
|
|
|
|
|
|
|
|
if (!action_name)
|
|
|
|
action_name = strrchr (action_and_target, '|') + 1;
|
|
|
|
|
|
|
|
action = g_hash_table_lookup (muxer->observed_actions, action_name);
|
|
|
|
for (node = action ? action->watchers : NULL; node; node = node->next)
|
|
|
|
gtk_action_observer_primary_accel_changed (node->data, GTK_ACTION_OBSERVABLE (muxer),
|
|
|
|
action_name, action_and_target);
|
|
|
|
g_signal_emit (muxer, accel_signal, 0, action_name, action_and_target);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_action_muxer_parent_primary_accel_changed (GtkActionMuxer *parent,
|
|
|
|
const gchar *action_name,
|
|
|
|
const gchar *action_and_target,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkActionMuxer *muxer = user_data;
|
|
|
|
|
|
|
|
/* If it's in our table then don't let the parent one filter through */
|
|
|
|
if (muxer->primary_accels && g_hash_table_lookup (muxer->primary_accels, action_and_target))
|
|
|
|
return;
|
|
|
|
|
|
|
|
gtk_action_muxer_primary_accel_changed (muxer, action_name, action_and_target);
|
|
|
|
}
|
|
|
|
|
2011-11-30 14:33:03 +00:00
|
|
|
static gboolean
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_query_action (GActionGroup *action_group,
|
|
|
|
const gchar *action_name,
|
|
|
|
gboolean *enabled,
|
|
|
|
const GVariantType **parameter_type,
|
|
|
|
const GVariantType **state_type,
|
|
|
|
GVariant **state_hint,
|
|
|
|
GVariant **state)
|
|
|
|
{
|
|
|
|
GtkActionMuxer *muxer = GTK_ACTION_MUXER (action_group);
|
2011-11-30 14:33:03 +00:00
|
|
|
Group *group;
|
2012-08-17 17:16:51 +00:00
|
|
|
const gchar *unprefixed_name;
|
2011-11-30 14:33:03 +00:00
|
|
|
|
2013-05-09 18:15:51 +00:00
|
|
|
group = gtk_action_muxer_find_group (muxer, action_name, &unprefixed_name);
|
2011-11-30 14:33:03 +00:00
|
|
|
|
2012-08-17 17:16:51 +00:00
|
|
|
if (group)
|
|
|
|
return g_action_group_query_action (group->group, unprefixed_name, enabled,
|
|
|
|
parameter_type, state_type, state_hint, state);
|
2011-11-30 14:33:03 +00:00
|
|
|
|
2012-08-17 17:16:51 +00:00
|
|
|
if (muxer->parent)
|
|
|
|
return g_action_group_query_action (G_ACTION_GROUP (muxer->parent), action_name,
|
|
|
|
enabled, parameter_type,
|
|
|
|
state_type, state_hint, state);
|
|
|
|
|
|
|
|
return FALSE;
|
2011-11-30 14:33:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_activate_action (GActionGroup *action_group,
|
|
|
|
const gchar *action_name,
|
|
|
|
GVariant *parameter)
|
2011-11-30 14:33:03 +00:00
|
|
|
{
|
2013-05-09 18:15:51 +00:00
|
|
|
GtkActionMuxer *muxer = GTK_ACTION_MUXER (action_group);
|
2011-11-30 14:33:03 +00:00
|
|
|
Group *group;
|
2012-08-17 17:16:51 +00:00
|
|
|
const gchar *unprefixed_name;
|
2011-11-30 14:33:03 +00:00
|
|
|
|
2013-05-09 18:15:51 +00:00
|
|
|
group = gtk_action_muxer_find_group (muxer, action_name, &unprefixed_name);
|
2011-11-30 14:33:03 +00:00
|
|
|
|
|
|
|
if (group)
|
2012-08-17 17:16:51 +00:00
|
|
|
g_action_group_activate_action (group->group, unprefixed_name, parameter);
|
|
|
|
else if (muxer->parent)
|
|
|
|
g_action_group_activate_action (G_ACTION_GROUP (muxer->parent), action_name, parameter);
|
2011-11-30 14:33:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_change_action_state (GActionGroup *action_group,
|
|
|
|
const gchar *action_name,
|
|
|
|
GVariant *state)
|
2011-11-30 14:33:03 +00:00
|
|
|
{
|
2013-05-09 18:15:51 +00:00
|
|
|
GtkActionMuxer *muxer = GTK_ACTION_MUXER (action_group);
|
2011-11-30 14:33:03 +00:00
|
|
|
Group *group;
|
2012-08-17 17:16:51 +00:00
|
|
|
const gchar *unprefixed_name;
|
2011-11-30 14:33:03 +00:00
|
|
|
|
2013-05-09 18:15:51 +00:00
|
|
|
group = gtk_action_muxer_find_group (muxer, action_name, &unprefixed_name);
|
2011-11-30 14:33:03 +00:00
|
|
|
|
|
|
|
if (group)
|
2012-08-17 17:16:51 +00:00
|
|
|
g_action_group_change_action_state (group->group, unprefixed_name, state);
|
|
|
|
else if (muxer->parent)
|
|
|
|
g_action_group_change_action_state (G_ACTION_GROUP (muxer->parent), action_name, state);
|
2011-11-30 14:33:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_unregister_internal (Action *action,
|
|
|
|
gpointer observer)
|
2011-11-30 14:33:03 +00:00
|
|
|
{
|
2013-05-09 18:15:51 +00:00
|
|
|
GtkActionMuxer *muxer = action->muxer;
|
2011-11-30 14:33:03 +00:00
|
|
|
GSList **ptr;
|
|
|
|
|
|
|
|
for (ptr = &action->watchers; *ptr; ptr = &(*ptr)->next)
|
|
|
|
if ((*ptr)->data == observer)
|
|
|
|
{
|
|
|
|
*ptr = g_slist_remove (*ptr, observer);
|
|
|
|
|
|
|
|
if (action->watchers == NULL)
|
2012-08-17 17:16:51 +00:00
|
|
|
g_hash_table_remove (muxer->observed_actions, action->fullname);
|
2011-11-30 14:33:03 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_weak_notify (gpointer data,
|
|
|
|
GObject *where_the_object_was)
|
2011-11-30 14:33:03 +00:00
|
|
|
{
|
|
|
|
Action *action = data;
|
|
|
|
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_unregister_internal (action, where_the_object_was);
|
2011-11-30 14:33:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_register_observer (GtkActionObservable *observable,
|
|
|
|
const gchar *name,
|
|
|
|
GtkActionObserver *observer)
|
2011-11-30 14:33:03 +00:00
|
|
|
{
|
2013-05-09 18:15:51 +00:00
|
|
|
GtkActionMuxer *muxer = GTK_ACTION_MUXER (observable);
|
2011-11-30 14:33:03 +00:00
|
|
|
Action *action;
|
|
|
|
|
2012-08-17 17:16:51 +00:00
|
|
|
action = g_hash_table_lookup (muxer->observed_actions, name);
|
2011-11-30 14:33:03 +00:00
|
|
|
|
|
|
|
if (action == NULL)
|
|
|
|
{
|
|
|
|
action = g_slice_new (Action);
|
2012-08-17 17:16:51 +00:00
|
|
|
action->muxer = muxer;
|
2011-11-30 14:33:03 +00:00
|
|
|
action->fullname = g_strdup (name);
|
|
|
|
action->watchers = NULL;
|
|
|
|
|
2012-08-17 17:16:51 +00:00
|
|
|
g_hash_table_insert (muxer->observed_actions, action->fullname, action);
|
2011-11-30 14:33:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
action->watchers = g_slist_prepend (action->watchers, observer);
|
2013-05-09 18:15:51 +00:00
|
|
|
g_object_weak_ref (G_OBJECT (observer), gtk_action_muxer_weak_notify, action);
|
2011-11-30 14:33:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_unregister_observer (GtkActionObservable *observable,
|
|
|
|
const gchar *name,
|
|
|
|
GtkActionObserver *observer)
|
2011-11-30 14:33:03 +00:00
|
|
|
{
|
2013-05-09 18:15:51 +00:00
|
|
|
GtkActionMuxer *muxer = GTK_ACTION_MUXER (observable);
|
2011-11-30 14:33:03 +00:00
|
|
|
Action *action;
|
|
|
|
|
2012-08-17 17:16:51 +00:00
|
|
|
action = g_hash_table_lookup (muxer->observed_actions, name);
|
2013-05-09 18:15:51 +00:00
|
|
|
g_object_weak_unref (G_OBJECT (observer), gtk_action_muxer_weak_notify, action);
|
|
|
|
gtk_action_muxer_unregister_internal (action, observer);
|
2011-11-30 14:33:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_free_group (gpointer data)
|
2011-11-30 14:33:03 +00:00
|
|
|
{
|
|
|
|
Group *group = data;
|
2012-06-29 03:55:33 +00:00
|
|
|
gint i;
|
|
|
|
|
|
|
|
/* 'for loop' or 'four loop'? */
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
g_signal_handler_disconnect (group->group, group->handler_ids[i]);
|
2011-11-30 14:33:03 +00:00
|
|
|
|
|
|
|
g_object_unref (group->group);
|
|
|
|
g_free (group->prefix);
|
|
|
|
|
|
|
|
g_slice_free (Group, group);
|
|
|
|
}
|
|
|
|
|
2012-08-17 17:16:51 +00:00
|
|
|
static void
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_free_action (gpointer data)
|
2012-08-17 17:16:51 +00:00
|
|
|
{
|
|
|
|
Action *action = data;
|
|
|
|
GSList *it;
|
|
|
|
|
|
|
|
for (it = action->watchers; it; it = it->next)
|
2013-05-09 18:15:51 +00:00
|
|
|
g_object_weak_unref (G_OBJECT (it->data), gtk_action_muxer_weak_notify, action);
|
2012-08-17 17:16:51 +00:00
|
|
|
|
|
|
|
g_slist_free (action->watchers);
|
|
|
|
g_free (action->fullname);
|
|
|
|
|
|
|
|
g_slice_free (Action, action);
|
|
|
|
}
|
|
|
|
|
2011-11-30 14:33:03 +00:00
|
|
|
static void
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_finalize (GObject *object)
|
2011-11-30 14:33:03 +00:00
|
|
|
{
|
2013-05-09 18:15:51 +00:00
|
|
|
GtkActionMuxer *muxer = GTK_ACTION_MUXER (object);
|
2011-11-30 14:33:03 +00:00
|
|
|
|
2012-08-17 17:16:51 +00:00
|
|
|
g_assert_cmpint (g_hash_table_size (muxer->observed_actions), ==, 0);
|
|
|
|
g_hash_table_unref (muxer->observed_actions);
|
2011-11-30 14:33:03 +00:00
|
|
|
g_hash_table_unref (muxer->groups);
|
|
|
|
|
2013-05-09 18:15:51 +00:00
|
|
|
G_OBJECT_CLASS (gtk_action_muxer_parent_class)
|
2011-11-30 14:33:03 +00:00
|
|
|
->finalize (object);
|
|
|
|
}
|
|
|
|
|
2012-08-17 17:16:51 +00:00
|
|
|
static void
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_dispose (GObject *object)
|
2012-08-17 17:16:51 +00:00
|
|
|
{
|
2013-05-09 18:15:51 +00:00
|
|
|
GtkActionMuxer *muxer = GTK_ACTION_MUXER (object);
|
2012-08-17 17:16:51 +00:00
|
|
|
|
|
|
|
if (muxer->parent)
|
|
|
|
{
|
2013-05-09 18:15:51 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (muxer->parent, gtk_action_muxer_action_added_to_parent, muxer);
|
|
|
|
g_signal_handlers_disconnect_by_func (muxer->parent, gtk_action_muxer_action_removed_from_parent, muxer);
|
|
|
|
g_signal_handlers_disconnect_by_func (muxer->parent, gtk_action_muxer_parent_action_enabled_changed, muxer);
|
|
|
|
g_signal_handlers_disconnect_by_func (muxer->parent, gtk_action_muxer_parent_action_state_changed, muxer);
|
2013-07-10 02:37:17 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (muxer->parent, gtk_action_muxer_parent_primary_accel_changed, muxer);
|
2012-08-17 17:16:51 +00:00
|
|
|
|
|
|
|
g_clear_object (&muxer->parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_hash_table_remove_all (muxer->observed_actions);
|
|
|
|
|
2013-05-09 18:15:51 +00:00
|
|
|
G_OBJECT_CLASS (gtk_action_muxer_parent_class)
|
2012-08-17 17:16:51 +00:00
|
|
|
->dispose (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2012-08-17 17:16:51 +00:00
|
|
|
{
|
2013-05-09 18:15:51 +00:00
|
|
|
GtkActionMuxer *muxer = GTK_ACTION_MUXER (object);
|
2012-08-17 17:16:51 +00:00
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_PARENT:
|
2013-05-09 18:15:51 +00:00
|
|
|
g_value_set_object (value, gtk_action_muxer_get_parent (muxer));
|
2012-08-17 17:16:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2012-08-17 17:16:51 +00:00
|
|
|
{
|
2013-05-09 18:15:51 +00:00
|
|
|
GtkActionMuxer *muxer = GTK_ACTION_MUXER (object);
|
2012-08-17 17:16:51 +00:00
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_PARENT:
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_set_parent (muxer, g_value_get_object (value));
|
2012-08-17 17:16:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-30 14:33:03 +00:00
|
|
|
static void
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_init (GtkActionMuxer *muxer)
|
2011-11-30 14:33:03 +00:00
|
|
|
{
|
2013-05-09 18:15:51 +00:00
|
|
|
muxer->observed_actions = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, gtk_action_muxer_free_action);
|
|
|
|
muxer->groups = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, gtk_action_muxer_free_group);
|
2011-11-30 14:33:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_observable_iface_init (GtkActionObservableInterface *iface)
|
2011-11-30 14:33:03 +00:00
|
|
|
{
|
2013-05-09 18:15:51 +00:00
|
|
|
iface->register_observer = gtk_action_muxer_register_observer;
|
|
|
|
iface->unregister_observer = gtk_action_muxer_unregister_observer;
|
2011-11-30 14:33:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_group_iface_init (GActionGroupInterface *iface)
|
2011-11-30 14:33:03 +00:00
|
|
|
{
|
2013-05-09 18:15:51 +00:00
|
|
|
iface->list_actions = gtk_action_muxer_list_actions;
|
|
|
|
iface->query_action = gtk_action_muxer_query_action;
|
|
|
|
iface->activate_action = gtk_action_muxer_activate_action;
|
|
|
|
iface->change_action_state = gtk_action_muxer_change_action_state;
|
2011-11-30 14:33:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_class_init (GObjectClass *class)
|
2011-11-30 14:33:03 +00:00
|
|
|
{
|
2013-05-09 18:15:51 +00:00
|
|
|
class->get_property = gtk_action_muxer_get_property;
|
|
|
|
class->set_property = gtk_action_muxer_set_property;
|
|
|
|
class->finalize = gtk_action_muxer_finalize;
|
|
|
|
class->dispose = gtk_action_muxer_dispose;
|
2012-08-17 17:16:51 +00:00
|
|
|
|
2013-07-10 02:37:17 +00:00
|
|
|
accel_signal = g_signal_new ("primary-accel-changed", GTK_TYPE_ACTION_MUXER, G_SIGNAL_RUN_LAST,
|
|
|
|
0, NULL, NULL, NULL, G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRING);
|
|
|
|
|
2012-08-17 17:16:51 +00:00
|
|
|
properties[PROP_PARENT] = g_param_spec_object ("parent", "Parent",
|
|
|
|
"The parent muxer",
|
2013-05-09 18:15:51 +00:00
|
|
|
GTK_TYPE_ACTION_MUXER,
|
2012-08-17 17:16:51 +00:00
|
|
|
G_PARAM_READWRITE |
|
|
|
|
G_PARAM_STATIC_STRINGS);
|
|
|
|
|
|
|
|
g_object_class_install_properties (class, NUM_PROPERTIES, properties);
|
2011-11-30 14:33:03 +00:00
|
|
|
}
|
|
|
|
|
2013-05-09 19:28:57 +00:00
|
|
|
/**
|
2013-05-09 18:15:51 +00:00
|
|
|
* gtk_action_muxer_insert:
|
|
|
|
* @muxer: a #GtkActionMuxer
|
2011-11-30 14:33:03 +00:00
|
|
|
* @prefix: the prefix string for the action group
|
|
|
|
* @action_group: a #GActionGroup
|
|
|
|
*
|
|
|
|
* Adds the actions in @action_group to the list of actions provided by
|
|
|
|
* @muxer. @prefix is prefixed to each action name, such that for each
|
|
|
|
* action <varname>x</varname> in @action_group, there is an equivalent
|
|
|
|
* action @prefix<literal>.</literal><varname>x</varname> in @muxer.
|
|
|
|
*
|
|
|
|
* For example, if @prefix is "<literal>app</literal>" and @action_group
|
|
|
|
* contains an action called "<literal>quit</literal>", then @muxer will
|
|
|
|
* now contain an action called "<literal>app.quit</literal>".
|
|
|
|
*
|
2013-05-09 18:15:51 +00:00
|
|
|
* If any #GtkActionObservers are registered for actions in the group,
|
2011-11-30 14:33:03 +00:00
|
|
|
* "action_added" notifications will be emitted, as appropriate.
|
|
|
|
*
|
|
|
|
* @prefix must not contain a dot ('.').
|
2011-12-01 11:30:10 +00:00
|
|
|
*/
|
2011-11-30 14:33:03 +00:00
|
|
|
void
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_insert (GtkActionMuxer *muxer,
|
|
|
|
const gchar *prefix,
|
|
|
|
GActionGroup *action_group)
|
2011-11-30 14:33:03 +00:00
|
|
|
{
|
|
|
|
gchar **actions;
|
|
|
|
Group *group;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
/* TODO: diff instead of ripout and replace */
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_remove (muxer, prefix);
|
2011-11-30 14:33:03 +00:00
|
|
|
|
|
|
|
group = g_slice_new (Group);
|
|
|
|
group->muxer = muxer;
|
|
|
|
group->group = g_object_ref (action_group);
|
|
|
|
group->prefix = g_strdup (prefix);
|
|
|
|
|
|
|
|
g_hash_table_insert (muxer->groups, group->prefix, group);
|
|
|
|
|
|
|
|
actions = g_action_group_list_actions (group->group);
|
|
|
|
for (i = 0; actions[i]; i++)
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_action_added_to_group (group->group, actions[i], group);
|
2011-11-30 14:33:03 +00:00
|
|
|
g_strfreev (actions);
|
|
|
|
|
|
|
|
group->handler_ids[0] = g_signal_connect (group->group, "action-added",
|
2013-05-09 18:15:51 +00:00
|
|
|
G_CALLBACK (gtk_action_muxer_action_added_to_group), group);
|
2011-11-30 14:33:03 +00:00
|
|
|
group->handler_ids[1] = g_signal_connect (group->group, "action-removed",
|
2013-05-09 18:15:51 +00:00
|
|
|
G_CALLBACK (gtk_action_muxer_action_removed_from_group), group);
|
2011-11-30 14:33:03 +00:00
|
|
|
group->handler_ids[2] = g_signal_connect (group->group, "action-enabled-changed",
|
2013-05-09 18:15:51 +00:00
|
|
|
G_CALLBACK (gtk_action_muxer_group_action_enabled_changed), group);
|
2011-11-30 14:33:03 +00:00
|
|
|
group->handler_ids[3] = g_signal_connect (group->group, "action-state-changed",
|
2013-05-09 18:15:51 +00:00
|
|
|
G_CALLBACK (gtk_action_muxer_group_action_state_changed), group);
|
2011-11-30 14:33:03 +00:00
|
|
|
}
|
|
|
|
|
2013-05-09 19:28:57 +00:00
|
|
|
/**
|
2013-05-09 18:15:51 +00:00
|
|
|
* gtk_action_muxer_remove:
|
|
|
|
* @muxer: a #GtkActionMuxer
|
2011-11-30 14:33:03 +00:00
|
|
|
* @prefix: the prefix of the action group to remove
|
|
|
|
*
|
2013-05-09 18:15:51 +00:00
|
|
|
* Removes a #GActionGroup from the #GtkActionMuxer.
|
2011-11-30 14:33:03 +00:00
|
|
|
*
|
2013-05-09 18:15:51 +00:00
|
|
|
* If any #GtkActionObservers are registered for actions in the group,
|
2011-11-30 14:33:03 +00:00
|
|
|
* "action_removed" notifications will be emitted, as appropriate.
|
2011-12-01 11:30:10 +00:00
|
|
|
*/
|
2011-11-30 14:33:03 +00:00
|
|
|
void
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_remove (GtkActionMuxer *muxer,
|
|
|
|
const gchar *prefix)
|
2011-11-30 14:33:03 +00:00
|
|
|
{
|
|
|
|
Group *group;
|
|
|
|
|
|
|
|
group = g_hash_table_lookup (muxer->groups, prefix);
|
|
|
|
|
|
|
|
if (group != NULL)
|
|
|
|
{
|
|
|
|
gchar **actions;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
g_hash_table_steal (muxer->groups, prefix);
|
|
|
|
|
|
|
|
actions = g_action_group_list_actions (group->group);
|
|
|
|
for (i = 0; actions[i]; i++)
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_action_removed_from_group (group->group, actions[i], group);
|
2011-11-30 14:33:03 +00:00
|
|
|
g_strfreev (actions);
|
|
|
|
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_free_group (group);
|
2011-11-30 14:33:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-09 19:28:57 +00:00
|
|
|
/**
|
2013-05-09 18:15:51 +00:00
|
|
|
* gtk_action_muxer_new:
|
2011-11-30 14:33:03 +00:00
|
|
|
*
|
2013-05-09 18:15:51 +00:00
|
|
|
* Creates a new #GtkActionMuxer.
|
2011-12-01 11:30:10 +00:00
|
|
|
*/
|
2013-05-09 18:15:51 +00:00
|
|
|
GtkActionMuxer *
|
|
|
|
gtk_action_muxer_new (void)
|
2011-11-30 14:33:03 +00:00
|
|
|
{
|
2013-05-09 18:15:51 +00:00
|
|
|
return g_object_new (GTK_TYPE_ACTION_MUXER, NULL);
|
2011-11-30 14:33:03 +00:00
|
|
|
}
|
2012-08-17 17:16:51 +00:00
|
|
|
|
2013-05-09 19:28:57 +00:00
|
|
|
/**
|
|
|
|
* gtk_action_muxer_get_parent:
|
2013-05-09 18:15:51 +00:00
|
|
|
* @muxer: a #GtkActionMuxer
|
2012-08-17 17:16:51 +00:00
|
|
|
*
|
2013-05-09 19:28:57 +00:00
|
|
|
* Returns: (transfer none): the parent of @muxer, or NULL.
|
2012-08-17 17:16:51 +00:00
|
|
|
*/
|
2013-05-09 18:15:51 +00:00
|
|
|
GtkActionMuxer *
|
|
|
|
gtk_action_muxer_get_parent (GtkActionMuxer *muxer)
|
2012-08-17 17:16:51 +00:00
|
|
|
{
|
2013-05-09 18:15:51 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_ACTION_MUXER (muxer), NULL);
|
2012-08-17 17:16:51 +00:00
|
|
|
|
|
|
|
return muxer->parent;
|
|
|
|
}
|
|
|
|
|
2013-07-10 02:37:17 +00:00
|
|
|
static void
|
|
|
|
emit_changed_accels (GtkActionMuxer *muxer,
|
|
|
|
GtkActionMuxer *parent)
|
|
|
|
{
|
|
|
|
while (parent)
|
|
|
|
{
|
|
|
|
if (parent->primary_accels)
|
|
|
|
{
|
|
|
|
GHashTableIter iter;
|
|
|
|
gpointer key;
|
|
|
|
|
|
|
|
g_hash_table_iter_init (&iter, parent->primary_accels);
|
|
|
|
while (g_hash_table_iter_next (&iter, &key, NULL))
|
|
|
|
gtk_action_muxer_primary_accel_changed (muxer, NULL, key);
|
|
|
|
}
|
|
|
|
|
|
|
|
parent = parent->parent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-09 19:28:57 +00:00
|
|
|
/**
|
|
|
|
* gtk_action_muxer_set_parent:
|
2013-05-09 18:15:51 +00:00
|
|
|
* @muxer: a #GtkActionMuxer
|
|
|
|
* @parent: (allow-none): the new parent #GtkActionMuxer
|
2012-08-17 17:16:51 +00:00
|
|
|
*
|
|
|
|
* Sets the parent of @muxer to @parent.
|
|
|
|
*/
|
|
|
|
void
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_set_parent (GtkActionMuxer *muxer,
|
|
|
|
GtkActionMuxer *parent)
|
2012-08-17 17:16:51 +00:00
|
|
|
{
|
2013-05-09 18:15:51 +00:00
|
|
|
g_return_if_fail (GTK_IS_ACTION_MUXER (muxer));
|
|
|
|
g_return_if_fail (parent == NULL || GTK_IS_ACTION_MUXER (parent));
|
2012-08-17 17:16:51 +00:00
|
|
|
|
|
|
|
if (muxer->parent == parent)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (muxer->parent != NULL)
|
|
|
|
{
|
|
|
|
gchar **actions;
|
|
|
|
gchar **it;
|
|
|
|
|
|
|
|
actions = g_action_group_list_actions (G_ACTION_GROUP (muxer->parent));
|
|
|
|
for (it = actions; *it; it++)
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_action_removed (muxer, *it);
|
2012-08-17 17:16:51 +00:00
|
|
|
g_strfreev (actions);
|
|
|
|
|
2013-07-10 02:37:17 +00:00
|
|
|
emit_changed_accels (muxer, muxer->parent);
|
|
|
|
|
2013-05-09 18:15:51 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (muxer->parent, gtk_action_muxer_action_added_to_parent, muxer);
|
|
|
|
g_signal_handlers_disconnect_by_func (muxer->parent, gtk_action_muxer_action_removed_from_parent, muxer);
|
|
|
|
g_signal_handlers_disconnect_by_func (muxer->parent, gtk_action_muxer_parent_action_enabled_changed, muxer);
|
|
|
|
g_signal_handlers_disconnect_by_func (muxer->parent, gtk_action_muxer_parent_action_state_changed, muxer);
|
2013-07-10 02:37:17 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (muxer->parent, gtk_action_muxer_parent_primary_accel_changed, muxer);
|
2012-08-17 17:16:51 +00:00
|
|
|
|
|
|
|
g_object_unref (muxer->parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
muxer->parent = parent;
|
|
|
|
|
|
|
|
if (muxer->parent != NULL)
|
|
|
|
{
|
|
|
|
gchar **actions;
|
|
|
|
gchar **it;
|
|
|
|
|
|
|
|
g_object_ref (muxer->parent);
|
|
|
|
|
|
|
|
actions = g_action_group_list_actions (G_ACTION_GROUP (muxer->parent));
|
|
|
|
for (it = actions; *it; it++)
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_action_added (muxer, *it, G_ACTION_GROUP (muxer->parent), *it);
|
2012-08-17 17:16:51 +00:00
|
|
|
g_strfreev (actions);
|
|
|
|
|
2013-07-10 02:37:17 +00:00
|
|
|
emit_changed_accels (muxer, muxer->parent);
|
|
|
|
|
2012-08-17 17:16:51 +00:00
|
|
|
g_signal_connect (muxer->parent, "action-added",
|
2013-05-09 18:15:51 +00:00
|
|
|
G_CALLBACK (gtk_action_muxer_action_added_to_parent), muxer);
|
2012-08-17 17:16:51 +00:00
|
|
|
g_signal_connect (muxer->parent, "action-removed",
|
2013-05-09 18:15:51 +00:00
|
|
|
G_CALLBACK (gtk_action_muxer_action_removed_from_parent), muxer);
|
2012-08-17 17:16:51 +00:00
|
|
|
g_signal_connect (muxer->parent, "action-enabled-changed",
|
2013-05-09 18:15:51 +00:00
|
|
|
G_CALLBACK (gtk_action_muxer_parent_action_enabled_changed), muxer);
|
2012-08-17 17:16:51 +00:00
|
|
|
g_signal_connect (muxer->parent, "action-state-changed",
|
2013-05-09 18:15:51 +00:00
|
|
|
G_CALLBACK (gtk_action_muxer_parent_action_state_changed), muxer);
|
2013-07-10 02:37:17 +00:00
|
|
|
g_signal_connect (muxer->parent, "primary-accel-changed",
|
|
|
|
G_CALLBACK (gtk_action_muxer_parent_primary_accel_changed), muxer);
|
2012-08-17 17:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (muxer), properties[PROP_PARENT]);
|
|
|
|
}
|
2013-07-10 02:37:17 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
gtk_action_muxer_set_primary_accel (GtkActionMuxer *muxer,
|
|
|
|
const gchar *action_and_target,
|
|
|
|
const gchar *primary_accel)
|
|
|
|
{
|
|
|
|
if (!muxer->primary_accels)
|
|
|
|
muxer->primary_accels = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
|
|
|
|
|
|
|
|
if (primary_accel)
|
|
|
|
g_hash_table_insert (muxer->primary_accels, g_strdup (action_and_target), g_strdup (primary_accel));
|
|
|
|
else
|
|
|
|
g_hash_table_remove (muxer->primary_accels, action_and_target);
|
|
|
|
|
|
|
|
gtk_action_muxer_primary_accel_changed (muxer, NULL, action_and_target);
|
|
|
|
}
|
|
|
|
|
|
|
|
const gchar *
|
|
|
|
gtk_action_muxer_get_primary_accel (GtkActionMuxer *muxer,
|
|
|
|
const gchar *action_and_target)
|
|
|
|
{
|
|
|
|
if (muxer->primary_accels)
|
|
|
|
{
|
|
|
|
const gchar *primary_accel;
|
|
|
|
|
|
|
|
primary_accel = g_hash_table_lookup (muxer->primary_accels, action_and_target);
|
|
|
|
|
|
|
|
if (primary_accel)
|
|
|
|
return primary_accel;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!muxer->parent)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return gtk_action_muxer_get_primary_accel (muxer->parent, action_and_target);
|
|
|
|
}
|
|
|
|
|
|
|
|
gchar *
|
|
|
|
gtk_print_action_and_target (const gchar *action_namespace,
|
|
|
|
const gchar *action_name,
|
|
|
|
GVariant *target)
|
|
|
|
{
|
|
|
|
GString *result;
|
|
|
|
|
2013-10-27 21:36:32 +00:00
|
|
|
g_return_val_if_fail (strchr (action_name, '|') == NULL, NULL);
|
|
|
|
g_return_val_if_fail (action_namespace == NULL || strchr (action_namespace, '|') == NULL, NULL);
|
2013-07-10 02:37:17 +00:00
|
|
|
|
|
|
|
result = g_string_new (NULL);
|
|
|
|
|
|
|
|
if (target)
|
|
|
|
g_variant_print_string (target, result, TRUE);
|
|
|
|
g_string_append_c (result, '|');
|
|
|
|
|
|
|
|
if (action_namespace)
|
|
|
|
{
|
|
|
|
g_string_append (result, action_namespace);
|
|
|
|
g_string_append_c (result, '.');
|
|
|
|
}
|
|
|
|
|
|
|
|
g_string_append (result, action_name);
|
|
|
|
|
|
|
|
return g_string_free (result, FALSE);
|
|
|
|
}
|