mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-24 14:36:13 +01:00
Make 4 incompatible changes to the GAction API
This commit represents an API break to GAction in the following ways: - the 'set_state' entry in the GActionInterface vtable has been renamed to 'change_state'. The number and order of vtable items has not otherwise changed. - g_action_set_state() has been renamed to g_action_change_state() to match the updated vtable entry. - the "state" property of the GAction interface has been changed to read-only to reflect the fact that g_action_set_state() no longer exists. - GSimpleActionClass has been hidden. GSimpleAction can no longer be subclassed. >> Rationale g_action_set_state() has never been a true setter in the sense that calling it will update the value of the "state" property. It has always been closer to "request 'state' to be changed to this value" with semantics defined by the implementor of the interface. This is why the equivalent method in GActionGroup had its name changed from 'set' to 'change'. This change makes the two interfaces more consistent and removes any implication about the effect that calling set_state() should have on the 'state' property. >> Impact This incompatible API break was undertaken only because I strongly suspect that it will go entirely unnoticed. If the break actually affects anybody, then we will accommodate them (possibly going as far as to revert this commit entirely). The virtual table change only impacts implementors of GAction. I strongly suspect that this is nobody (except for GSimpleAction). The hiding of GSimpleActionClass only impacts impacts subclasses of GSimpleAction. I strongly suspect that none of these exist. The changing of the property to be read-only only affects people who were trying to change the state by using GObject properties. I strongly suspect that this is nobody at all. The removal of the g_action_set_state() call is the most dangerous, but I still suspect that it will impact nobody outside of GLib. If anybody is impacted by this change then, at their request, I will reintroduce the API as a deprecated alias for g_action_change_state().
This commit is contained in:
parent
d1e26c51c8
commit
5ff65d8695
@ -2832,9 +2832,9 @@ g_action_get_state_hint
|
||||
<SUBSECTION>
|
||||
g_action_get_enabled
|
||||
g_action_get_state
|
||||
g_action_set_state
|
||||
|
||||
<SUBSECTION>
|
||||
g_action_change_state
|
||||
g_action_activate
|
||||
|
||||
<SUBSECTION Standard>
|
||||
@ -2857,6 +2857,7 @@ g_simple_action_new_stateful
|
||||
|
||||
<SUBSECTION>
|
||||
g_simple_action_set_enabled
|
||||
g_simple_action_set_state
|
||||
|
||||
<SUBSECTION Standard>
|
||||
GSimpleActionPrivate
|
||||
|
@ -39,7 +39,7 @@ G_DEFINE_INTERFACE (GAction, g_action, G_TYPE_OBJECT)
|
||||
* parameter type (which is given at construction time).
|
||||
*
|
||||
* An action may optionally have a state, in which case the state may be
|
||||
* set with g_action_set_state(). This call takes a #GVariant. The
|
||||
* set with g_action_change_state(). This call takes a #GVariant. The
|
||||
* correct type for the state is determined by a static state type
|
||||
* (which is given at construction time).
|
||||
*
|
||||
@ -54,8 +54,8 @@ G_DEFINE_INTERFACE (GAction, g_action, G_TYPE_OBJECT)
|
||||
* name of the action, the parameter type, the enabled state, the
|
||||
* optional state type and the state and emitting the appropriate
|
||||
* signals when these change. The implementor responsible for filtering
|
||||
* calls to g_action_activate() and g_action_set_state() for type safety
|
||||
* and for the state being enabled.
|
||||
* calls to g_action_activate() and g_action_change_state() for type
|
||||
* safety and for the state being enabled.
|
||||
*
|
||||
* Probably the only useful thing to do with a #GAction is to put it
|
||||
* inside of a #GSimpleActionGroup.
|
||||
@ -104,7 +104,7 @@ g_action_default_init (GActionInterface *iface)
|
||||
* If @action is currently enabled.
|
||||
*
|
||||
* If the action is disabled then calls to g_action_activate() and
|
||||
* g_action_set_state() have no effect.
|
||||
* g_action_change_state() have no effect.
|
||||
*
|
||||
* Since: 2.28
|
||||
**/
|
||||
@ -146,13 +146,12 @@ g_action_default_init (GActionInterface *iface)
|
||||
P_("The state the action is in"),
|
||||
G_VARIANT_TYPE_ANY,
|
||||
NULL,
|
||||
G_PARAM_CONSTRUCT |
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_READABLE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
}
|
||||
|
||||
/**
|
||||
* g_action_set_state:
|
||||
* g_action_change_state:
|
||||
* @action: a #GAction
|
||||
* @value: the new state
|
||||
*
|
||||
@ -167,11 +166,11 @@ g_action_default_init (GActionInterface *iface)
|
||||
*
|
||||
* If the @value GVariant is floating, it is consumed.
|
||||
*
|
||||
* Since: 2.28
|
||||
* Since: 2.30
|
||||
**/
|
||||
void
|
||||
g_action_set_state (GAction *action,
|
||||
GVariant *value)
|
||||
g_action_change_state (GAction *action,
|
||||
GVariant *value)
|
||||
{
|
||||
const GVariantType *state_type;
|
||||
|
||||
@ -184,7 +183,7 @@ g_action_set_state (GAction *action,
|
||||
g_variant_ref_sink (value);
|
||||
|
||||
G_ACTION_GET_IFACE (action)
|
||||
->set_state (action, value);
|
||||
->change_state (action, value);
|
||||
|
||||
g_variant_unref (value);
|
||||
}
|
||||
@ -269,13 +268,13 @@ g_action_get_parameter_type (GAction *action)
|
||||
* If the action is stateful (e.g. created with
|
||||
* g_simple_action_new_stateful()) then this function returns the
|
||||
* #GVariantType of the state. This is the type of the initial value
|
||||
* given as the state. All calls to g_action_set_state() must give a
|
||||
* given as the state. All calls to g_action_change_state() must give a
|
||||
* #GVariant of this type and g_action_get_state() will return a
|
||||
* #GVariant of the same type.
|
||||
*
|
||||
* If the action is not stateful (e.g. created with g_simple_action_new())
|
||||
* then this function will return %NULL. In that case, g_action_get_state()
|
||||
* will return %NULL and you must not call g_action_set_state().
|
||||
* will return %NULL and you must not call g_action_change_state().
|
||||
*
|
||||
* Returns: (allow-none): the state type, if the action is stateful
|
||||
*
|
||||
|
@ -47,7 +47,7 @@ typedef struct _GActionInterface GActionInterface;
|
||||
* @get_state_hint: the virtual function pointer for g_action_get_state_hint()
|
||||
* @get_enabled: the virtual function pointer for g_action_get_enabled()
|
||||
* @get_state: the virtual function pointer for g_action_get_state()
|
||||
* @set_state: the virtual function pointer for g_action_set_state()
|
||||
* @change_state: the virtual function pointer for g_action_change_state()
|
||||
* @activate: the virtual function pointer for g_action_activate(). Note that #GAction does not have an
|
||||
* 'activate' signal but that implementations of it may have one.
|
||||
*
|
||||
@ -65,9 +65,9 @@ struct _GActionInterface
|
||||
|
||||
gboolean (* get_enabled) (GAction *action);
|
||||
GVariant * (* get_state) (GAction *action);
|
||||
void (* set_state) (GAction *action,
|
||||
GVariant *value);
|
||||
|
||||
void (* change_state) (GAction *action,
|
||||
GVariant *value);
|
||||
void (* activate) (GAction *action,
|
||||
GVariant *parameter);
|
||||
};
|
||||
@ -81,9 +81,9 @@ GVariant * g_action_get_state_hint (GAction
|
||||
|
||||
gboolean g_action_get_enabled (GAction *action);
|
||||
GVariant * g_action_get_state (GAction *action);
|
||||
void g_action_set_state (GAction *action,
|
||||
GVariant *value);
|
||||
|
||||
void g_action_change_state (GAction *action,
|
||||
GVariant *value);
|
||||
void g_action_activate (GAction *action,
|
||||
GVariant *parameter);
|
||||
G_END_DECLS
|
||||
|
@ -1376,7 +1376,7 @@ g_action_get_state
|
||||
g_action_get_state_hint
|
||||
g_action_get_state_type
|
||||
g_action_get_type
|
||||
g_action_set_state
|
||||
g_action_change_state
|
||||
g_simple_action_group_get_type
|
||||
g_simple_action_group_insert
|
||||
g_simple_action_group_lookup
|
||||
@ -1387,6 +1387,7 @@ g_simple_action_get_type
|
||||
g_simple_action_new
|
||||
g_simple_action_new_stateful
|
||||
g_simple_action_set_enabled
|
||||
g_simple_action_set_state
|
||||
g_pollable_input_stream_get_type
|
||||
g_pollable_input_stream_can_poll
|
||||
g_pollable_input_stream_create_source
|
||||
|
@ -26,10 +26,6 @@
|
||||
#include "gaction.h"
|
||||
#include "glibintl.h"
|
||||
|
||||
static void g_simple_action_iface_init (GActionInterface *iface);
|
||||
G_DEFINE_TYPE_WITH_CODE (GSimpleAction, g_simple_action, G_TYPE_OBJECT,
|
||||
G_IMPLEMENT_INTERFACE (G_TYPE_ACTION, g_simple_action_iface_init))
|
||||
|
||||
/**
|
||||
* SECTION:gsimpleaction
|
||||
* @title: GSimpleAction
|
||||
@ -41,16 +37,22 @@ G_DEFINE_TYPE_WITH_CODE (GSimpleAction, g_simple_action, G_TYPE_OBJECT,
|
||||
*
|
||||
* See also #GtkAction.
|
||||
**/
|
||||
|
||||
struct _GSimpleActionPrivate
|
||||
struct _GSimpleAction
|
||||
{
|
||||
GObject parent_instance;
|
||||
|
||||
gchar *name;
|
||||
GVariantType *parameter_type;
|
||||
guint enabled : 1;
|
||||
guint state_set : 1;
|
||||
gboolean enabled;
|
||||
GVariant *state;
|
||||
};
|
||||
|
||||
typedef GObjectClass GSimpleActionClass;
|
||||
|
||||
static void g_simple_action_iface_init (GActionInterface *iface);
|
||||
G_DEFINE_TYPE_WITH_CODE (GSimpleAction, g_simple_action, G_TYPE_OBJECT,
|
||||
G_IMPLEMENT_INTERFACE (G_TYPE_ACTION, g_simple_action_iface_init))
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_NONE,
|
||||
@ -74,7 +76,7 @@ g_simple_action_get_name (GAction *action)
|
||||
{
|
||||
GSimpleAction *simple = G_SIMPLE_ACTION (action);
|
||||
|
||||
return simple->priv->name;
|
||||
return simple->name;
|
||||
}
|
||||
|
||||
const GVariantType *
|
||||
@ -82,7 +84,7 @@ g_simple_action_get_parameter_type (GAction *action)
|
||||
{
|
||||
GSimpleAction *simple = G_SIMPLE_ACTION (action);
|
||||
|
||||
return simple->priv->parameter_type;
|
||||
return simple->parameter_type;
|
||||
}
|
||||
|
||||
static const GVariantType *
|
||||
@ -90,8 +92,8 @@ g_simple_action_get_state_type (GAction *action)
|
||||
{
|
||||
GSimpleAction *simple = G_SIMPLE_ACTION (action);
|
||||
|
||||
if (simple->priv->state != NULL)
|
||||
return g_variant_get_type (simple->priv->state);
|
||||
if (simple->state != NULL)
|
||||
return g_variant_get_type (simple->state);
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
@ -107,34 +109,58 @@ g_simple_action_get_enabled (GAction *action)
|
||||
{
|
||||
GSimpleAction *simple = G_SIMPLE_ACTION (action);
|
||||
|
||||
return simple->priv->enabled;
|
||||
return simple->enabled;
|
||||
}
|
||||
|
||||
static void
|
||||
g_simple_action_set_state (GAction *action,
|
||||
GVariant *value)
|
||||
g_simple_action_change_state (GAction *action,
|
||||
GVariant *value)
|
||||
{
|
||||
GSimpleAction *simple = G_SIMPLE_ACTION (action);
|
||||
|
||||
g_simple_action_set_state (simple, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_simple_action_set_state:
|
||||
* @simple: a #GSimpleAction
|
||||
* @value: the new #GVariant for the state
|
||||
*
|
||||
* Sets the state of the action.
|
||||
*
|
||||
* This directly updates the 'state' property to the given value.
|
||||
*
|
||||
* This should only be called by the implementor of the action. Users
|
||||
* of the action should not attempt to directly modify the 'state'
|
||||
* property. Instead, they should call g_action_change_state() to
|
||||
* request the change.
|
||||
*
|
||||
* Since: 2.30
|
||||
**/
|
||||
void
|
||||
g_simple_action_set_state (GSimpleAction *simple,
|
||||
GVariant *value)
|
||||
{
|
||||
g_return_if_fail (G_IS_SIMPLE_ACTION (simple));
|
||||
g_return_if_fail (value != NULL);
|
||||
|
||||
{
|
||||
const GVariantType *state_type;
|
||||
|
||||
state_type = simple->priv->state ?
|
||||
g_variant_get_type (simple->priv->state) : NULL;
|
||||
state_type = simple->state ?
|
||||
g_variant_get_type (simple->state) : NULL;
|
||||
g_return_if_fail (state_type != NULL);
|
||||
g_return_if_fail (g_variant_is_of_type (value, state_type));
|
||||
}
|
||||
|
||||
g_variant_ref_sink (value);
|
||||
|
||||
if (!g_variant_equal (simple->priv->state, value))
|
||||
if (!simple->state || !g_variant_equal (simple->state, value))
|
||||
{
|
||||
if (simple->priv->state)
|
||||
g_variant_unref (simple->priv->state);
|
||||
if (simple->state)
|
||||
g_variant_unref (simple->state);
|
||||
|
||||
simple->priv->state = g_variant_ref (value);
|
||||
simple->state = g_variant_ref (value);
|
||||
|
||||
g_object_notify (G_OBJECT (simple), "state");
|
||||
}
|
||||
@ -147,7 +173,7 @@ g_simple_action_get_state (GAction *action)
|
||||
{
|
||||
GSimpleAction *simple = G_SIMPLE_ACTION (action);
|
||||
|
||||
return simple->priv->state ? g_variant_ref (simple->priv->state) : NULL;
|
||||
return simple->state ? g_variant_ref (simple->state) : NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -156,16 +182,16 @@ g_simple_action_activate (GAction *action,
|
||||
{
|
||||
GSimpleAction *simple = G_SIMPLE_ACTION (action);
|
||||
|
||||
g_return_if_fail (simple->priv->parameter_type == NULL ?
|
||||
g_return_if_fail (simple->parameter_type == NULL ?
|
||||
parameter == NULL :
|
||||
(parameter != NULL &&
|
||||
g_variant_is_of_type (parameter,
|
||||
simple->priv->parameter_type)));
|
||||
simple->parameter_type)));
|
||||
|
||||
if (parameter != NULL)
|
||||
g_variant_ref_sink (parameter);
|
||||
|
||||
if (simple->priv->enabled)
|
||||
if (simple->enabled)
|
||||
g_signal_emit (simple, g_simple_action_signals[SIGNAL_ACTIVATE], 0, parameter);
|
||||
|
||||
if (parameter != NULL)
|
||||
@ -183,45 +209,19 @@ g_simple_action_set_property (GObject *object,
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_NAME:
|
||||
g_assert (simple->priv->name == NULL);
|
||||
simple->priv->name = g_value_dup_string (value);
|
||||
g_assert (simple->name == NULL);
|
||||
simple->name = g_value_dup_string (value);
|
||||
break;
|
||||
|
||||
case PROP_PARAMETER_TYPE:
|
||||
g_assert (simple->priv->parameter_type == NULL);
|
||||
simple->priv->parameter_type = g_value_dup_boxed (value);
|
||||
g_assert (simple->parameter_type == NULL);
|
||||
simple->parameter_type = g_value_dup_boxed (value);
|
||||
break;
|
||||
|
||||
case PROP_ENABLED:
|
||||
g_simple_action_set_enabled (simple, g_value_get_boolean (value));
|
||||
break;
|
||||
|
||||
case PROP_STATE:
|
||||
/* PROP_STATE is marked as G_PARAM_CONSTRUCT so we always get a
|
||||
* call during object construction, even if it is NULL. We treat
|
||||
* that first call differently, for a number of reasons.
|
||||
*
|
||||
* First, we don't want the value to be rejected by the
|
||||
* possibly-overridden .set_state() function. Second, we don't
|
||||
* want to be tripped by the assertions in g_simple_action_set_state()
|
||||
* that would enforce the catch22 that we only provide a value of
|
||||
* the same type as the existing value (when there is not yet an
|
||||
* existing value).
|
||||
*/
|
||||
if (simple->priv->state_set)
|
||||
g_simple_action_set_state (G_ACTION (simple),
|
||||
g_value_get_variant (value));
|
||||
|
||||
else /* this is the special case */
|
||||
{
|
||||
/* only do it the first time. */
|
||||
simple->priv->state_set = TRUE;
|
||||
|
||||
/* blindly set it. */
|
||||
simple->priv->state = g_value_dup_variant (value);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
@ -267,11 +267,11 @@ g_simple_action_finalize (GObject *object)
|
||||
{
|
||||
GSimpleAction *simple = G_SIMPLE_ACTION (object);
|
||||
|
||||
g_free (simple->priv->name);
|
||||
if (simple->priv->parameter_type)
|
||||
g_variant_type_free (simple->priv->parameter_type);
|
||||
if (simple->priv->state)
|
||||
g_variant_unref (simple->priv->state);
|
||||
g_free (simple->name);
|
||||
if (simple->parameter_type)
|
||||
g_variant_type_free (simple->parameter_type);
|
||||
if (simple->state)
|
||||
g_variant_unref (simple->state);
|
||||
|
||||
G_OBJECT_CLASS (g_simple_action_parent_class)
|
||||
->finalize (object);
|
||||
@ -280,9 +280,6 @@ g_simple_action_finalize (GObject *object)
|
||||
void
|
||||
g_simple_action_init (GSimpleAction *simple)
|
||||
{
|
||||
simple->priv = G_TYPE_INSTANCE_GET_PRIVATE (simple,
|
||||
G_TYPE_SIMPLE_ACTION,
|
||||
GSimpleActionPrivate);
|
||||
}
|
||||
|
||||
void
|
||||
@ -294,7 +291,7 @@ g_simple_action_iface_init (GActionInterface *iface)
|
||||
iface->get_state_hint = g_simple_action_get_state_hint;
|
||||
iface->get_enabled = g_simple_action_get_enabled;
|
||||
iface->get_state = g_simple_action_get_state;
|
||||
iface->set_state = g_simple_action_set_state;
|
||||
iface->change_state = g_simple_action_change_state;
|
||||
iface->activate = g_simple_action_activate;
|
||||
}
|
||||
|
||||
@ -303,7 +300,6 @@ g_simple_action_class_init (GSimpleActionClass *class)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
||||
|
||||
|
||||
object_class->get_property = g_simple_action_get_property;
|
||||
object_class->set_property = g_simple_action_set_property;
|
||||
object_class->finalize = g_simple_action_finalize;
|
||||
@ -324,8 +320,7 @@ g_simple_action_class_init (GSimpleActionClass *class)
|
||||
g_signal_new (I_("activate"),
|
||||
G_TYPE_SIMPLE_ACTION,
|
||||
G_SIGNAL_RUN_LAST | G_SIGNAL_MUST_COLLECT,
|
||||
G_STRUCT_OFFSET (GSimpleActionClass, activate),
|
||||
NULL, NULL,
|
||||
0, NULL, NULL,
|
||||
g_cclosure_marshal_VOID__VARIANT,
|
||||
G_TYPE_NONE, 1,
|
||||
G_TYPE_VARIANT);
|
||||
@ -370,7 +365,7 @@ g_simple_action_class_init (GSimpleActionClass *class)
|
||||
* If @action is currently enabled.
|
||||
*
|
||||
* If the action is disabled then calls to g_simple_action_activate() and
|
||||
* g_simple_action_set_state() have no effect.
|
||||
* g_simple_action_change_state() have no effect.
|
||||
*
|
||||
* Since: 2.28
|
||||
**/
|
||||
@ -412,11 +407,8 @@ g_simple_action_class_init (GSimpleActionClass *class)
|
||||
P_("The state the action is in"),
|
||||
G_VARIANT_TYPE_ANY,
|
||||
NULL,
|
||||
G_PARAM_CONSTRUCT |
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_READABLE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_type_class_add_private (class, sizeof (GSimpleActionPrivate));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -429,6 +421,9 @@ g_simple_action_class_init (GSimpleActionClass *class)
|
||||
* An action must be enabled in order to be activated or in order to
|
||||
* have its state changed from outside callers.
|
||||
*
|
||||
* This should only be called by the implementor of the action. Users
|
||||
* of the action should not attempt to modify its enabled flag.
|
||||
*
|
||||
* Since: 2.28
|
||||
**/
|
||||
void
|
||||
@ -439,9 +434,9 @@ g_simple_action_set_enabled (GSimpleAction *simple,
|
||||
|
||||
enabled = !!enabled;
|
||||
|
||||
if (simple->priv->enabled != enabled)
|
||||
if (simple->enabled != enabled)
|
||||
{
|
||||
simple->priv->enabled = enabled;
|
||||
simple->enabled = enabled;
|
||||
g_object_notify (G_OBJECT (simple), "enabled");
|
||||
}
|
||||
}
|
||||
@ -490,9 +485,14 @@ g_simple_action_new_stateful (const gchar *name,
|
||||
const GVariantType *parameter_type,
|
||||
GVariant *state)
|
||||
{
|
||||
return g_object_new (G_TYPE_SIMPLE_ACTION,
|
||||
"name", name,
|
||||
"parameter-type", parameter_type,
|
||||
"state", state,
|
||||
NULL);
|
||||
GSimpleAction *simple;
|
||||
|
||||
simple = g_object_new (G_TYPE_SIMPLE_ACTION,
|
||||
"name", name,
|
||||
"parameter-type", parameter_type,
|
||||
NULL);
|
||||
|
||||
simple->state = g_variant_ref_sink (state);
|
||||
|
||||
return simple;
|
||||
}
|
||||
|
@ -33,50 +33,8 @@ G_BEGIN_DECLS
|
||||
#define G_TYPE_SIMPLE_ACTION (g_simple_action_get_type ())
|
||||
#define G_SIMPLE_ACTION(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), \
|
||||
G_TYPE_SIMPLE_ACTION, GSimpleAction))
|
||||
#define G_SIMPLE_ACTION_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), \
|
||||
G_TYPE_SIMPLE_ACTION, GSimpleActionClass))
|
||||
#define G_IS_SIMPLE_ACTION(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), \
|
||||
G_TYPE_SIMPLE_ACTION))
|
||||
#define G_IS_SIMPLE_ACTION_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), \
|
||||
G_TYPE_SIMPLE_ACTION))
|
||||
#define G_SIMPLE_ACTION_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), \
|
||||
G_TYPE_SIMPLE_ACTION, GSimpleActionClass))
|
||||
|
||||
typedef struct _GSimpleActionPrivate GSimpleActionPrivate;
|
||||
typedef struct _GSimpleActionClass GSimpleActionClass;
|
||||
|
||||
/**
|
||||
* GSimpleAction:
|
||||
*
|
||||
* The <structname>GSimpleAction</structname> structure contains private
|
||||
* data and should only be accessed using the provided API
|
||||
*
|
||||
* Since: 2.28
|
||||
*/
|
||||
struct _GSimpleAction
|
||||
{
|
||||
/*< private >*/
|
||||
GObject parent_instance;
|
||||
|
||||
GSimpleActionPrivate *priv;
|
||||
};
|
||||
|
||||
/**
|
||||
* GSimpleActionClass:
|
||||
* @activate: the class closure for the activate signal
|
||||
*
|
||||
* Since: 2.28
|
||||
*/
|
||||
struct _GSimpleActionClass
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
|
||||
/* signals */
|
||||
void (* activate) (GSimpleAction *simple,
|
||||
GVariant *parameter);
|
||||
/*< private >*/
|
||||
gpointer padding[6];
|
||||
};
|
||||
|
||||
GType g_simple_action_get_type (void) G_GNUC_CONST;
|
||||
|
||||
@ -90,6 +48,9 @@ GSimpleAction * g_simple_action_new_stateful (const g
|
||||
void g_simple_action_set_enabled (GSimpleAction *simple,
|
||||
gboolean enabled);
|
||||
|
||||
void g_simple_action_set_state (GSimpleAction *simple,
|
||||
GVariant *value);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __G_SIMPLE_ACTION_H__ */
|
||||
|
@ -148,9 +148,9 @@ g_simple_action_group_get_state (GActionGroup *group,
|
||||
}
|
||||
|
||||
static void
|
||||
g_simple_action_group_set_state (GActionGroup *group,
|
||||
const gchar *action_name,
|
||||
GVariant *value)
|
||||
g_simple_action_group_change_state (GActionGroup *group,
|
||||
const gchar *action_name,
|
||||
GVariant *value)
|
||||
{
|
||||
GSimpleActionGroup *simple = G_SIMPLE_ACTION_GROUP (group);
|
||||
GAction *action;
|
||||
@ -160,7 +160,7 @@ g_simple_action_group_set_state (GActionGroup *group,
|
||||
if (action == NULL)
|
||||
return;
|
||||
|
||||
g_action_set_state (action, value);
|
||||
g_action_change_state (action, value);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -258,7 +258,7 @@ g_simple_action_group_iface_init (GActionGroupInterface *iface)
|
||||
iface->get_action_state_hint = g_simple_action_group_get_state_hint;
|
||||
iface->get_action_enabled = g_simple_action_group_get_enabled;
|
||||
iface->get_action_state = g_simple_action_group_get_state;
|
||||
iface->change_action_state = g_simple_action_group_set_state;
|
||||
iface->change_action_state = g_simple_action_group_change_state;
|
||||
iface->activate_action = g_simple_action_group_activate;
|
||||
}
|
||||
|
||||
|
@ -232,12 +232,12 @@ test_stateful (void)
|
||||
|
||||
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
|
||||
{
|
||||
g_action_set_state (G_ACTION (action), g_variant_new_int32 (123));
|
||||
g_simple_action_set_state (action, g_variant_new_int32 (123));
|
||||
exit (0);
|
||||
}
|
||||
g_test_trap_assert_failed ();
|
||||
|
||||
g_action_set_state (G_ACTION (action), g_variant_new_string ("hello"));
|
||||
g_simple_action_set_state (action, g_variant_new_string ("hello"));
|
||||
state = g_action_get_state (G_ACTION (action));
|
||||
g_assert_cmpstr (g_variant_get_string (state, NULL), ==, "hello");
|
||||
g_variant_unref (state);
|
||||
@ -247,7 +247,7 @@ test_stateful (void)
|
||||
action = g_simple_action_new ("foo", NULL);
|
||||
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
|
||||
{
|
||||
g_action_set_state (G_ACTION (action), g_variant_new_int32 (123));
|
||||
g_simple_action_set_state (action, g_variant_new_int32 (123));
|
||||
exit (0);
|
||||
}
|
||||
g_test_trap_assert_failed ();
|
||||
|
@ -23,21 +23,21 @@ activate_action (GAction *action,
|
||||
}
|
||||
|
||||
static void
|
||||
activate_toggle_action (GAction *action,
|
||||
GVariant *parameter,
|
||||
gpointer data)
|
||||
activate_toggle_action (GSimpleAction *action,
|
||||
GVariant *parameter,
|
||||
gpointer data)
|
||||
{
|
||||
GApplication *application = G_APPLICATION (data);
|
||||
GVariant *state;
|
||||
gboolean b;
|
||||
|
||||
g_print ("action %s activated\n", g_action_get_name (action));
|
||||
g_print ("action %s activated\n", g_action_get_name (G_ACTION (action)));
|
||||
|
||||
g_application_hold (application);
|
||||
state = g_action_get_state (action);
|
||||
state = g_action_get_state (G_ACTION (action));
|
||||
b = g_variant_get_boolean (state);
|
||||
g_variant_unref (state);
|
||||
g_action_set_state (action, g_variant_new_boolean (!b));
|
||||
g_simple_action_set_state (action, g_variant_new_boolean (!b));
|
||||
g_print ("state change %d -> %d\n", b, !b);
|
||||
g_application_release (application);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user