## GSimpleAction GSimpleAction — A simple GAction implementation |

## Functions

GSimpleAction * | g_simple_action_new ()
GSimpleAction * | g_simple_action_new_stateful ()
void | g_simple_action_set_enabled ()
void | g_simple_action_set_state ()
void | g_simple_action_set_state_hint ()

## Properties

gboolean | enabled | Read / Write
gchar * | name | Read / Write / Construct Only
GVariantType * | parameter-type | Read / Write / Construct Only
GVariant * | state | Read / Write / Construct
GVariantType * | state-type | Read

## Signals

void | activate | Run Last
void | change-state | Run Last

## Types and Values

| GSimpleAction

## Object Hierarchy

        GObject
        ╰── GSimpleAction

## Implemented Interfaces

GSimpleAction implements GAction.

## Includes

    #include <gio/gio.h>

## Description

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.

## Functions

### g_simple_action_new ()

    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()`.

#### Parameters

name | the name of the action |
parameter_type | the type of parameter to the activate function. | [allow-none]

#### Returns

a new GSimpleAction

Since 2.28

### g_simple_action_new_stateful ()

    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.

#### Parameters

name | the name of the action |
parameter_type | the type of the parameter to the activate function. | [allow-none]
state | the initial state of the action |

#### Returns

a new GSimpleAction

Since 2.28

### g_simple_action_set_enabled ()

    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.

#### Parameters

simple | a GSimpleAction |
enabled | whether the action is enabled |

Since 2.28

### g_simple_action_set_state ()

    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.

#### Parameters

simple | a GSimpleAction |
value | the new GVariant for the state |

Since 2.30

### g_simple_action_set_state_hint ()

    void
    g_simple_action_set_state_hint (GSimpleAction *simple,
                                    GVariant *state_hint);

Sets the state hint for the action.

See `g_action_get_state_hint()` for more information about action state hints.

#### Parameters

simple | a GSimpleAction |
state_hint | a GVariant representing the state hint. | [allow-none]

Since 2.44

## Types and Values

### GSimpleAction

    typedef struct _GSimpleAction GSimpleAction;

GSimpleAction is an opaque data structure and can only be accessed using the following functions.

## Property Details

### The `“enabled”` property

      “enabled”                  gboolean

If `action` is currently enabled.

If the action is disabled then calls to `g_action_activate()` and `g_action_change_state()` have no effect.

Flags: Read / Write

Default value: TRUE

Since 2.28

### The `“name”` property

      “name”                     gchar *

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

Flags: Read / Write / Construct Only

Default value: NULL

Since 2.28

### The `“parameter-type”` property

      “parameter-type”           GVariantType *

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

Flags: Read / Write / Construct Only

Since 2.28

### The `“state”` property

      “state”                    GVariant *

The state of the action, or `NULL` if the action is stateless.

Flags: Read / Write / Construct

Allowed values: GVariant<*>

Default value: NULL

Since 2.28

### The `“state-type”` property

      “state-type”               GVariantType *

The GVariantType of the state that the action has, or `NULL` if the action is stateless.

Flags: Read

Since 2.28

## Signal Details

### The `“activate”` signal

    void
    user_function (GSimpleAction *simple,
                   GVariant      *parameter,
                   gpointer       user_data)

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.

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

#### Parameters

simple | the GSimpleAction |
parameter | the parameter to the activation. | [allow-none]
user_data | user data set when the signal handler was connected. |

Flags: Run Last

Since 2.28

### The `“change-state”` signal

    void
    user_function (GSimpleAction *simple,
                   GVariant      *value,
                   gpointer       user_data)

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.

An example of a '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.

#### Parameters

simple | the GSimpleAction |
value | the requested value for the state. | [allow-none]
user_data | user data set when the signal handler was connected. |

Flags: Run Last

Since 2.30