Interface ActionGroup
- All Superinterfaces:
Proxy
- All Known Subinterfaces:
RemoteActionGroup
- All Known Implementing Classes:
ActionGroup.ActionGroupImpl
,Application
,Application
,Application
,ApplicationWindow
,ApplicationWindow
,DBusActionGroup
,RemoteActionGroup.RemoteActionGroupImpl
,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, io.github.jwharm.javagi.base.Out<java.lang.Boolean>, io.github.jwharm.javagi.base.Out<org.gnome.glib.VariantType>, io.github.jwharm.javagi.base.Out<org.gnome.glib.VariantType>, io.github.jwharm.javagi.base.Out<org.gnome.glib.Variant>, io.github.jwharm.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, io.github.jwharm.javagi.base.Out<java.lang.Boolean>, io.github.jwharm.javagi.base.Out<org.gnome.glib.VariantType>, io.github.jwharm.javagi.base.Out<org.gnome.glib.VariantType>, io.github.jwharm.javagi.base.Out<org.gnome.glib.Variant>, io.github.jwharm.javagi.base.Out<org.gnome.glib.Variant>)
.
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
Functional interface declaration of theActionAddedCallback
callback.static interface
Functional interface declaration of theActionEnabledChangedCallback
callback.static class
The ActionGroupImpl type represents a native instance of the ActionGroup interface.static class
The virtual function table forGio.ActionGroup
.static interface
Functional interface declaration of theActionRemovedCallback
callback.static interface
Functional interface declaration of theActionStateChangedCallback
callback. -
Method Summary
Modifier and TypeMethodDescriptiondefault void
actionAdded
(String actionName) Emits theGio.ActionGroup::action-added
signal on this ActionGroup.default void
actionEnabledChanged
(String actionName, boolean enabled) Emits theGio.ActionGroup::action-enabled-changed
signal on this ActionGroup.default void
actionRemoved
(String actionName) Emits theGio.ActionGroup::action-removed
signal on this ActionGroup.default void
actionStateChanged
(String actionName, Variant state) Emits theGio.ActionGroup::action-state-changed
signal on this ActionGroup.default void
activateAction
(String actionName, @Nullable Variant parameter) Activate the named action within this ActionGroup.default void
changeActionState
(String actionName, Variant value) Request for the state of the named action within this ActionGroup to be changed tovalue
.default void
emitActionAdded
(@Nullable String detail, String actionName) Emits the "action-added" signal.default void
emitActionEnabledChanged
(@Nullable String detail, String actionName, boolean enabled) Emits the "action-enabled-changed" signal.default void
emitActionRemoved
(@Nullable String detail, String actionName) Emits the "action-removed" signal.default void
emitActionStateChanged
(@Nullable String detail, String actionName, Variant value) Emits the "action-state-changed" signal.default boolean
getActionEnabled
(String actionName) Checks if the named action within this ActionGroup is currently enabled.default VariantType
getActionParameterType
(String actionName) Queries the type of the parameter that must be given when activating the named action within this ActionGroup.default Variant
getActionState
(String actionName) Queries the current state of the named action within this ActionGroup.default Variant
getActionStateHint
(String actionName) Requests a hint about the valid range of values for the state of the named action within this ActionGroup.default VariantType
getActionStateType
(String actionName) Queries the type of the state of the named action within this ActionGroup.static Type
getType()
Get the GType of the ActionGroup classdefault boolean
Checks if the named action exists within this ActionGroup.default String[]
Lists the actions contained within this ActionGroup.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 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 this ActionGroup.
-
Method Details
-
getType
-
actionAdded
Emits theGio.ActionGroup::action-added
signal on this ActionGroup.This function should only be called by
Gio.ActionGroup
implementations.- Parameters:
actionName
- the name of an action in the group
-
actionEnabledChanged
Emits theGio.ActionGroup::action-enabled-changed
signal on this ActionGroup.This function should only be called by
Gio.ActionGroup
implementations.- Parameters:
actionName
- the name of an action in the groupenabled
- whether the action is now enabled
-
actionRemoved
Emits theGio.ActionGroup::action-removed
signal on this ActionGroup.This function should only be called by
Gio.ActionGroup
implementations.- Parameters:
actionName
- the name of an action in the group
-
actionStateChanged
Emits theGio.ActionGroup::action-state-changed
signal on this ActionGroup.This function should only be called by
Gio.ActionGroup
implementations.- Parameters:
actionName
- the name of an action in the groupstate
- the new state of the named action
-
activateAction
Activate the named action within this 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 thenparameter
must beNULL
. SeegetActionParameterType(java.lang.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(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
-
changeActionState
Request for the state of the named action within this ActionGroup to be changed tovalue
.The action must be stateful and
value
must 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
value
GVariant is floating, it is consumed.- Parameters:
actionName
- the name of the action to request the change onvalue
- the new state
-
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
-
getActionParameterType
Queries the type of the parameter that must be given when activating the named action within this ActionGroup.When activating the action using
activateAction(java.lang.String, org.gnome.glib.Variant)
, theGLib.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 anyGLib.Variant
, butNULL
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
-
getActionState
Queries the current state of the named action within this 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 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
-
getActionStateHint
Requests a hint about the valid range of values for the state of the named action within this 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 aGLib.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 withVariant.unref()
when it is no longer required.- Parameters:
actionName
- the name of the action to query- Returns:
- the state range hint
-
getActionStateType
Queries the type of the state of the named action within this ActionGroup.If the action is stateful then this function returns the
GLib.VariantType
of the state. All calls tochangeActionState(java.lang.String, org.gnome.glib.Variant)
must give aGLib.Variant
of this type andgetActionState(java.lang.String)
will return aGLib.Variant
of the same type.If the action is not stateful then this function will return
NULL
. In that case,getActionState(java.lang.String)
will returnNULL
and 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
-
hasAction
Checks if the named action exists within this ActionGroup.- Parameters:
actionName
- the name of the action to check for- Returns:
- whether the named action exists
-
listActions
Lists the actions contained within this ActionGroup.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
-
queryAction
default boolean queryAction(String actionName, Out<Boolean> enabled, @Nullable @Nullable Out<VariantType> parameterType, @Nullable @Nullable Out<VariantType> stateType, @Nullable @Nullable Out<Variant> stateHint, @Nullable @Nullable Out<Variant> state) Queries all aspects of the named action within an this ActionGroup.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.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 groupenabled
- if the action is presently enabledparameterType
- the parameter type, orNULL
if none neededstateType
- the state type, orNULL
if statelessstateHint
- the state hint, orNULL
if nonestate
- the current state, orNULL
if stateless- Returns:
TRUE
if the action exists, elseFALSE
-
onActionAdded
default SignalConnection<ActionGroup.ActionAddedCallback> onActionAdded(@Nullable @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
- See Also:
-
emitActionAdded
Emits the "action-added" signal. SeeonActionAdded(java.lang.String, org.gnome.gio.ActionGroup.ActionAddedCallback)
. -
onActionEnabledChanged
default SignalConnection<ActionGroup.ActionEnabledChangedCallback> onActionEnabledChanged(@Nullable @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
- See Also:
-
emitActionEnabledChanged
default void emitActionEnabledChanged(@Nullable @Nullable String detail, String actionName, boolean enabled) Emits the "action-enabled-changed" signal. SeeonActionEnabledChanged(java.lang.String, org.gnome.gio.ActionGroup.ActionEnabledChangedCallback)
. -
onActionRemoved
default SignalConnection<ActionGroup.ActionRemovedCallback> onActionRemoved(@Nullable @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
- See Also:
-
emitActionRemoved
Emits the "action-removed" signal. SeeonActionRemoved(java.lang.String, org.gnome.gio.ActionGroup.ActionRemovedCallback)
. -
onActionStateChanged
default SignalConnection<ActionGroup.ActionStateChangedCallback> onActionStateChanged(@Nullable @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
- See Also:
-
emitActionStateChanged
default void emitActionStateChanged(@Nullable @Nullable String detail, String actionName, Variant value) Emits the "action-state-changed" signal. SeeonActionStateChanged(java.lang.String, org.gnome.gio.ActionGroup.ActionStateChangedCallback)
.
-