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
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(java.lang.String, org.gnome.glib.Variant). Activating an
action may require a GLib.Variant parameter. The required type of the
parameter can be inquired with getActionParameterType(java.lang.String).
Actions may be disabled, see getActionEnabled(java.lang.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(java.lang.String).
Activating a stateful action may change its state, but it is also possible to
set the state by calling changeActionState(java.lang.String, org.gnome.glib.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(java.lang.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(java.lang.String, org.javagi.base.Out<java.lang.Boolean>, org.javagi.base.Out<org.gnome.glib.VariantType>, org.javagi.base.Out<org.gnome.glib.VariantType>, org.javagi.base.Out<org.gnome.glib.Variant>, org.javagi.base.Out<org.gnome.glib.Variant>). The other virtual functions should
not be implemented — their ‘wrappers’ are actually implemented with
calls to queryAction(java.lang.String, org.javagi.base.Out<java.lang.Boolean>, org.javagi.base.Out<org.gnome.glib.VariantType>, org.javagi.base.Out<org.gnome.glib.VariantType>, org.javagi.base.Out<org.gnome.glib.Variant>, org.javagi.base.Out<org.gnome.glib.Variant>).
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceFunctional interface declaration of theActionAddedCallbackcallback.static interfaceFunctional interface declaration of theActionEnabledChangedCallbackcallback.static classThe ActionGroup$Impl type represents a native instance of the ActionGroup interface.static classThe virtual function table forGio.ActionGroup.static interfaceFunctional interface declaration of theActionRemovedCallbackcallback.static interfaceFunctional interface declaration of theActionStateChangedCallbackcallback. -
Method Summary
Modifier and TypeMethodDescriptiondefault voidactionAdded(String actionName) Emits theGio.ActionGroup::action-addedsignal onactionGroup.default voidactionEnabledChanged(String actionName, boolean enabled) Emits theGio.ActionGroup::action-enabled-changedsignal onactionGroup.default voidactionRemoved(String actionName) Emits theGio.ActionGroup::action-removedsignal onactionGroup.default voidactionStateChanged(String actionName, Variant state) Emits theGio.ActionGroup::action-state-changedsignal onactionGroup.default voidactivateAction(String actionName, @Nullable Variant parameter) Activate the named action withinactionGroup.default voidchangeActionState(String actionName, Variant value) Request for the state of the named action within this ActionGroup to be changed tovalue.default voidemitActionAdded(@Nullable String detail, String actionName) Emits the "action-added" signal.default voidemitActionEnabledChanged(@Nullable String detail, String actionName, boolean enabled) Emits the "action-enabled-changed" signal.default voidemitActionRemoved(@Nullable String detail, String actionName) Emits the "action-removed" signal.default voidemitActionStateChanged(@Nullable String detail, String actionName, @Nullable Variant value) Emits the "action-state-changed" signal.default booleangetActionEnabled(String actionName) Checks if the named action within this ActionGroup is currently enabled.default @Nullable VariantTypegetActionParameterType(String actionName) Queries the type of the parameter that must be given when activating the named action withinactionGroup.default @Nullable VariantgetActionState(String actionName) Queries the current state of the named action withinactionGroup.default @Nullable VariantgetActionStateHint(String actionName) Requests a hint about the valid range of values for the state of the named action withinactionGroup.default @Nullable VariantTypegetActionStateType(String actionName) Queries the type of the state of the named action withinactionGroup.static @Nullable TypegetType()Get the GType of the ActionGroup classdefault booleanChecks if the named action exists withinactionGroup.default String[]Lists the actions contained withinactionGroup.onActionAdded(@Nullable String detail, ActionGroup.ActionAddedCallback handler) Signals that a new action was just added to the group.onActionEnabledChanged(@Nullable String detail, ActionGroup.ActionEnabledChangedCallback handler) Signals that the enabled status of the named action has changed.onActionRemoved(@Nullable String detail, ActionGroup.ActionRemovedCallback handler) Signals that an action is just about to be removed from the group.onActionStateChanged(@Nullable String detail, ActionGroup.ActionStateChangedCallback handler) Signals that the state of the named action has changed.default booleanqueryAction(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 anactionGroup.
-
Method Details
-
getType
-
actionAdded
Emits theGio.ActionGroup::action-addedsignal onactionGroup.This function should only be called by
Gio.ActionGroupimplementations.- Parameters:
actionName- the name of an action in the group- Since:
- 2.28
-
actionEnabledChanged
Emits theGio.ActionGroup::action-enabled-changedsignal onactionGroup.This function should only be called by
Gio.ActionGroupimplementations.- Parameters:
actionName- the name of an action in the groupenabled- whether the action is now enabled- Since:
- 2.28
-
actionRemoved
Emits theGio.ActionGroup::action-removedsignal onactionGroup.This function should only be called by
Gio.ActionGroupimplementations.- Parameters:
actionName- the name of an action in the group- Since:
- 2.28
-
actionStateChanged
Emits theGio.ActionGroup::action-state-changedsignal onactionGroup.This function should only be called by
Gio.ActionGroupimplementations.- Parameters:
actionName- the name of an action in the groupstate- the new state of the named action- Since:
- 2.28
-
activateAction
Activate the named action withinactionGroup.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 thenparametermust beNULL. SeegetActionParameterType(java.lang.String).If the
Gio.ActionGroupimplementation 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(org.gnome.gio.Cancellable, org.gnome.gio.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(org.gnome.gio.Cancellable, org.gnome.gio.AsyncReadyCallback)is called beforeexit(). Withoutg_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 activateparameter- parameters to the activation- Since:
- 2.28
-
changeActionState
Request for the state of the named action within this ActionGroup to be changed tovalue.The action must be stateful and
valuemust be of the correct type. SeegetActionStateType(java.lang.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.SeegetActionStateHint(java.lang.String).If the
valueGVariant is floating, it is consumed.- Parameters:
actionName- the name of the action to request the change onvalue- the new state- Since:
- 2.28
-
getActionEnabled
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
Queries the type of the parameter that must be given when activating the named action withinactionGroup.When activating the action using
activateAction(java.lang.String, org.gnome.glib.Variant), theGLib.Variantgiven to that function must be of the type returned by this function.In the case that this function returns
NULL, you must not give anyGLib.Variant, butNULLinstead.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
Queries the current state of the named action withinactionGroup.If the action is not stateful then
NULLwill be returned. If the action is stateful then the type of the return value is the type given bygetActionStateType(java.lang.String).The return value (if non-
NULL) should be freed withVariant.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
Requests a hint about the valid range of values for the state of the named action withinactionGroup.If
NULLis 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.Variantarray is returned then each item in the array is a possible value for the state. If aGLib.Variantpair (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 withVariant.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
Queries the type of the state of the named action withinactionGroup.If the action is stateful then this function returns the
GLib.VariantTypeof the state. All calls tochangeActionState(java.lang.String, org.gnome.glib.Variant)must give aGLib.Variantof this type andgetActionState(java.lang.String)will return aGLib.Variantof the same type.If the action is not stateful then this function will return
NULL. In that case,getActionState(java.lang.String)will returnNULLand you must not callchangeActionState(java.lang.String, org.gnome.glib.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
Checks if the named action exists withinactionGroup.- Parameters:
actionName- the name of the action to check for- Returns:
- whether the named action exists
- Since:
- 2.28
-
listActions
Lists the actions contained withinactionGroup.The caller is responsible for freeing the list with
GLib.strfreev(java.lang.foreign.MemorySegment)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 anactionGroup.This function acquires the information available from
hasAction(java.lang.String),getActionEnabled(java.lang.String),getActionParameterType(java.lang.String),getActionStateType(java.lang.String),getActionStateHint(java.lang.String)andgetActionState(java.lang.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.ActionGroupcan 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,
TRUEis returned and any of the requested fields (as indicated by having a non-NULLreference passed in) are filled. If the action doesn’t exist,FALSEis returned and the fields may or may not have been modified.- Parameters:
actionName- the name of an action in the groupenabled- if the action is presently enabledparameterType- the parameter type, orNULLif none neededstateType- the state type, orNULLif statelessstateHint- the state hint, orNULLif nonestate- the current state, orNULLif stateless- Returns:
TRUEif the action exists, elseFALSE- 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 detailhandler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- Since:
- 2.28
- See Also:
-
emitActionAdded
Emits the "action-added" signal. SeeonActionAdded(java.lang.String, org.gnome.gio.ActionGroup.ActionAddedCallback). -
onActionEnabledChanged
default SignalConnection<ActionGroup.ActionEnabledChangedCallback> onActionEnabledChanged(@Nullable String detail, ActionGroup.ActionEnabledChangedCallback handler) Signals that the enabled status of the named action has changed.- Parameters:
detail- the signal detailhandler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- Since:
- 2.28
- See Also:
-
emitActionEnabledChanged
Emits the "action-enabled-changed" signal. SeeonActionEnabledChanged(java.lang.String, org.gnome.gio.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 detailhandler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- Since:
- 2.28
- See Also:
-
emitActionRemoved
Emits the "action-removed" signal. SeeonActionRemoved(java.lang.String, org.gnome.gio.ActionGroup.ActionRemovedCallback). -
onActionStateChanged
default SignalConnection<ActionGroup.ActionStateChangedCallback> onActionStateChanged(@Nullable String detail, ActionGroup.ActionStateChangedCallback handler) Signals that the state of the named action has changed.- Parameters:
detail- the signal detailhandler- 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. SeeonActionStateChanged(java.lang.String, org.gnome.gio.ActionGroup.ActionStateChangedCallback).
-