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"
|
|
|
|
|
2018-02-02 09:13:10 +00:00
|
|
|
#include "gtkactionmuxerprivate.h"
|
2011-11-30 14:33:03 +00:00
|
|
|
|
2019-06-10 03:10:13 +00:00
|
|
|
#include "gtkactionobservableprivate.h"
|
|
|
|
#include "gtkactionobserverprivate.h"
|
2020-03-20 16:22:29 +00:00
|
|
|
#include "gtkbitmaskprivate.h"
|
2015-09-12 13:13:00 +00:00
|
|
|
#include "gtkintl.h"
|
2019-06-02 21:07:27 +00:00
|
|
|
#include "gtkmarshalers.h"
|
2020-03-20 16:22:29 +00:00
|
|
|
#include "gtkwidgetprivate.h"
|
2019-06-22 20:18:05 +00:00
|
|
|
#include "gsettings-mapping.h"
|
2011-11-30 14:33:03 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2020-07-19 19:11:35 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
char *action_and_target;
|
|
|
|
char *accel;
|
|
|
|
} GtkAccel;
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_accel_clear (GtkAccel *accel)
|
|
|
|
{
|
|
|
|
g_free (accel->action_and_target);
|
|
|
|
g_free (accel->accel);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define GDK_ARRAY_NAME gtk_accels
|
|
|
|
#define GDK_ARRAY_TYPE_NAME GtkAccels
|
|
|
|
#define GDK_ARRAY_ELEMENT_TYPE GtkAccel
|
|
|
|
#define GDK_ARRAY_FREE_FUNC gtk_accel_clear
|
|
|
|
#define GDK_ARRAY_BY_VALUE 1
|
|
|
|
#define GDK_ARRAY_PREALLOC 2
|
|
|
|
#include "gdk/gdkarrayimpl.c"
|
|
|
|
|
|
|
|
static guint
|
|
|
|
gtk_accels_find (GtkAccels *accels,
|
|
|
|
const char *action_and_target)
|
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
for (i = 0; i < gtk_accels_get_size (accels); i++)
|
|
|
|
{
|
|
|
|
GtkAccel *accel = gtk_accels_index (accels, i);
|
|
|
|
if (strcmp (accel->action_and_target, action_and_target) == 0)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return G_MAXUINT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_accels_replace (GtkAccels *accels,
|
|
|
|
const char *action_and_target,
|
|
|
|
const char *primary_accel)
|
|
|
|
{
|
|
|
|
guint position;
|
|
|
|
|
|
|
|
position = gtk_accels_find (accels, action_and_target);
|
|
|
|
if (position < gtk_accels_get_size (accels))
|
|
|
|
{
|
|
|
|
GtkAccel *accel = gtk_accels_index (accels, position);
|
|
|
|
g_free (accel->accel);
|
|
|
|
accel->accel = g_strdup (primary_accel);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GtkAccel accel;
|
|
|
|
|
|
|
|
accel.action_and_target = g_strdup (action_and_target);
|
|
|
|
accel.accel = g_strdup (primary_accel);
|
|
|
|
gtk_accels_append (accels, &accel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_accels_remove (GtkAccels *accels,
|
|
|
|
const char *action_and_target)
|
|
|
|
{
|
|
|
|
guint position;
|
|
|
|
|
|
|
|
position = gtk_accels_find (accels, action_and_target);
|
|
|
|
if (position < gtk_accels_get_size (accels))
|
|
|
|
gtk_accels_splice (accels, position, 1, NULL, 0);
|
|
|
|
}
|
|
|
|
|
2014-01-22 02:47:34 +00:00
|
|
|
/*< private >
|
2013-05-09 18:15:51 +00:00
|
|
|
* SECTION:gtkactionmuxer
|
2020-07-19 21:04:11 +00:00
|
|
|
* @short_description: Aggregate and monitor actions from multiple sources
|
2011-11-30 14:33:03 +00:00
|
|
|
*
|
2020-07-19 21:04:11 +00:00
|
|
|
* #GtkActionMuxer is #GtkActionObservable and #GtkActionObserver that
|
|
|
|
* offers a #GActionGroup-like api and is capable of containing other
|
|
|
|
* #GActionGroup instances. #GtkActionMuxer does not implement the
|
|
|
|
* #GActionGroup interface because it requires excessive signal emissions
|
|
|
|
* and has poor scalability. We use the #GtkActionObserver machinery
|
|
|
|
* instead to propagate changes between action muxer instances and
|
|
|
|
* to other users.
|
|
|
|
*
|
|
|
|
* Beyond action groups, #GtkActionMuxer can incorporate actions that
|
|
|
|
* are associated with widget classes (*class actions*) and actions
|
|
|
|
* that are associated with the parent widget, allowing for recursive
|
|
|
|
* lookup.
|
|
|
|
*
|
|
|
|
* In addition to the action attributes provided by #GActionGroup,
|
|
|
|
* #GtkActionMuxer maintains a *primary accelerator* string for
|
|
|
|
* actions that can be shown in menuitems.
|
2011-11-30 14:33:03 +00:00
|
|
|
*
|
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
|
2014-02-07 19:03:49 +00:00
|
|
|
* applicable to an entire application (such as “quit”) and one
|
2011-11-30 14:33:03 +00:00
|
|
|
* containing actions applicable to a particular window in the
|
2014-02-07 19:03:49 +00:00
|
|
|
* application (such as “fullscreen”).
|
2011-11-30 14:33:03 +00:00
|
|
|
*
|
|
|
|
* In this case, each of these action groups could be added to a
|
2020-07-19 21:04:11 +00:00
|
|
|
* #GtkActionMuxer with the prefixes “app” and “win”, respectively.
|
|
|
|
* This would expose the actions as “app.quit” and “win.fullscreen”
|
|
|
|
* on the #GActionGroup-like interface presented by the #GtkActionMuxer.
|
2011-11-30 14:33:03 +00:00
|
|
|
*
|
2020-07-19 21:04:11 +00:00
|
|
|
* Activations and state change requests on the #GtkActionMuxer are
|
|
|
|
* wired through to the underlying actions in the expected way.
|
2011-11-30 14:33:03 +00:00
|
|
|
*
|
2014-02-05 18:07:34 +00:00
|
|
|
* This class is typically only used at the site of “consumption” of
|
2011-11-30 14:33:03 +00:00
|
|
|
* 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_observable_iface_init (GtkActionObservableInterface *iface);
|
2020-07-19 05:17:23 +00:00
|
|
|
static void gtk_action_muxer_observer_iface_init (GtkActionObserverInterface *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;
|
2020-07-19 19:11:35 +00:00
|
|
|
GtkActionMuxer *parent;
|
|
|
|
GtkWidget *widget;
|
2011-11-30 14:33:03 +00:00
|
|
|
|
2012-08-17 17:16:51 +00:00
|
|
|
GHashTable *observed_actions;
|
2011-11-30 14:33:03 +00:00
|
|
|
GHashTable *groups;
|
2020-07-19 19:11:35 +00:00
|
|
|
GtkAccels primary_accels;
|
2020-03-20 16:22:29 +00:00
|
|
|
|
|
|
|
GtkBitmask *widget_actions_disabled;
|
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,
|
2020-07-19 05:17:23 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTION_OBSERVER, gtk_action_muxer_observer_iface_init)
|
2013-05-09 18:15:51 +00:00
|
|
|
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,
|
2019-06-15 23:08:39 +00:00
|
|
|
PROP_WIDGET,
|
2012-08-17 17:16:51 +00:00
|
|
|
NUM_PROPERTIES
|
|
|
|
};
|
|
|
|
|
|
|
|
static GParamSpec *properties[NUM_PROPERTIES];
|
|
|
|
|
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;
|
2020-07-24 18:40:36 +00:00
|
|
|
char *fullname;
|
2011-11-30 14:33:03 +00:00
|
|
|
} Action;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2013-05-09 18:15:51 +00:00
|
|
|
GtkActionMuxer *muxer;
|
2011-11-30 14:33:03 +00:00
|
|
|
GActionGroup *group;
|
2020-07-24 18:40:36 +00:00
|
|
|
char *prefix;
|
2011-11-30 14:33:03 +00:00
|
|
|
gulong handler_ids[4];
|
|
|
|
} Group;
|
|
|
|
|
2020-03-20 16:22:29 +00:00
|
|
|
static inline guint
|
|
|
|
get_action_position (GtkWidgetAction *action)
|
|
|
|
{
|
|
|
|
guint slot;
|
|
|
|
/* We use the length of @action to the end of the chain as the slot so that
|
|
|
|
* we have stable positions for any class or it's subclasses. Doing so helps
|
|
|
|
* us avoid having mutable arrays in the class data as we will not have
|
|
|
|
* access to the ClassPrivate data during instance _init() functions.
|
|
|
|
*/
|
|
|
|
for (slot = 0; action->next != NULL; slot++, action = action->next) {}
|
|
|
|
return slot;
|
|
|
|
}
|
|
|
|
|
2012-08-17 17:16:51 +00:00
|
|
|
static void
|
2019-06-15 22:04:19 +00:00
|
|
|
gtk_action_muxer_append_group_actions (const char *prefix,
|
|
|
|
Group *group,
|
2019-06-14 12:12:10 +00:00
|
|
|
GHashTable *actions)
|
2012-08-17 17:16:51 +00:00
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
char **group_actions;
|
|
|
|
char **action;
|
2012-08-17 17:16:51 +00:00
|
|
|
|
|
|
|
group_actions = g_action_group_list_actions (group->group);
|
|
|
|
for (action = group_actions; *action; action++)
|
|
|
|
{
|
2019-06-14 12:12:10 +00:00
|
|
|
char *name = g_strconcat (prefix, ".", *action, NULL);
|
|
|
|
g_hash_table_add (actions, name);
|
2012-08-17 17:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_strfreev (group_actions);
|
|
|
|
}
|
|
|
|
|
2020-07-19 05:55:13 +00:00
|
|
|
char **
|
2020-10-15 20:18:36 +00:00
|
|
|
gtk_action_muxer_list_actions (GtkActionMuxer *muxer,
|
|
|
|
gboolean local_only)
|
2011-11-30 14:33:03 +00:00
|
|
|
{
|
2019-06-14 12:12:10 +00:00
|
|
|
GHashTable *actions;
|
|
|
|
char **keys;
|
2011-11-30 14:33:03 +00:00
|
|
|
|
2020-07-19 05:55:13 +00:00
|
|
|
actions = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
|
2012-03-30 18:05:46 +00:00
|
|
|
|
2012-08-17 17:16:51 +00:00
|
|
|
for ( ; muxer != NULL; muxer = muxer->parent)
|
|
|
|
{
|
2019-06-15 22:04:19 +00:00
|
|
|
GHashTableIter iter;
|
|
|
|
const char *prefix;
|
|
|
|
Group *group;
|
|
|
|
|
2020-03-20 16:22:29 +00:00
|
|
|
if (muxer->widget)
|
2019-06-14 12:12:10 +00:00
|
|
|
{
|
2020-03-20 16:22:29 +00:00
|
|
|
GtkWidgetClass *klass = GTK_WIDGET_GET_CLASS (muxer->widget);
|
|
|
|
GtkWidgetClassPrivate *priv = klass->priv;
|
|
|
|
GtkWidgetAction *action;
|
2019-06-14 12:12:10 +00:00
|
|
|
|
2020-03-20 16:22:29 +00:00
|
|
|
for (action = priv->actions; action; action = action->next)
|
|
|
|
g_hash_table_add (actions, g_strdup (action->name));
|
2019-06-14 12:12:10 +00:00
|
|
|
}
|
|
|
|
|
2020-07-19 13:45:12 +00:00
|
|
|
if (muxer->groups)
|
|
|
|
{
|
|
|
|
g_hash_table_iter_init (&iter, muxer->groups);
|
|
|
|
while (g_hash_table_iter_next (&iter, (gpointer *)&prefix, (gpointer *)&group))
|
|
|
|
gtk_action_muxer_append_group_actions (prefix, group, actions);
|
|
|
|
}
|
2020-10-15 20:18:36 +00:00
|
|
|
|
|
|
|
if (local_only)
|
|
|
|
break;
|
2012-08-17 17:16:51 +00:00
|
|
|
}
|
2012-03-30 18:05:46 +00:00
|
|
|
|
2019-06-14 12:12:10 +00:00
|
|
|
keys = (char **)g_hash_table_get_keys_as_array (actions, NULL);
|
|
|
|
|
|
|
|
g_hash_table_steal_all (actions);
|
|
|
|
g_hash_table_unref (actions);
|
|
|
|
|
|
|
|
return (char **)keys;
|
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,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *full_name,
|
|
|
|
const char **action_name)
|
2011-11-30 14:33:03 +00:00
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *dot;
|
|
|
|
char *prefix;
|
2019-06-22 22:51:23 +00:00
|
|
|
const char *name;
|
2011-11-30 14:33:03 +00:00
|
|
|
Group *group;
|
|
|
|
|
2020-07-19 13:45:12 +00:00
|
|
|
if (!muxer->groups)
|
|
|
|
return NULL;
|
|
|
|
|
2012-08-17 17:16:51 +00:00
|
|
|
dot = strchr (full_name, '.');
|
2011-11-30 14:33:03 +00:00
|
|
|
|
|
|
|
if (!dot)
|
|
|
|
return NULL;
|
|
|
|
|
2019-06-22 22:51:23 +00:00
|
|
|
name = dot + 1;
|
|
|
|
|
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)
|
2019-06-22 22:51:23 +00:00
|
|
|
*action_name = name;
|
|
|
|
|
|
|
|
if (group &&
|
|
|
|
g_action_group_has_action (group->group, name))
|
|
|
|
return group;
|
2011-11-30 14:33:03 +00:00
|
|
|
|
2019-06-22 22:51:23 +00:00
|
|
|
return NULL;
|
2011-11-30 14:33:03 +00:00
|
|
|
}
|
|
|
|
|
2019-06-14 17:41:45 +00:00
|
|
|
GActionGroup *
|
|
|
|
gtk_action_muxer_find (GtkActionMuxer *muxer,
|
|
|
|
const char *action_name,
|
|
|
|
const char **unprefixed_name)
|
|
|
|
{
|
|
|
|
Group *group;
|
|
|
|
|
|
|
|
group = gtk_action_muxer_find_group (muxer, action_name, unprefixed_name);
|
2019-06-22 22:51:23 +00:00
|
|
|
if (group)
|
|
|
|
return group->group;
|
2019-06-14 17:41:45 +00:00
|
|
|
|
2019-06-22 22:51:23 +00:00
|
|
|
return NULL;
|
2019-06-14 17:41:45 +00:00
|
|
|
}
|
|
|
|
|
2020-12-03 03:41:16 +00:00
|
|
|
GActionGroup *
|
|
|
|
gtk_action_muxer_get_group (GtkActionMuxer *muxer,
|
|
|
|
const char *group_name)
|
|
|
|
{
|
|
|
|
Group *group;
|
|
|
|
|
|
|
|
group = g_hash_table_lookup (muxer->groups, group_name);
|
|
|
|
if (group)
|
|
|
|
return group->group;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-07-19 13:45:12 +00:00
|
|
|
static inline Action *
|
|
|
|
find_observers (GtkActionMuxer *muxer,
|
|
|
|
const char *action_name)
|
|
|
|
{
|
|
|
|
if (muxer->observed_actions)
|
|
|
|
return g_hash_table_lookup (muxer->observed_actions, action_name);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-06-14 12:12:10 +00:00
|
|
|
void
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_action_enabled_changed (GtkActionMuxer *muxer,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *action_name,
|
2013-05-09 18:15:51 +00:00
|
|
|
gboolean enabled)
|
2011-11-30 14:33:03 +00:00
|
|
|
{
|
2020-03-20 16:22:29 +00:00
|
|
|
GtkWidgetAction *iter;
|
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
|
|
|
|
2020-03-20 16:22:29 +00:00
|
|
|
if (muxer->widget)
|
2019-06-14 12:12:10 +00:00
|
|
|
{
|
2020-03-20 16:22:29 +00:00
|
|
|
GtkWidgetClass *klass = GTK_WIDGET_GET_CLASS (muxer->widget);
|
|
|
|
GtkWidgetClassPrivate *priv = klass->priv;
|
|
|
|
|
|
|
|
for (iter = priv->actions; iter; iter = iter->next)
|
2019-06-14 12:12:10 +00:00
|
|
|
{
|
2020-03-20 16:22:29 +00:00
|
|
|
if (strcmp (action_name, iter->name) == 0)
|
2019-06-14 12:12:10 +00:00
|
|
|
{
|
2020-03-20 16:22:29 +00:00
|
|
|
guint position = get_action_position (iter);
|
|
|
|
muxer->widget_actions_disabled =
|
|
|
|
_gtk_bitmask_set (muxer->widget_actions_disabled, position, !enabled);
|
2019-06-14 12:12:10 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-03-20 16:22:29 +00:00
|
|
|
|
2020-07-19 13:45:12 +00:00
|
|
|
action = find_observers (muxer, action_name);
|
|
|
|
|
2012-08-17 17:16:51 +00:00
|
|
|
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);
|
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,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *action_name,
|
2013-05-09 18:15:51 +00:00
|
|
|
gboolean enabled,
|
|
|
|
gpointer user_data)
|
2011-11-30 14:33:03 +00:00
|
|
|
{
|
|
|
|
Group *group = user_data;
|
2020-07-24 18:40:36 +00:00
|
|
|
char *fullname;
|
2011-11-30 14:33:03 +00:00
|
|
|
|
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);
|
2011-11-30 14:33:03 +00:00
|
|
|
g_free (fullname);
|
|
|
|
}
|
|
|
|
|
2019-06-14 12:12:10 +00:00
|
|
|
void
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_action_state_changed (GtkActionMuxer *muxer,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *action_name,
|
2013-05-09 18:15:51 +00:00
|
|
|
GVariant *state)
|
2011-11-30 14:33:03 +00:00
|
|
|
{
|
|
|
|
Action *action;
|
|
|
|
GSList *node;
|
|
|
|
|
2020-07-19 13:45:12 +00:00
|
|
|
action = find_observers (muxer, 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
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-05-09 18:15:51 +00:00
|
|
|
gtk_action_muxer_group_action_state_changed (GActionGroup *action_group,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *action_name,
|
2013-05-09 18:15:51 +00:00
|
|
|
GVariant *state,
|
|
|
|
gpointer user_data)
|
2012-08-17 17:16:51 +00:00
|
|
|
{
|
|
|
|
Group *group = user_data;
|
2020-07-24 18:40:36 +00:00
|
|
|
char *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_state_changed (group->muxer, fullname, state);
|
2011-11-30 14:33:03 +00:00
|
|
|
g_free (fullname);
|
|
|
|
}
|
|
|
|
|
2020-07-19 05:17:23 +00:00
|
|
|
static gboolean action_muxer_query_action (GtkActionMuxer *muxer,
|
|
|
|
const char *action_name,
|
|
|
|
gboolean *enabled,
|
|
|
|
const GVariantType **parameter_type,
|
|
|
|
const GVariantType **state_type,
|
|
|
|
GVariant **state_hint,
|
|
|
|
GVariant **state,
|
|
|
|
gboolean recurse);
|
2012-08-17 17:16:51 +00:00
|
|
|
|
2020-04-24 04:52:17 +00:00
|
|
|
static void
|
|
|
|
notify_observers_added (GtkActionMuxer *muxer,
|
|
|
|
GtkActionMuxer *parent)
|
|
|
|
{
|
|
|
|
GHashTableIter iter;
|
|
|
|
const char *action_name;
|
|
|
|
Action *action;
|
|
|
|
|
2020-07-19 13:45:12 +00:00
|
|
|
if (!muxer->observed_actions)
|
|
|
|
return;
|
|
|
|
|
2020-04-24 04:52:17 +00:00
|
|
|
g_hash_table_iter_init (&iter, muxer->observed_actions);
|
|
|
|
while (g_hash_table_iter_next (&iter, (gpointer *)&action_name, (gpointer *)&action))
|
|
|
|
{
|
|
|
|
const GVariantType *parameter_type;
|
|
|
|
gboolean enabled;
|
|
|
|
GVariant *state;
|
|
|
|
GSList *node;
|
|
|
|
|
|
|
|
if (!action->watchers)
|
|
|
|
continue;
|
|
|
|
|
2020-07-19 05:17:23 +00:00
|
|
|
if (action_muxer_query_action (muxer, action_name,
|
|
|
|
NULL, NULL, NULL, NULL, NULL,
|
|
|
|
FALSE))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
gtk_action_observable_register_observer (GTK_ACTION_OBSERVABLE (parent), action_name, GTK_ACTION_OBSERVER (muxer));
|
|
|
|
|
|
|
|
if (!action_muxer_query_action (parent, action_name,
|
|
|
|
&enabled, ¶meter_type,
|
|
|
|
NULL, NULL, &state,
|
|
|
|
TRUE))
|
2020-04-24 04:52:17 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
for (node = action->watchers; node; node = node->next)
|
2020-07-19 02:28:53 +00:00
|
|
|
{
|
|
|
|
gtk_action_observer_action_added (node->data,
|
|
|
|
GTK_ACTION_OBSERVABLE (muxer),
|
|
|
|
action_name, parameter_type, enabled, state);
|
|
|
|
}
|
2020-04-24 04:52:17 +00:00
|
|
|
|
|
|
|
if (state)
|
|
|
|
g_variant_unref (state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
notify_observers_removed (GtkActionMuxer *muxer,
|
|
|
|
GtkActionMuxer *parent)
|
|
|
|
{
|
|
|
|
GHashTableIter iter;
|
|
|
|
const char *action_name;
|
|
|
|
Action *action;
|
|
|
|
|
2020-07-19 13:45:12 +00:00
|
|
|
if (!muxer->observed_actions)
|
|
|
|
return;
|
|
|
|
|
2020-04-24 04:52:17 +00:00
|
|
|
g_hash_table_iter_init (&iter, muxer->observed_actions);
|
2020-04-24 05:11:13 +00:00
|
|
|
while (g_hash_table_iter_next (&iter, (gpointer *)&action_name, (gpointer *)&action))
|
2020-04-24 04:52:17 +00:00
|
|
|
{
|
|
|
|
GSList *node;
|
|
|
|
|
2020-07-19 05:17:23 +00:00
|
|
|
gtk_action_observable_unregister_observer (GTK_ACTION_OBSERVABLE (parent), action_name, GTK_ACTION_OBSERVER (muxer));
|
|
|
|
|
2020-04-24 04:52:17 +00:00
|
|
|
for (node = action->watchers; node; node = node->next)
|
2020-07-19 02:28:53 +00:00
|
|
|
{
|
|
|
|
gtk_action_observer_action_removed (node->data,
|
|
|
|
GTK_ACTION_OBSERVABLE (muxer),
|
|
|
|
action_name);
|
|
|
|
}
|
2020-04-24 04:52:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-07-19 05:17:23 +00:00
|
|
|
gtk_action_muxer_action_added (GtkActionMuxer *muxer,
|
|
|
|
const char *action_name,
|
|
|
|
const GVariantType *parameter_type,
|
|
|
|
gboolean enabled,
|
|
|
|
GVariant *state)
|
2020-04-24 04:52:17 +00:00
|
|
|
{
|
2020-07-19 05:17:23 +00:00
|
|
|
Action *action;
|
|
|
|
GSList *node;
|
2020-04-24 04:52:17 +00:00
|
|
|
|
2020-07-19 13:45:12 +00:00
|
|
|
action = find_observers (muxer, action_name);
|
2020-07-19 05:17:23 +00:00
|
|
|
for (node = action ? action->watchers : NULL; node; node = node->next)
|
|
|
|
gtk_action_observer_action_added (node->data,
|
|
|
|
GTK_ACTION_OBSERVABLE (muxer),
|
|
|
|
action_name, parameter_type, enabled, state);
|
2020-04-24 04:52:17 +00:00
|
|
|
}
|
|
|
|
|
2012-08-17 17:16:51 +00:00
|
|
|
static void
|
2020-07-19 05:17:23 +00:00
|
|
|
gtk_action_muxer_action_added_to_group (GActionGroup *action_group,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *action_name,
|
2020-07-19 05:17:23 +00:00
|
|
|
gpointer user_data)
|
2011-11-30 14:33:03 +00:00
|
|
|
{
|
2020-07-19 05:17:23 +00:00
|
|
|
Group *group = user_data;
|
|
|
|
GtkActionMuxer *muxer = group->muxer;
|
|
|
|
Action *action;
|
2011-11-30 14:33:03 +00:00
|
|
|
const GVariantType *parameter_type;
|
|
|
|
gboolean enabled;
|
|
|
|
GVariant *state;
|
2020-07-19 05:17:23 +00:00
|
|
|
char *fullname;
|
2011-11-30 14:33:03 +00:00
|
|
|
|
2020-07-19 05:17:23 +00:00
|
|
|
fullname = g_strconcat (group->prefix, ".", action_name, NULL);
|
2020-07-19 13:45:12 +00:00
|
|
|
|
|
|
|
if (muxer->parent)
|
|
|
|
gtk_action_observable_unregister_observer (GTK_ACTION_OBSERVABLE (muxer->parent),
|
|
|
|
fullname,
|
|
|
|
GTK_ACTION_OBSERVER (muxer));
|
|
|
|
|
|
|
|
action = find_observers (muxer, fullname);
|
2012-08-17 17:16:51 +00:00
|
|
|
|
|
|
|
if (action && action->watchers &&
|
2020-07-19 05:17:23 +00:00
|
|
|
g_action_group_query_action (action_group, action_name,
|
2012-08-17 17:16:51 +00:00
|
|
|
&enabled, ¶meter_type, NULL, NULL, &state))
|
2011-11-30 14:33:03 +00:00
|
|
|
{
|
2020-07-19 05:17:23 +00:00
|
|
|
gtk_action_muxer_action_added (muxer, fullname, 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
|
|
|
|
2020-07-19 05:17:23 +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 (GtkActionMuxer *muxer,
|
2020-07-19 05:17:23 +00:00
|
|
|
const char *action_name)
|
2012-08-17 17:16:51 +00:00
|
|
|
{
|
2011-11-30 14:33:03 +00:00
|
|
|
Action *action;
|
|
|
|
GSList *node;
|
|
|
|
|
2020-07-19 13:45:12 +00:00
|
|
|
action = find_observers (muxer, action_name);
|
2011-11-30 14:33:03 +00:00
|
|
|
for (node = action ? action->watchers : NULL; node; node = node->next)
|
2020-07-19 05:17:23 +00:00
|
|
|
gtk_action_observer_action_removed (node->data, GTK_ACTION_OBSERVABLE (muxer), 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_from_group (GActionGroup *action_group,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *action_name,
|
2013-05-09 18:15:51 +00:00
|
|
|
gpointer user_data)
|
2012-08-17 17:16:51 +00:00
|
|
|
{
|
|
|
|
Group *group = user_data;
|
2020-07-19 05:17:23 +00:00
|
|
|
GtkActionMuxer *muxer = group->muxer;
|
|
|
|
char *fullname;
|
|
|
|
Action *action;
|
2012-08-17 17:16:51 +00:00
|
|
|
|
2020-07-19 05:17:23 +00:00
|
|
|
fullname = g_strconcat (group->prefix, ".", action_name, NULL);
|
|
|
|
gtk_action_muxer_action_removed (muxer, fullname);
|
|
|
|
g_free (fullname);
|
2011-11-30 14:33:03 +00:00
|
|
|
|
2020-07-19 13:45:12 +00:00
|
|
|
action = find_observers (muxer, action_name);
|
2012-08-17 17:16:51 +00:00
|
|
|
|
2020-07-19 05:17:23 +00:00
|
|
|
if (action && action->watchers &&
|
|
|
|
!action_muxer_query_action (muxer, action_name,
|
|
|
|
NULL, NULL, NULL, NULL, NULL, FALSE))
|
|
|
|
{
|
|
|
|
if (muxer->parent)
|
|
|
|
gtk_action_observable_register_observer (GTK_ACTION_OBSERVABLE (muxer->parent),
|
|
|
|
action_name,
|
|
|
|
GTK_ACTION_OBSERVER (muxer));
|
|
|
|
}
|
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,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *action_name,
|
|
|
|
const char *action_and_target)
|
2013-07-10 02:37:17 +00:00
|
|
|
{
|
|
|
|
Action *action;
|
|
|
|
GSList *node;
|
|
|
|
|
|
|
|
if (!action_name)
|
|
|
|
action_name = strrchr (action_and_target, '|') + 1;
|
|
|
|
|
2020-07-19 13:45:12 +00:00
|
|
|
action = find_observers (muxer, action_name);
|
2013-07-10 02:37:17 +00:00
|
|
|
for (node = action ? action->watchers : NULL; node; node = node->next)
|
2020-07-19 05:17:23 +00:00
|
|
|
gtk_action_observer_primary_accel_changed (node->data, GTK_ACTION_OBSERVABLE (muxer),
|
|
|
|
action_name, action_and_target);
|
2013-07-10 02:37:17 +00:00
|
|
|
}
|
|
|
|
|
2019-06-22 20:18:05 +00:00
|
|
|
static GVariant *
|
|
|
|
prop_action_get_state (GtkWidget *widget,
|
|
|
|
GtkWidgetAction *action)
|
|
|
|
{
|
|
|
|
GValue value = G_VALUE_INIT;
|
|
|
|
GVariant *result;
|
|
|
|
|
|
|
|
g_value_init (&value, action->pspec->value_type);
|
|
|
|
g_object_get_property (G_OBJECT (widget), action->pspec->name, &value);
|
|
|
|
|
|
|
|
result = g_settings_set_mapping (&value, action->state_type, NULL);
|
|
|
|
g_value_unset (&value);
|
|
|
|
|
|
|
|
return g_variant_ref_sink (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GVariant *
|
|
|
|
prop_action_get_state_hint (GtkWidget *widget,
|
|
|
|
GtkWidgetAction *action)
|
|
|
|
{
|
|
|
|
if (action->pspec->value_type == G_TYPE_INT)
|
|
|
|
{
|
|
|
|
GParamSpecInt *pspec = (GParamSpecInt *)action->pspec;
|
|
|
|
return g_variant_new ("(ii)", pspec->minimum, pspec->maximum);
|
|
|
|
}
|
|
|
|
else if (action->pspec->value_type == G_TYPE_UINT)
|
|
|
|
{
|
|
|
|
GParamSpecUInt *pspec = (GParamSpecUInt *)action->pspec;
|
|
|
|
return g_variant_new ("(uu)", pspec->minimum, pspec->maximum);
|
|
|
|
}
|
|
|
|
else if (action->pspec->value_type == G_TYPE_FLOAT)
|
|
|
|
{
|
|
|
|
GParamSpecFloat *pspec = (GParamSpecFloat *)action->pspec;
|
|
|
|
return g_variant_new ("(dd)", (double)pspec->minimum, (double)pspec->maximum);
|
|
|
|
}
|
|
|
|
else if (action->pspec->value_type == G_TYPE_DOUBLE)
|
|
|
|
{
|
|
|
|
GParamSpecDouble *pspec = (GParamSpecDouble *)action->pspec;
|
|
|
|
return g_variant_new ("(dd)", pspec->minimum, pspec->maximum);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
prop_action_set_state (GtkWidget *widget,
|
|
|
|
GtkWidgetAction *action,
|
|
|
|
GVariant *state)
|
|
|
|
{
|
|
|
|
GValue value = G_VALUE_INIT;
|
|
|
|
|
|
|
|
g_value_init (&value, action->pspec->value_type);
|
|
|
|
g_settings_get_mapping (&value, state, NULL);
|
|
|
|
|
|
|
|
g_object_set_property (G_OBJECT (widget), action->pspec->name, &value);
|
|
|
|
g_value_unset (&value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
prop_action_activate (GtkWidget *widget,
|
|
|
|
GtkWidgetAction *action,
|
|
|
|
GVariant *parameter)
|
|
|
|
{
|
|
|
|
if (action->pspec->value_type == G_TYPE_BOOLEAN)
|
|
|
|
{
|
|
|
|
gboolean value;
|
|
|
|
|
|
|
|
g_return_if_fail (parameter == NULL);
|
|
|
|
|
|
|
|
g_object_get (G_OBJECT (widget), action->pspec->name, &value, NULL);
|
|
|
|
value = !value;
|
|
|
|
g_object_set (G_OBJECT (widget), action->pspec->name, value, NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_return_if_fail (parameter != NULL && g_variant_is_of_type (parameter, action->state_type));
|
|
|
|
|
|
|
|
prop_action_set_state (widget, action, parameter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
prop_action_notify (GObject *object,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2020-04-29 00:22:26 +00:00
|
|
|
GtkWidget *widget = GTK_WIDGET (object);
|
|
|
|
GtkWidgetAction *action = user_data;
|
|
|
|
GtkActionMuxer *muxer = _gtk_widget_get_action_muxer (widget, TRUE);
|
2019-06-22 20:18:05 +00:00
|
|
|
GVariant *state;
|
|
|
|
|
2020-04-29 00:22:26 +00:00
|
|
|
g_assert (muxer->widget == widget);
|
2020-03-20 16:22:29 +00:00
|
|
|
g_assert (action->pspec == pspec);
|
2019-06-22 20:18:05 +00:00
|
|
|
|
2020-04-29 00:22:26 +00:00
|
|
|
state = prop_action_get_state (widget, action);
|
2019-06-22 20:18:05 +00:00
|
|
|
gtk_action_muxer_action_state_changed (muxer, action->name, state);
|
|
|
|
g_variant_unref (state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
prop_actions_connect (GtkActionMuxer *muxer)
|
|
|
|
{
|
2020-03-20 16:22:29 +00:00
|
|
|
GtkWidgetClassPrivate *priv;
|
|
|
|
GtkWidgetAction *action;
|
|
|
|
GtkWidgetClass *klass;
|
2020-04-29 00:22:26 +00:00
|
|
|
guint signal_id;
|
2020-03-20 16:22:29 +00:00
|
|
|
|
|
|
|
if (!muxer->widget)
|
|
|
|
return;
|
2019-06-22 20:18:05 +00:00
|
|
|
|
2020-03-20 16:22:29 +00:00
|
|
|
klass = GTK_WIDGET_GET_CLASS (muxer->widget);
|
|
|
|
priv = klass->priv;
|
|
|
|
if (!priv->actions)
|
2019-06-22 20:18:05 +00:00
|
|
|
return;
|
|
|
|
|
2020-04-29 00:22:26 +00:00
|
|
|
signal_id = g_signal_lookup ("notify", G_TYPE_OBJECT);
|
|
|
|
|
2020-03-20 16:22:29 +00:00
|
|
|
for (action = priv->actions; action; action = action->next)
|
2019-06-22 20:18:05 +00:00
|
|
|
{
|
|
|
|
if (!action->pspec)
|
|
|
|
continue;
|
|
|
|
|
2020-04-29 00:22:26 +00:00
|
|
|
g_signal_connect_closure_by_id (muxer->widget,
|
|
|
|
signal_id,
|
|
|
|
g_param_spec_get_name_quark (action->pspec),
|
|
|
|
g_cclosure_new (G_CALLBACK (prop_action_notify),
|
|
|
|
action,
|
|
|
|
NULL),
|
|
|
|
FALSE);
|
2019-06-22 20:18:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-19 05:17:23 +00:00
|
|
|
static gboolean
|
|
|
|
action_muxer_query_action (GtkActionMuxer *muxer,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *action_name,
|
2020-07-19 05:17:23 +00:00
|
|
|
gboolean *enabled,
|
|
|
|
const GVariantType **parameter_type,
|
|
|
|
const GVariantType **state_type,
|
|
|
|
GVariant **state_hint,
|
|
|
|
GVariant **state,
|
|
|
|
gboolean recurse)
|
2013-05-09 18:15:51 +00:00
|
|
|
{
|
2020-03-20 16:22:29 +00:00
|
|
|
GtkWidgetAction *action;
|
2011-11-30 14:33:03 +00:00
|
|
|
Group *group;
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *unprefixed_name;
|
2011-11-30 14:33:03 +00:00
|
|
|
|
2020-03-20 16:22:29 +00:00
|
|
|
if (muxer->widget)
|
2019-06-14 12:12:10 +00:00
|
|
|
{
|
2020-03-20 16:22:29 +00:00
|
|
|
GtkWidgetClass *klass = GTK_WIDGET_GET_CLASS (muxer->widget);
|
|
|
|
GtkWidgetClassPrivate *priv = klass->priv;
|
2019-06-14 12:12:10 +00:00
|
|
|
|
2020-03-20 16:22:29 +00:00
|
|
|
for (action = priv->actions; action; action = action->next)
|
2019-06-14 12:12:10 +00:00
|
|
|
{
|
2020-03-20 16:22:29 +00:00
|
|
|
guint position;
|
2019-06-14 12:12:10 +00:00
|
|
|
|
2020-03-20 16:22:29 +00:00
|
|
|
if (strcmp (action->name, action_name) != 0)
|
|
|
|
continue;
|
2019-06-14 12:12:10 +00:00
|
|
|
|
2020-03-20 16:22:29 +00:00
|
|
|
position = get_action_position (action);
|
|
|
|
|
|
|
|
if (enabled)
|
|
|
|
*enabled = !_gtk_bitmask_get (muxer->widget_actions_disabled, position);
|
|
|
|
if (parameter_type)
|
|
|
|
*parameter_type = action->parameter_type;
|
|
|
|
if (state_type)
|
|
|
|
*state_type = action->state_type;
|
|
|
|
|
|
|
|
if (state_hint)
|
|
|
|
*state_hint = NULL;
|
|
|
|
if (state)
|
|
|
|
*state = NULL;
|
2019-06-14 12:12:10 +00:00
|
|
|
|
2020-03-20 16:22:29 +00:00
|
|
|
if (action->pspec)
|
|
|
|
{
|
|
|
|
if (state)
|
|
|
|
*state = prop_action_get_state (muxer->widget, action);
|
|
|
|
if (state_hint)
|
|
|
|
*state_hint = prop_action_get_state_hint (muxer->widget, action);
|
2019-06-14 12:12:10 +00:00
|
|
|
}
|
2020-03-20 16:22:29 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2019-06-14 12:12:10 +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
|
|
|
|
2020-07-19 05:17:23 +00:00
|
|
|
if (muxer->parent && recurse)
|
|
|
|
return gtk_action_muxer_query_action (muxer->parent, action_name,
|
|
|
|
enabled, parameter_type,
|
|
|
|
state_type, state_hint, state);
|
2012-08-17 17:16:51 +00:00
|
|
|
|
|
|
|
return FALSE;
|
2011-11-30 14:33:03 +00:00
|
|
|
}
|
|
|
|
|
2020-07-19 05:17:23 +00:00
|
|
|
gboolean
|
|
|
|
gtk_action_muxer_query_action (GtkActionMuxer *muxer,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *action_name,
|
2020-07-19 05:17:23 +00:00
|
|
|
gboolean *enabled,
|
|
|
|
const GVariantType **parameter_type,
|
|
|
|
const GVariantType **state_type,
|
|
|
|
GVariant **state_hint,
|
|
|
|
GVariant **state)
|
|
|
|
{
|
|
|
|
return action_muxer_query_action (muxer, action_name,
|
|
|
|
enabled, parameter_type,
|
|
|
|
state_type, state_hint, state,
|
|
|
|
TRUE);
|
|
|
|
}
|
|
|
|
|
2020-07-19 02:28:53 +00:00
|
|
|
gboolean
|
|
|
|
gtk_action_muxer_has_action (GtkActionMuxer *muxer,
|
|
|
|
const char *action_name)
|
|
|
|
{
|
2020-07-19 05:17:23 +00:00
|
|
|
return action_muxer_query_action (muxer, action_name,
|
|
|
|
NULL, NULL, NULL, NULL, NULL,
|
|
|
|
TRUE);
|
2020-07-19 02:28:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_action_muxer_activate_action (GtkActionMuxer *muxer,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *action_name,
|
2020-07-19 02:28:53 +00:00
|
|
|
GVariant *parameter)
|
2011-11-30 14:33:03 +00:00
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *unprefixed_name;
|
2020-03-20 16:22:29 +00:00
|
|
|
Group *group;
|
2011-11-30 14:33:03 +00:00
|
|
|
|
2020-03-20 16:22:29 +00:00
|
|
|
if (muxer->widget)
|
2019-06-14 12:12:10 +00:00
|
|
|
{
|
2020-03-20 16:22:29 +00:00
|
|
|
GtkWidgetClass *klass = GTK_WIDGET_GET_CLASS (muxer->widget);
|
|
|
|
GtkWidgetClassPrivate *priv = klass->priv;
|
|
|
|
GtkWidgetAction *action;
|
2019-06-14 12:12:10 +00:00
|
|
|
|
2020-03-20 16:22:29 +00:00
|
|
|
for (action = priv->actions; action; action = action->next)
|
2019-06-14 12:12:10 +00:00
|
|
|
{
|
|
|
|
if (strcmp (action->name, action_name) == 0)
|
|
|
|
{
|
2020-03-20 16:22:29 +00:00
|
|
|
guint position = get_action_position (action);
|
|
|
|
|
|
|
|
if (!_gtk_bitmask_get (muxer->widget_actions_disabled, position))
|
2019-06-23 01:19:19 +00:00
|
|
|
{
|
|
|
|
if (action->activate)
|
|
|
|
action->activate (muxer->widget, action->name, parameter);
|
|
|
|
else if (action->pspec)
|
|
|
|
prop_action_activate (muxer->widget, action, parameter);
|
|
|
|
}
|
2019-06-14 12:12:10 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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)
|
2020-07-19 05:17:23 +00:00
|
|
|
gtk_action_muxer_activate_action (muxer->parent, action_name, parameter);
|
2011-11-30 14:33:03 +00:00
|
|
|
}
|
|
|
|
|
2020-07-19 02:28:53 +00:00
|
|
|
void
|
|
|
|
gtk_action_muxer_change_action_state (GtkActionMuxer *muxer,
|
2020-07-19 05:17:23 +00:00
|
|
|
const char *action_name,
|
2020-07-19 02:28:53 +00:00
|
|
|
GVariant *state)
|
2011-11-30 14:33:03 +00:00
|
|
|
{
|
2020-03-20 16:22:29 +00:00
|
|
|
GtkWidgetAction *action;
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *unprefixed_name;
|
2020-03-20 16:22:29 +00:00
|
|
|
Group *group;
|
2011-11-30 14:33:03 +00:00
|
|
|
|
2020-03-20 16:22:29 +00:00
|
|
|
if (muxer->widget)
|
2019-06-14 12:12:10 +00:00
|
|
|
{
|
2020-03-20 16:22:29 +00:00
|
|
|
GtkWidgetClass *klass = GTK_WIDGET_GET_CLASS (muxer->widget);
|
|
|
|
GtkWidgetClassPrivate *priv = klass->priv;
|
2019-06-14 12:12:10 +00:00
|
|
|
|
2020-03-20 16:22:29 +00:00
|
|
|
for (action = priv->actions; action; action = action->next)
|
2019-06-14 12:12:10 +00:00
|
|
|
{
|
|
|
|
if (strcmp (action->name, action_name) == 0)
|
|
|
|
{
|
2019-06-22 20:18:05 +00:00
|
|
|
if (action->pspec)
|
|
|
|
prop_action_set_state (muxer->widget, action, state);
|
2019-06-14 12:12:10 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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)
|
2020-07-19 05:17:23 +00:00
|
|
|
gtk_action_muxer_change_action_state (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)
|
2020-07-19 05:17:23 +00:00
|
|
|
{
|
|
|
|
if (muxer->parent)
|
|
|
|
gtk_action_observable_unregister_observer (GTK_ACTION_OBSERVABLE (muxer->parent),
|
|
|
|
action->fullname,
|
|
|
|
GTK_ACTION_OBSERVER (muxer));
|
2012-08-17 17:16:51 +00:00
|
|
|
g_hash_table_remove (muxer->observed_actions, action->fullname);
|
2020-07-19 05:17:23 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2020-07-19 13:45:12 +00:00
|
|
|
static void gtk_action_muxer_free_action (gpointer data);
|
|
|
|
|
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,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *name,
|
2013-05-09 18:15:51 +00:00
|
|
|
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;
|
2020-07-19 05:17:23 +00:00
|
|
|
gboolean enabled;
|
|
|
|
const GVariantType *parameter_type;
|
|
|
|
GVariant *state;
|
2011-11-30 14:33:03 +00:00
|
|
|
|
2020-07-19 13:45:12 +00:00
|
|
|
if (!muxer->observed_actions)
|
|
|
|
muxer->observed_actions = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, gtk_action_muxer_free_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);
|
2020-07-19 05:17:23 +00:00
|
|
|
|
|
|
|
if (action_muxer_query_action (muxer, name,
|
|
|
|
&enabled, ¶meter_type,
|
|
|
|
NULL, NULL, &state, FALSE))
|
|
|
|
{
|
|
|
|
gtk_action_muxer_action_added (muxer, name, parameter_type, enabled, state);
|
|
|
|
g_clear_pointer (&state, g_variant_unref);
|
|
|
|
}
|
|
|
|
else if (muxer->parent)
|
|
|
|
{
|
|
|
|
if (action_muxer_query_action (muxer->parent, name,
|
|
|
|
&enabled, ¶meter_type,
|
|
|
|
NULL, NULL, &state, FALSE))
|
|
|
|
{
|
|
|
|
gtk_action_muxer_action_added (muxer, name, parameter_type, enabled, state);
|
|
|
|
g_clear_pointer (&state, g_variant_unref);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_action_observable_register_observer (GTK_ACTION_OBSERVABLE (muxer->parent),
|
|
|
|
name,
|
|
|
|
GTK_ACTION_OBSERVER (muxer));
|
|
|
|
}
|
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,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *name,
|
2013-05-09 18:15:51 +00:00
|
|
|
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;
|
|
|
|
|
2020-07-19 13:45:12 +00:00
|
|
|
action = find_observers (muxer, name);
|
|
|
|
if (action)
|
|
|
|
{
|
|
|
|
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;
|
2020-07-24 13:54:49 +00:00
|
|
|
int i;
|
2012-06-29 03:55:33 +00:00
|
|
|
|
|
|
|
/* '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
|
|
|
|
2020-07-19 13:45:12 +00:00
|
|
|
if (muxer->observed_actions)
|
|
|
|
{
|
|
|
|
g_assert_cmpint (g_hash_table_size (muxer->observed_actions), ==, 0);
|
|
|
|
g_hash_table_unref (muxer->observed_actions);
|
|
|
|
}
|
|
|
|
if (muxer->groups)
|
|
|
|
g_hash_table_unref (muxer->groups);
|
2020-07-19 19:11:35 +00:00
|
|
|
|
|
|
|
gtk_accels_clear (&muxer->primary_accels);
|
2011-11-30 14:33:03 +00:00
|
|
|
|
2020-03-20 16:22:29 +00:00
|
|
|
_gtk_bitmask_free (muxer->widget_actions_disabled);
|
2019-07-06 05:13:41 +00:00
|
|
|
|
2020-03-20 16:22:29 +00:00
|
|
|
G_OBJECT_CLASS (gtk_action_muxer_parent_class)->finalize (object);
|
2011-11-30 14:33:03 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2020-07-19 05:17:23 +00:00
|
|
|
g_clear_object (&muxer->parent);
|
2020-07-19 13:45:12 +00:00
|
|
|
if (muxer->observed_actions)
|
|
|
|
g_hash_table_remove_all (muxer->observed_actions);
|
2012-08-17 17:16:51 +00:00
|
|
|
|
2020-03-25 21:02:59 +00:00
|
|
|
muxer->widget = NULL;
|
|
|
|
|
2020-07-19 05:17:23 +00:00
|
|
|
G_OBJECT_CLASS (gtk_action_muxer_parent_class)->dispose (object);
|
2012-08-17 17:16:51 +00:00
|
|
|
}
|
|
|
|
|
2020-04-28 22:34:23 +00:00
|
|
|
void
|
|
|
|
gtk_action_muxer_connect_class_actions (GtkActionMuxer *muxer)
|
2019-06-22 20:18:05 +00:00
|
|
|
{
|
|
|
|
prop_actions_connect (muxer);
|
|
|
|
}
|
|
|
|
|
2012-08-17 17:16:51 +00:00
|
|
|
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;
|
|
|
|
|
2019-06-15 23:08:39 +00:00
|
|
|
case PROP_WIDGET:
|
|
|
|
g_value_set_object (value, muxer->widget);
|
|
|
|
break;
|
|
|
|
|
2012-08-17 17:16:51 +00:00
|
|
|
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;
|
|
|
|
|
2019-06-15 23:08:39 +00:00
|
|
|
case PROP_WIDGET:
|
|
|
|
muxer->widget = g_value_get_object (value);
|
|
|
|
break;
|
|
|
|
|
2012-08-17 17:16:51 +00:00
|
|
|
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
|
|
|
{
|
2020-03-20 16:22:29 +00:00
|
|
|
muxer->widget_actions_disabled = _gtk_bitmask_new ();
|
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
|
|
|
}
|
|
|
|
|
2020-07-19 05:17:23 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_action_muxer_observer_action_added (GtkActionObserver *observer,
|
|
|
|
GtkActionObservable *observable,
|
|
|
|
const char *action_name,
|
|
|
|
const GVariantType *parameter_type,
|
|
|
|
gboolean enabled,
|
|
|
|
GVariant *state)
|
2020-07-19 02:28:53 +00:00
|
|
|
{
|
2020-07-19 05:17:23 +00:00
|
|
|
gtk_action_muxer_action_added (GTK_ACTION_MUXER (observer),
|
|
|
|
action_name,
|
|
|
|
parameter_type,
|
|
|
|
enabled,
|
|
|
|
state);
|
2020-07-19 02:28:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-07-19 05:17:23 +00:00
|
|
|
gtk_action_muxer_observer_action_removed (GtkActionObserver *observer,
|
|
|
|
GtkActionObservable *observable,
|
|
|
|
const char *action_name)
|
2020-07-19 02:28:53 +00:00
|
|
|
{
|
2020-07-19 05:17:23 +00:00
|
|
|
gtk_action_muxer_action_removed (GTK_ACTION_MUXER (observer), action_name);
|
2020-07-19 02:28:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-07-19 05:17:23 +00:00
|
|
|
gtk_action_muxer_observer_action_enabled_changed (GtkActionObserver *observer,
|
|
|
|
GtkActionObservable *observable,
|
|
|
|
const char *action_name,
|
|
|
|
gboolean enabled)
|
2020-07-19 02:28:53 +00:00
|
|
|
{
|
2020-07-19 05:17:23 +00:00
|
|
|
gtk_action_muxer_action_enabled_changed (GTK_ACTION_MUXER (observer), action_name, enabled);
|
2020-07-19 02:28:53 +00:00
|
|
|
}
|
|
|
|
|
2011-11-30 14:33:03 +00:00
|
|
|
static void
|
2020-07-19 05:17:23 +00:00
|
|
|
gtk_action_muxer_observer_action_state_changed (GtkActionObserver *observer,
|
|
|
|
GtkActionObservable *observable,
|
|
|
|
const char *action_name,
|
|
|
|
GVariant *state)
|
2011-11-30 14:33:03 +00:00
|
|
|
{
|
2020-07-19 05:17:23 +00:00
|
|
|
gtk_action_muxer_action_state_changed (GTK_ACTION_MUXER (observer), action_name, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_action_muxer_observer_primary_accel_changed (GtkActionObserver *observer,
|
|
|
|
GtkActionObservable *observable,
|
|
|
|
const char *action_name,
|
|
|
|
const char *action_and_target)
|
|
|
|
{
|
|
|
|
gtk_action_muxer_primary_accel_changed (GTK_ACTION_MUXER (observer),
|
|
|
|
action_name,
|
|
|
|
action_and_target);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_action_muxer_observer_iface_init (GtkActionObserverInterface *iface)
|
|
|
|
{
|
|
|
|
iface->action_added = gtk_action_muxer_observer_action_added;
|
|
|
|
iface->action_removed = gtk_action_muxer_observer_action_removed;
|
|
|
|
iface->action_enabled_changed = gtk_action_muxer_observer_action_enabled_changed;
|
|
|
|
iface->action_state_changed = gtk_action_muxer_observer_action_state_changed;
|
|
|
|
iface->primary_accel_changed = gtk_action_muxer_observer_primary_accel_changed;
|
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
|
|
|
|
|
|
|
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);
|
|
|
|
|
2019-06-15 23:08:39 +00:00
|
|
|
properties[PROP_WIDGET] = g_param_spec_object ("widget", "Widget",
|
|
|
|
"The widget that owns the muxer",
|
|
|
|
GTK_TYPE_WIDGET,
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
G_PARAM_CONSTRUCT_ONLY |
|
|
|
|
G_PARAM_STATIC_STRINGS);
|
|
|
|
|
2012-08-17 17:16:51 +00:00
|
|
|
g_object_class_install_properties (class, NUM_PROPERTIES, properties);
|
2011-11-30 14:33:03 +00:00
|
|
|
}
|
|
|
|
|
2014-01-22 02:47:34 +00:00
|
|
|
/*< private >
|
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
|
2014-02-04 23:32:42 +00:00
|
|
|
* action `x` in @action_group, there is an equivalent
|
|
|
|
* action @prefix`.x` in @muxer.
|
2011-11-30 14:33:03 +00:00
|
|
|
*
|
2014-02-05 18:07:34 +00:00
|
|
|
* For example, if @prefix is “`app`” and @action_group
|
|
|
|
* contains an action called “`quit`”, then @muxer will
|
|
|
|
* now contain an action called “`app.quit`”.
|
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,
|
2014-02-05 18:07:34 +00:00
|
|
|
* “action_added” notifications will be emitted, as appropriate.
|
2011-11-30 14:33:03 +00:00
|
|
|
*
|
|
|
|
* @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,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *prefix,
|
2013-05-09 18:15:51 +00:00
|
|
|
GActionGroup *action_group)
|
2011-11-30 14:33:03 +00:00
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
char **actions;
|
2011-11-30 14:33:03 +00:00
|
|
|
Group *group;
|
2020-07-24 13:54:49 +00:00
|
|
|
int i;
|
2011-11-30 14:33:03 +00:00
|
|
|
|
|
|
|
/* 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
|
|
|
|
2020-07-19 13:45:12 +00:00
|
|
|
if (!muxer->groups)
|
|
|
|
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
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-01-22 02:47:34 +00:00
|
|
|
/*< private >
|
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,
|
2014-02-05 18:07:34 +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,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *prefix)
|
2011-11-30 14:33:03 +00:00
|
|
|
{
|
|
|
|
Group *group;
|
|
|
|
|
2020-07-19 13:45:12 +00:00
|
|
|
if (!muxer->groups)
|
|
|
|
return;
|
|
|
|
|
2011-11-30 14:33:03 +00:00
|
|
|
group = g_hash_table_lookup (muxer->groups, prefix);
|
|
|
|
|
|
|
|
if (group != NULL)
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
char **actions;
|
2020-07-24 13:54:49 +00:00
|
|
|
int i;
|
2011-11-30 14:33:03 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-22 02:47:34 +00:00
|
|
|
/*< private >
|
2013-05-09 18:15:51 +00:00
|
|
|
* gtk_action_muxer_new:
|
2019-06-15 23:08:39 +00:00
|
|
|
* @widget: the widget to which the muxer belongs
|
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 *
|
2020-03-20 16:22:29 +00:00
|
|
|
gtk_action_muxer_new (GtkWidget *widget)
|
2011-11-30 14:33:03 +00:00
|
|
|
{
|
2019-06-15 23:08:39 +00:00
|
|
|
return g_object_new (GTK_TYPE_ACTION_MUXER,
|
|
|
|
"widget", widget,
|
|
|
|
NULL);
|
2011-11-30 14:33:03 +00:00
|
|
|
}
|
2012-08-17 17:16:51 +00:00
|
|
|
|
2014-01-22 02:47:34 +00:00
|
|
|
/*< private >
|
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;
|
|
|
|
}
|
|
|
|
|
2014-01-22 02:47:34 +00:00
|
|
|
/*< private >
|
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)
|
|
|
|
{
|
2020-04-24 04:52:17 +00:00
|
|
|
notify_observers_removed (muxer, muxer->parent);
|
2012-08-17 17:16:51 +00:00
|
|
|
g_object_unref (muxer->parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
muxer->parent = parent;
|
|
|
|
|
|
|
|
if (muxer->parent != NULL)
|
|
|
|
{
|
|
|
|
g_object_ref (muxer->parent);
|
2020-04-24 04:52:17 +00:00
|
|
|
notify_observers_added (muxer, muxer->parent);
|
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,
|
2020-07-19 19:11:35 +00:00
|
|
|
const char *action_and_target,
|
|
|
|
const char *primary_accel)
|
2013-07-10 02:37:17 +00:00
|
|
|
{
|
|
|
|
if (primary_accel)
|
2020-07-19 19:11:35 +00:00
|
|
|
gtk_accels_replace (&muxer->primary_accels, action_and_target, primary_accel);
|
2013-07-10 02:37:17 +00:00
|
|
|
else
|
2020-07-19 19:11:35 +00:00
|
|
|
gtk_accels_remove (&muxer->primary_accels, action_and_target);
|
2013-07-10 02:37:17 +00:00
|
|
|
|
|
|
|
gtk_action_muxer_primary_accel_changed (muxer, NULL, action_and_target);
|
|
|
|
}
|
|
|
|
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *
|
2013-07-10 02:37:17 +00:00
|
|
|
gtk_action_muxer_get_primary_accel (GtkActionMuxer *muxer,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *action_and_target)
|
2013-07-10 02:37:17 +00:00
|
|
|
{
|
2020-07-19 19:11:35 +00:00
|
|
|
guint position;
|
2013-07-10 02:37:17 +00:00
|
|
|
|
2020-07-19 19:11:35 +00:00
|
|
|
position = gtk_accels_find (&muxer->primary_accels, action_and_target);
|
|
|
|
if (position < G_MAXUINT)
|
|
|
|
return gtk_accels_index (&muxer->primary_accels, position)->accel;
|
2013-07-10 02:37:17 +00:00
|
|
|
|
|
|
|
if (!muxer->parent)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return gtk_action_muxer_get_primary_accel (muxer->parent, action_and_target);
|
|
|
|
}
|
|
|
|
|
2020-07-24 18:40:36 +00:00
|
|
|
char *
|
|
|
|
gtk_print_action_and_target (const char *action_namespace,
|
|
|
|
const char *action_name,
|
2013-07-10 02:37:17 +00:00
|
|
|
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);
|
|
|
|
}
|
2014-05-14 00:27:58 +00:00
|
|
|
|
2020-07-24 18:40:36 +00:00
|
|
|
char *
|
|
|
|
gtk_normalise_detailed_action_name (const char *detailed_action_name)
|
2016-04-20 15:13:26 +00:00
|
|
|
{
|
|
|
|
GError *error = NULL;
|
2020-07-24 18:40:36 +00:00
|
|
|
char *action_and_target;
|
|
|
|
char *action_name;
|
2016-04-20 15:13:26 +00:00
|
|
|
GVariant *target;
|
|
|
|
|
|
|
|
g_action_parse_detailed_name (detailed_action_name, &action_name, &target, &error);
|
|
|
|
g_assert_no_error (error);
|
|
|
|
|
|
|
|
action_and_target = gtk_print_action_and_target (NULL, action_name, target);
|
|
|
|
|
|
|
|
if (target)
|
|
|
|
g_variant_unref (target);
|
|
|
|
|
|
|
|
g_free (action_name);
|
|
|
|
|
|
|
|
return action_and_target;
|
|
|
|
}
|
2019-06-14 17:41:45 +00:00
|
|
|
|