1.71 <GSimpleAction>

Class: <GSimpleAction>

It derives from <GObject>.

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>.

Properties

Property: simple-action:enabled self

If action is currently enabled.

If the action is disabled then calls to action:activate and action:change-state have no effect.

Its value is a boolean.

Set it with (set! (simple-action:enabled self) value).

Property: simple-action:name self

The name of the action. This is mostly meaningful for identifying the action once it has been added to a <GSimpleActionGroup>.

Its value is a string, or #f.

It can only be set when the object is made, with #:name.

Property: simple-action:parameter-type self

The type of the parameter that must be given when activating the action.

Its value is a <GVariantType>, or #f.

It can only be set when the object is made, with #:parameter-type.

Property: simple-action:state self

The state of the action, or #f if the action is stateless.

Its value is a <GVariant>, or #f.

Set it with (set! (simple-action:state self) value).

Property: simple-action:state-type self

The <GVariantType> of the state that the action has, or #f if the action is stateless.

Its value is a <GVariantType>, or #f.

It is read only.

Procedures

Procedure: simple-action:new name [parameter-type] ⇒ %return

Creates a new action.

The created action is stateless. See simple-action:new-stateful to create an action that has state.

name

Passed: a string.

the name of the action

parameter-type

Passed, or left out: a <GVariantType>, or #f.

the type of parameter that will be passed to handlers for the simple-action:activate signal, or #f for no parameter

%return

Returned: a <GSimpleAction>.

a new <GSimpleAction>

Procedure: simple-action:new-stateful name parameter-type state ⇒ %return

Creates a new stateful action.

All future state values must have the same <GVariantType> as the initial state.

If the state <GVariant> is floating, it is consumed.

name

Passed: a string.

the name of the action

parameter-type

Passed: a <GVariantType>, or #f.

the type of the parameter that will be passed to handlers for the simple-action:activate signal, or #f for no parameter

state

Passed: a <GVariant>.

the initial state of the action

%return

Returned: a <GSimpleAction>.

a new <GSimpleAction>

Method: simple-action:set-enabled self enabled
Method: set-enabled self 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.

self

Passed: a <GSimpleAction>.

a <GSimpleAction>

enabled

Passed: a boolean.

whether the action is enabled

Method: simple-action:set-state self value
Method: set-state self 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 action:change-state to request the change.

If the value GVariant is floating, it is consumed.

self

Passed: a <GSimpleAction>.

a <GSimpleAction>

value

Passed: a <GVariant>.

the new <GVariant> for the state

Method: simple-action:set-state-hint self [state-hint]
Method: set-state-hint self [state-hint]

Sets the state hint for the action.

See action:get-state-hint for more information about action state hints.

self

Passed: a <GSimpleAction>.

a <GSimpleAction>

state-hint

Passed, or left out: a <GVariant>, or #f.

a <GVariant> representing the state hint

Signals

Signal: simple-action:activate

Connect a handler with (connect object simple-action:activate handler). It is called as (handler self parameter).

Indicates that the action was just activated.

parameter will always be of the expected type, i.e. the parameter type specified when the action was created. If an incorrect type is given when activating the action, this signal is not emitted.

Since GLib 2.40, if no handler is connected to this signal then the default behaviour for boolean-stated actions with a #f parameter type is to toggle them via the simple-action:change-state signal. For stateful actions where the state type is equal to the parameter type, the default is to forward them directly to simple-action:change-state. This should allow almost all users of <GSimpleAction> to connect only one handler or the other.

self

Passed: a <GSimpleAction>.

parameter

Passed: a <GVariant>, or #f.

the parameter to the activation, or #f if it has no parameter

Signal: simple-action:change-state

Connect a handler with (connect object simple-action:change-state handler). It is called as (handler self value).

Indicates that the action just received a request to change its state.

value will always be of the correct state type, i.e. the type of the initial state passed to simple-action:new-stateful. If an incorrect type is given when requesting to change the state, this signal is not emitted.

If no handler is connected to this signal then the default behaviour is to call 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 simple-action:set-state from the handler.

An example of a ’change-state’ handler:


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.

self

Passed: a <GSimpleAction>.

value

Passed: a <GVariant>, or #f.

the requested value for the state