Interface ActionGroup

All Superinterfaces:
Proxy
All Known Subinterfaces:
RemoteActionGroup
All Known Implementing Classes:
ActionGroup.ActionGroup$Impl, Application, Application, Application, ApplicationWindow, ApplicationWindow, DBusActionGroup, RemoteActionGroup.RemoteActionGroup$Impl, SimpleActionGroup

@Generated("org.javagi.JavaGI") public interface ActionGroup extends Proxy

GActionGroup represents a group of actions.

Actions can be used to expose functionality in a structured way, either from one part of a program to another, or to the outside world. Action groups are often used together with a Gio.MenuModel that provides additional representation data for displaying the actions to the user, e.g. in a menu.

The main way to interact with the actions in a GActionGroup is to activate them with activateAction(String, Variant). Activating an action may require a GLib.Variant parameter. The required type of the parameter can be inquired with getActionParameterType(String). Actions may be disabled, see getActionEnabled(String). Activating a disabled action has no effect.

Actions may optionally have a state in the form of a GLib.Variant. The current state of an action can be inquired with getActionState(String). Activating a stateful action may change its state, but it is also possible to set the state by calling changeActionState(String, Variant).

As typical example, consider a text editing application which has an option to change the current font to ‘bold’. A good way to represent this would be a stateful action, with a boolean state. Activating the action would toggle the state.

Each action in the group has a unique name (which is a string). All method calls, except listActions() take the name of an action as an argument.

The GActionGroup API is meant to be the ‘public’ API to the action group. The calls here are exactly the interaction that ‘external forces’ (eg: UI, incoming D-Bus messages, etc.) are supposed to have with actions. ‘Internal’ APIs (ie: ones meant only to be accessed by the action group implementation) are found on subclasses. This is why you will find – for example – getActionEnabled(String) but not an equivalent set_action_enabled() method.

Signals are emitted on the action group in response to state changes on individual actions.

