GIO Reference Manual | ||||
---|---|---|---|---|
Top | Description | Object Hierarchy | Implemented Interfaces | Properties | Signals |
GSimpleAction; GSimpleAction * g_simple_action_new (const gchar *name
,const GVariantType *parameter_type
); GSimpleAction * g_simple_action_new_stateful (const gchar *name
,const GVariantType *parameter_type
,GVariant *state
); void g_simple_action_set_enabled (GSimpleAction *simple
,gboolean enabled
); void g_simple_action_set_state (GSimpleAction *simple
,GVariant *value
);
"enabled" gboolean : Read / Write "name" gchar* : Read / Write / Construct Only "parameter-type" GVariantType* : Read / Write / Construct Only "state" GVariant* : Read / Write "state-type" GVariantType* : Read
A GSimpleAction is the obvious simple implementation of the GAction interface. This is the easiest way to create an action for purposes of adding it to a GSimpleActionGroup.
See also GtkAction.
GSimpleAction * g_simple_action_new (const gchar *name
,const GVariantType *parameter_type
);
Creates a new action.
The created action is stateless. See g_simple_action_new_stateful()
.
|
the name of the action |
|
the type of parameter to the activate function. [allow-none] |
Returns : |
a new GSimpleAction |
Since 2.28
GSimpleAction * g_simple_action_new_stateful (const gchar *name
,const GVariantType *parameter_type
,GVariant *state
);
Creates a new stateful action.
state
is the initial state of the action. All future state values
must have the same GVariantType as the initial state.
If the state
GVariant is floating, it is consumed.
|
the name of the action |
|
the type of the parameter to the activate function. [allow-none] |
|
the initial state of the action |
Returns : |
a new GSimpleAction |
Since 2.28
void g_simple_action_set_enabled (GSimpleAction *simple
,gboolean enabled
);
Sets the action as enabled or not.
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.
|
a GSimpleAction |
|
whether the action is enabled |
Since 2.28
void g_simple_action_set_state (GSimpleAction *simple
,GVariant *value
);
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.
If the value
GVariant is floating, it is consumed.
|
a GSimpleAction |
|
the new GVariant for the state |
Since 2.30
"enabled"
property"enabled" gboolean : Read / Write
If action
is currently enabled.
If the action is disabled then calls to g_action_activate()
and
g_action_change_state()
have no effect.
Default value: TRUE
Since 2.28
"name"
property"name" gchar* : Read / Write / Construct Only
The name of the action. This is mostly meaningful for identifying the action once it has been added to a GSimpleActionGroup.
Default value: NULL
Since 2.28
"parameter-type"
property"parameter-type" GVariantType* : Read / Write / Construct Only
The type of the parameter that must be given when activating the action.
Since 2.28
"state"
property"state" GVariant* : Read / Write
The state of the action, or NULL
if the action is stateless.
Allowed values: GVariant<*>
Default value: NULL
Since 2.28
"state-type"
property"state-type" GVariantType* : Read
The GVariantType of the state that the action has, or NULL
if the
action is stateless.
Since 2.28
"activate"
signalvoid user_function (GSimpleAction *simple,
GVariant *parameter,
gpointer user_data) : Run Last
Indicates that the action was just activated.
parameter
will always be of the expected type. In the event that
an incorrect type was given, no signal will be emitted.
|
the GSimpleAction |
|
the parameter to the activation. [allow-none] |
|
user data set when the signal handler was connected. |
Since 2.28
"change-state"
signalvoid user_function (GSimpleAction *simple,
GVariant *value,
gpointer user_data) : Run Last
Indicates that the action just received a request to change its state.
value
will always be of the correct state type. In the event that
an incorrect type was given, no signal will be emitted.
If no handler is connected to this signal then the default
behaviour is to call g_simple_action_set_state()
to set the state
to the requested value. If you connect a signal handler then no
default action is taken. If the state should change then you must
call g_simple_action_set_state()
from the handler.
Example 26. Example 'change-state' handler
1 2 3 4 5 6 7 8 9 10 11 12 13 |
static void change_volume_state (GSimpleAction *action, GVariant *value, gpointer user_data) { gint requested; requested = g_variant_get_int32 (value); // Volume only goes from 0 to 10 if (0 <= requested && requested <= 10) g_simple_action_set_state (action, value); } |
The handler need not set the state to the requested value. It could set it to any value at all, or take some other action.
|
the GSimpleAction |
|
the requested value for the state. [allow-none] |
|
user data set when the signal handler was connected. |
Since 2.30