Class SimpleAction

All Implemented Interfaces:
Action, Proxy

@Generated("org.javagi.JavaGI") public class SimpleAction extends GObject implements Action
A GSimpleAction is the obvious simple implementation of the Action interface. This is the easiest way to create an action for purposes of adding it to a SimpleActionGroup.
  • Constructor Details

    • SimpleAction

      public SimpleAction(MemorySegment address)
      Create a SimpleAction instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • SimpleAction

      public SimpleAction(String name, @Nullable VariantType parameterType)

      Creates a new action.

      The created action is stateless. See g_simple_action_new_stateful() to create an action that has state.

      Parameters:
      name - the name of the action
      parameterType - the type of parameter that will be passed to handlers for the GSimpleAction::activate signal, or null for no parameter
      Since:
      2.28
    • SimpleAction

      public SimpleAction()
      Create a new SimpleAction.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the SimpleAction class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected SimpleAction asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class GObject
      Returns:
      the instance as if it were its parent type
    • stateful

      public static SimpleAction stateful(String name, @Nullable VariantType parameterType, Variant state)

      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.

      Parameters:
      name - the name of the action
      parameterType - the type of the parameter that will be passed to handlers for the GSimpleAction::activate signal, or null for no parameter
      state - the initial state of the action
      Returns:
      a new GSimpleAction
      Since:
      2.28
    • setEnabled

      public void setEnabled(boolean 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:
      enabled - whether the action is enabled
      Since:
      2.28
    • setState

      public void setState(Variant 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:
      value - the new GVariant for the state
      Since:
      2.30
    • setStateHint

      public void setStateHint(@Nullable Variant stateHint)

      Sets the state hint for the action.

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

      Parameters:
      stateHint - a GVariant representing the state hint
      Since:
      2.44
    • onActivate

      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 null parameter type is to toggle them via the GSimpleAction::change-state signal. For stateful actions where the state type is equal to the parameter type, the default is to forward them directly to GSimpleAction::change-state. This should allow almost all users of GSimpleAction to connect only one handler or the other.

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      Since:
      2.28
      See Also:
    • emitActivate

      public void emitActivate(@Nullable Variant parameter)
      Emits the "activate" signal. See onActivate(SimpleAction.ActivateCallback).
    • onChangeState

      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 g_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 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:

      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:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      Since:
      2.30
      See Also:
    • emitChangeState

      public void emitChangeState(@Nullable Variant value)
      Emits the "change-state" signal. See onChangeState(SimpleAction.ChangeStateCallback).
    • builder

      public static SimpleAction.Builder<? extends SimpleAction.Builder> builder()
      A SimpleAction.Builder object constructs a SimpleAction with the specified properties. Use the various set...() methods to set properties, and finish construction with SimpleAction.Builder.build().
      Returns:
      the builder object