Implementations of GActionGroup should provide implementations for the virtual functions listActions() and queryAction(String, Out, Out, Out, Out, Out). The other virtual functions should not be implemented — their ‘wrappers’ are actually implemented with calls to queryAction(String, Out, Out, Out, Out, Out).

  • Method Details

    • getType

      static @Nullable Type getType()
      Get the GType of the ActionGroup class.
      Returns:
      the GType
    • actionAdded

      default void actionAdded(String actionName)

      Emits the Gio.ActionGroup::action-added signal on actionGroup.

      This function should only be called by Gio.ActionGroup implementations.

      Parameters:
      actionName - the name of an action in the group
      Since:
      2.28
    • actionEnabledChanged

      default void actionEnabledChanged(String actionName, boolean enabled)

      Emits the Gio.ActionGroup::action-enabled-changed signal on actionGroup.

      This function should only be called by Gio.ActionGroup implementations.

      Parameters:
      actionName - the name of an action in the group
      enabled - whether the action is now enabled
      Since:
      2.28
    • actionRemoved

      default void actionRemoved(String actionName)

      Emits the Gio.ActionGroup::action-removed signal on actionGroup.

      This function should only be called by Gio.ActionGroup implementations.

      Parameters:
      actionName - the name of an action in the group
      Since:
      2.28
    • actionStateChanged

      default void actionStateChanged(String actionName, Variant state)

      Emits the Gio.ActionGroup::action-state-changed signal on actionGroup.

      This function should only be called by Gio.ActionGroup implementations.

      Parameters:
      actionName - the name of an action in the group
      state - the new state of the named action
      Since:
      2.28
    • activateAction

      default void activateAction(String actionName, @Nullable Variant parameter)

      Activate the named action within actionGroup.

      If the action is expecting a parameter, then the correct type of parameter must be given as parameter. If the action is expecting no parameters then parameter must be NULL. See getActionParameterType(String).

      If the Gio.ActionGroup implementation supports asynchronous remote activation over D-Bus, this call may return before the relevant D-Bus traffic has been sent, or any replies have been received. In order to block on such asynchronous activation calls, DBusConnection.flush(Cancellable, AsyncReadyCallback) should be called prior to the code, which depends on the result of the action activation. Without flushing the D-Bus connection, there is no guarantee that the action would have been activated.

      The following code which runs in a remote app instance, shows an example of a ‘quit’ action being activated on the primary app instance over D-Bus. Here DBusConnection.flush(Cancellable, AsyncReadyCallback) is called before exit(). Without g_dbus_connection_flush(), the ‘quit’ action may fail to be activated on the primary instance.

      // call ‘quit’ action on primary instance
      g_action_group_activate_action (G_ACTION_GROUP (app), "quit", NULL);
      
      // make sure the action is activated now
      g_dbus_connection_flush (…);
      
      g_debug ("Application has been terminated. Exiting.");
      
      exit (0);
      
      Parameters:
      actionName - the name of the action to activate
      parameter - parameters to the activation
      Since:
      2.28
    • changeActionState

      default void changeActionState(String actionName, Variant value)

      Request for the state of the named action within this ActionGroup to be changed to value.

      The action must be stateful and value must be of the correct type. See getActionStateType(String).

      This call merely requests a change. The action may refuse to change its state or may change its state to something other than value. See getActionStateHint(String).

      If the value GVariant is floating, it is consumed.

      Parameters:
      actionName - the name of the action to request the change on
      value - the new state
      Since:
      2.28
    • getActionEnabled

      default boolean getActionEnabled(String actionName)

      Checks if the named action within this ActionGroup is currently enabled.

      An action must be enabled in order to be activated or in order to have its state changed from outside callers.

      Parameters:
      actionName - the name of the action to query
      Returns:
      whether the action is currently enabled
      Since:
      2.28
    • getActionParameterType

      default @Nullable VariantType getActionParameterType(String actionName)

      Queries the type of the parameter that must be given when activating the named action within actionGroup.

      When activating the action using activateAction(String, Variant), the GLib.Variant given to that function must be of the type returned by this function.

      In the case that this function returns NULL, you must not give any GLib.Variant, but NULL instead.

      The parameter type of a particular action will never change but it is possible for an action to be removed and for a new action to be added with the same name but a different parameter type.

      Parameters:
      actionName - the name of the action to query
      Returns:
      the parameter type
      Since:
      2.28
    • getActionState

      default @Nullable Variant getActionState(String actionName)

      Queries the current state of the named action within actionGroup.

      If the action is not stateful then NULL will be returned. If the action is stateful then the type of the return value is the type given by getActionStateType(String).

      The return value (if non-NULL) should be freed with Variant#unref when it is no longer required.

      Parameters:
      actionName - the name of the action to query
      Returns:
      the current state of the action
      Since:
      2.28
    • getActionStateHint

      default @Nullable Variant getActionStateHint(String actionName)

      Requests a hint about the valid range of values for the state of the named action within actionGroup.

      If NULL is returned it either means that the action is not stateful or that there is no hint about the valid range of values for the state of the action.

      If a GLib.Variant array is returned then each item in the array is a possible value for the state. If a GLib.Variant pair (ie: two-tuple) is returned then the tuple specifies the inclusive lower and upper bound of valid values for the state.

      In any case, the information is merely a hint. It may be possible to have a state value outside of the hinted range and setting a value within the range may fail.

      The return value (if non-NULL) should be freed with Variant#unref when it is no longer required.

      Parameters:
      actionName - the name of the action to query
      Returns:
      the state range hint
      Since:
      2.28
    • getActionStateType

      default @Nullable VariantType getActionStateType(String actionName)

      Queries the type of the state of the named action within actionGroup.

      If the action is stateful then this function returns the GLib.VariantType of the state. All calls to changeActionState(String, Variant) must give a GLib.Variant of this type and getActionState(String) will return a GLib.Variant of the same type.

      If the action is not stateful then this function will return NULL. In that case, getActionState(String) will return NULL and you must not call changeActionState(String, Variant).

      The state type of a particular action will never change but it is possible for an action to be removed and for a new action to be added with the same name but a different state type.

      Parameters:
      actionName - the name of the action to query
      Returns:
      the state type, if the action is stateful
      Since:
      2.28
    • hasAction

      default boolean hasAction(String actionName)
      Checks if the named action exists within actionGroup.
      Parameters:
      actionName - the name of the action to check for
      Returns:
      whether the named action exists
      Since:
      2.28
    • listActions

      default String[] listActions()

      Lists the actions contained within actionGroup.

      The caller is responsible for freeing the list with GLib#strfreev when it is no longer required.

      Returns:
      a NULL-terminated array of the names of the actions in the group
      Since:
      2.28
    • queryAction

      default boolean queryAction(String actionName, Out<Boolean> enabled, @Nullable Out<VariantType> parameterType, @Nullable Out<VariantType> stateType, @Nullable Out<Variant> stateHint, @Nullable Out<Variant> state)

      Queries all aspects of the named action within an actionGroup.

      This function acquires the information available from hasAction(String), getActionEnabled(String), getActionParameterType(String), getActionStateType(String), getActionStateHint(String) and getActionState(String) with a single function call.

      This provides two main benefits.

      The first is the improvement in efficiency that comes with not having to perform repeated lookups of the action in order to discover different things about it. The second is that implementing Gio.ActionGroup can now be done by only overriding this one virtual function.

      The interface provides a default implementation of this function that calls the individual functions, as required, to fetch the information. The interface also provides default implementations of those functions that call this function. All implementations, therefore, must override either this function or all of the others.

      If the action exists, TRUE is returned and any of the requested fields (as indicated by having a non-NULL reference passed in) are filled. If the action doesn’t exist, FALSE is returned and the fields may or may not have been modified.

      Parameters:
      actionName - the name of an action in the group
      enabled - if the action is presently enabled
      parameterType - the parameter type, or NULL if none needed
      stateType - the state type, or NULL if stateless
      stateHint - the state hint, or NULL if none
      state - the current state, or NULL if stateless
      Returns:
      TRUE if the action exists, else FALSE
      Since:
      2.32
    • onActionAdded

      default SignalConnection<ActionGroup.ActionAddedCallback> onActionAdded(@Nullable String detail, ActionGroup.ActionAddedCallback handler)

      Signals that a new action was just added to the group.

      This signal is emitted after the action has been added and is now visible.

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

      default void emitActionAdded(@Nullable String detail, String actionName)
      Emits the "action-added" signal. See onActionAdded(String, ActionGroup.ActionAddedCallback).
    • onActionEnabledChanged

      Signals that the enabled status of the named action has changed.
      Parameters:
      detail - the signal detail
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      Since:
      2.28
      See Also:
    • emitActionEnabledChanged

      default void emitActionEnabledChanged(@Nullable String detail, String actionName, boolean enabled)
      Emits the "action-enabled-changed" signal. See onActionEnabledChanged(String, ActionGroup.ActionEnabledChangedCallback).
    • onActionRemoved

      default SignalConnection<ActionGroup.ActionRemovedCallback> onActionRemoved(@Nullable String detail, ActionGroup.ActionRemovedCallback handler)

      Signals that an action is just about to be removed from the group.

      This signal is emitted before the action is removed, so the action is still visible and can be queried from the signal handler.

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

      default void emitActionRemoved(@Nullable String detail, String actionName)
      Emits the "action-removed" signal. See onActionRemoved(String, ActionGroup.ActionRemovedCallback).
    • onActionStateChanged

      Signals that the state of the named action has changed.
      Parameters:
      detail - the signal detail
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      Since:
      2.28
      See Also:
    • emitActionStateChanged

      default void emitActionStateChanged(@Nullable String detail, String actionName, @Nullable Variant value)
      Emits the "action-state-changed" signal. See onActionStateChanged(String, ActionGroup.ActionStateChangedCallback).