Class SimpleAction.Builder<B extends SimpleAction.Builder<B>>

Type Parameters:
B - the type of the Builder that is returned
All Implemented Interfaces:
Action.Builder<B>, BuilderInterface
Enclosing class:
SimpleAction

public static class SimpleAction.Builder<B extends SimpleAction.Builder<B>> extends GObject.Builder<B> implements Action.Builder<B>
Inner class implementing a builder pattern to construct a GObject with properties.
  • Constructor Details

    • Builder

      protected Builder()
      Default constructor for a Builder object.
  • Method Details

    • build

      public SimpleAction build()
      Finish building the SimpleAction object. This will call GObject.withProperties(Type, String[], Value[]) to create a new GObject instance, which is then cast to SimpleAction.
      Overrides:
      build in class GObject.Builder<B extends SimpleAction.Builder<B>>
      Returns:
      a new instance of SimpleAction with the properties that were set in the Builder object.
    • setEnabled

      public B setEnabled(boolean enabled)

      If action is currently enabled.

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

      Parameters:
      enabled - the value for the enabled property
      Returns:
      the Builder instance is returned, to allow method chaining
      Since:
      2.28
    • setName

      public B setName(String name)
      The name of the action. This is mostly meaningful for identifying the action once it has been added to a GSimpleActionGroup.
      Parameters:
      name - the value for the name property
      Returns:
      the Builder instance is returned, to allow method chaining
      Since:
      2.28
    • setParameterType

      public B setParameterType(VariantType parameterType)
      The type of the parameter that must be given when activating the action.
      Parameters:
      parameterType - the value for the parameter-type property
      Returns:
      the Builder instance is returned, to allow method chaining
      Since:
      2.28
    • setState

      public B setState(Variant state)
      The state of the action, or null if the action is stateless.
      Parameters:
      state - the value for the state property
      Returns:
      the Builder instance is returned, to allow method chaining
      Since:
      2.28
    • onActivate

      public B onActivate(SimpleAction.ActivateCallback handler)

      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:
      the Builder instance is returned, to allow method chaining
      Since:
      2.28
      See Also:
    • onChangeState

      public B onChangeState(SimpleAction.ChangeStateCallback handler)

      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:
      the Builder instance is returned, to allow method chaining
      Since:
      2.30
      See Also: