mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-04-21 22:59:16 +02:00
GAction: make GObject properties read-only
GAction is a read-only interface (as is visible by the lack of _set() functions on its API). The properties on the interface currently force implementors to support writing of the properties at construct time, however. Lift that restriction. Take advantage of this from GSimpleAction by nuking the set_property function and setting the fields directly in the constructor.
This commit is contained in:
parent
e6a25caa82
commit
bde41dacf7
@ -77,8 +77,7 @@ g_action_default_init (GActionInterface *iface)
|
|||||||
P_("Action Name"),
|
P_("Action Name"),
|
||||||
P_("The name used to invoke the action"),
|
P_("The name used to invoke the action"),
|
||||||
NULL,
|
NULL,
|
||||||
G_PARAM_READWRITE |
|
G_PARAM_READABLE |
|
||||||
G_PARAM_CONSTRUCT_ONLY |
|
|
||||||
G_PARAM_STATIC_STRINGS));
|
G_PARAM_STATIC_STRINGS));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -94,8 +93,7 @@ g_action_default_init (GActionInterface *iface)
|
|||||||
P_("Parameter Type"),
|
P_("Parameter Type"),
|
||||||
P_("The type of GVariant passed to activate()"),
|
P_("The type of GVariant passed to activate()"),
|
||||||
G_TYPE_VARIANT_TYPE,
|
G_TYPE_VARIANT_TYPE,
|
||||||
G_PARAM_READWRITE |
|
G_PARAM_READABLE |
|
||||||
G_PARAM_CONSTRUCT_ONLY |
|
|
||||||
G_PARAM_STATIC_STRINGS));
|
G_PARAM_STATIC_STRINGS));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -113,8 +111,7 @@ g_action_default_init (GActionInterface *iface)
|
|||||||
P_("Enabled"),
|
P_("Enabled"),
|
||||||
P_("If the action can be activated"),
|
P_("If the action can be activated"),
|
||||||
TRUE,
|
TRUE,
|
||||||
G_PARAM_CONSTRUCT |
|
G_PARAM_READABLE |
|
||||||
G_PARAM_READWRITE |
|
|
||||||
G_PARAM_STATIC_STRINGS));
|
G_PARAM_STATIC_STRINGS));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -207,35 +207,6 @@ g_simple_action_activate (GAction *action,
|
|||||||
g_variant_unref (parameter);
|
g_variant_unref (parameter);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
g_simple_action_set_property (GObject *object,
|
|
||||||
guint prop_id,
|
|
||||||
const GValue *value,
|
|
||||||
GParamSpec *pspec)
|
|
||||||
{
|
|
||||||
GSimpleAction *simple = G_SIMPLE_ACTION (object);
|
|
||||||
|
|
||||||
switch (prop_id)
|
|
||||||
{
|
|
||||||
case PROP_NAME:
|
|
||||||
g_assert (simple->name == NULL);
|
|
||||||
simple->name = g_value_dup_string (value);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PROP_PARAMETER_TYPE:
|
|
||||||
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;
|
|
||||||
|
|
||||||
default:
|
|
||||||
g_assert_not_reached ();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
g_simple_action_get_property (GObject *object,
|
g_simple_action_get_property (GObject *object,
|
||||||
guint prop_id,
|
guint prop_id,
|
||||||
@ -310,7 +281,6 @@ g_simple_action_class_init (GSimpleActionClass *class)
|
|||||||
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
||||||
|
|
||||||
object_class->get_property = g_simple_action_get_property;
|
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;
|
object_class->finalize = g_simple_action_finalize;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -397,8 +367,7 @@ g_simple_action_class_init (GSimpleActionClass *class)
|
|||||||
P_("Action Name"),
|
P_("Action Name"),
|
||||||
P_("The name used to invoke the action"),
|
P_("The name used to invoke the action"),
|
||||||
NULL,
|
NULL,
|
||||||
G_PARAM_READWRITE |
|
G_PARAM_READABLE |
|
||||||
G_PARAM_CONSTRUCT_ONLY |
|
|
||||||
G_PARAM_STATIC_STRINGS));
|
G_PARAM_STATIC_STRINGS));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -414,8 +383,7 @@ g_simple_action_class_init (GSimpleActionClass *class)
|
|||||||
P_("Parameter Type"),
|
P_("Parameter Type"),
|
||||||
P_("The type of GVariant passed to activate()"),
|
P_("The type of GVariant passed to activate()"),
|
||||||
G_TYPE_VARIANT_TYPE,
|
G_TYPE_VARIANT_TYPE,
|
||||||
G_PARAM_READWRITE |
|
G_PARAM_READABLE |
|
||||||
G_PARAM_CONSTRUCT_ONLY |
|
|
||||||
G_PARAM_STATIC_STRINGS));
|
G_PARAM_STATIC_STRINGS));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -433,8 +401,7 @@ g_simple_action_class_init (GSimpleActionClass *class)
|
|||||||
P_("Enabled"),
|
P_("Enabled"),
|
||||||
P_("If the action can be activated"),
|
P_("If the action can be activated"),
|
||||||
TRUE,
|
TRUE,
|
||||||
G_PARAM_CONSTRUCT |
|
G_PARAM_READABLE |
|
||||||
G_PARAM_READWRITE |
|
|
||||||
G_PARAM_STATIC_STRINGS));
|
G_PARAM_STATIC_STRINGS));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -516,10 +483,17 @@ GSimpleAction *
|
|||||||
g_simple_action_new (const gchar *name,
|
g_simple_action_new (const gchar *name,
|
||||||
const GVariantType *parameter_type)
|
const GVariantType *parameter_type)
|
||||||
{
|
{
|
||||||
return g_object_new (G_TYPE_SIMPLE_ACTION,
|
GSimpleAction *simple;
|
||||||
"name", name,
|
|
||||||
"parameter-type", parameter_type,
|
simple = g_object_new (G_TYPE_SIMPLE_ACTION, NULL);
|
||||||
NULL);
|
simple->name = g_strdup (name);
|
||||||
|
|
||||||
|
if (parameter_type)
|
||||||
|
simple->parameter_type = g_variant_type_copy (parameter_type);
|
||||||
|
|
||||||
|
simple->enabled = TRUE;
|
||||||
|
|
||||||
|
return simple;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -546,13 +520,15 @@ g_simple_action_new_stateful (const gchar *name,
|
|||||||
{
|
{
|
||||||
GSimpleAction *simple;
|
GSimpleAction *simple;
|
||||||
|
|
||||||
simple = g_object_new (G_TYPE_SIMPLE_ACTION,
|
simple = g_object_new (G_TYPE_SIMPLE_ACTION, NULL);
|
||||||
"name", name,
|
simple->name = g_strdup (name);
|
||||||
"parameter-type", parameter_type,
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
if (state)
|
if (parameter_type)
|
||||||
simple->state = g_variant_ref_sink (state);
|
simple->parameter_type = g_variant_type_copy (parameter_type);
|
||||||
|
|
||||||
|
simple->state = g_variant_ref_sink (state);
|
||||||
|
|
||||||
|
simple->enabled = TRUE;
|
||||||
|
|
||||||
return simple;
|
return simple;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user