
Gnome::Gio::R-ActionGroup
Description
Gnome::Gio::R-ActionGroup 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 Gnome::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 Gnome::Gio::R-ActionGroup is to activate them with .activate-action()
. Activating an action may require a Gnome::Glib::N-Variant parameter. The required type of the parameter can be inquired with .get-action-parameter-type()
. Actions may be disabled, see .get-action-enabled()
. Activating a disabled action has no effect.
Actions may optionally have a state in the form of a Gnome::Glib::N-Variant. The current state of an action can be inquired with .get-action-state()
. Activating a stateful action may change its state, but it is also possible to set the state by calling .change-action-state()
.
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 .list-actions()
take the name of an action as an argument.
The Gnome::Gio::R-ActionGroup 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 - .get-action-enabled()
but not an equivalent set() call.
Signals are emitted on the action group in response to state changes on individual actions.
Implementations of Gnome::Gio::R-ActionGroup should provide implementations for the virtual functions .list-actions()
and .query-action()
. The other virtual functions should not be implemented - their "wrappers" are actually implemented with calls to .query-action()
.
Methods
action-added
Emits the action-added signal on $action-group
.
This function should only be called by Gnome::Gio::R-ActionGroup implementations.
method action-added ( Str $action-name )
$action-name; the name of an action in the group.
action-enabled-changed
Emits the action-enabled-changed signal on $action-group
.
This function should only be called by Gnome::Gio::R-ActionGroup implementations.
method action-enabled-changed ( Str $action-name, Bool() $enabled )
$action-name; the name of an action in the group.
$enabled; whether or not the action is now enabled.
action-removed
Emits the action-removed signal on $action-group
.
This function should only be called by Gnome::Gio::R-ActionGroup implementations.
method action-removed ( Str $action-name )
$action-name; the name of an action in the group.
action-state-changed
Emits the action-state-changed signal on $action-group
.
This function should only be called by Gnome::Gio::R-ActionGroup implementations.
method action-state-changed ( Str $action-name, N-Object $state )
$action-name; the name of an action in the group.
$state; the new state of the named action
activate-action
Activate the named action within $action-group
.
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 undefined. See .get-action-parameter-type()
.
If the Gnome::Gio::R-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, g_dbus_connection_flush() 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 g_dbus_connection_flush() is called before exit()`. Without g_dbus_connection_flush(), the "quit" action may fail to be activated on the primary instance.
method activate-action ( Str $action-name, N-Object $parameter )
$action-name; the name of the action to activate.
$parameter; parameters to the activation
change-action-state
Request for the state of the named action within $action-group
to be changed to $value
.
The action must be stateful and $value
must be of the correct type. See .get-action-state-type()
.
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 .get-action-state-hint()
.
If the $value
GVariant is floating, it is consumed.
method change-action-state ( Str $action-name, N-Object $value )
$action-name; the name of the action to request the change on.
$value; the new state
get-action-enabled
Checks if the named action within $action-group
is currently enabled.
An action must be enabled in order to be activated or in order to have its state changed from outside callers.
method get-action-enabled ( Str $action-name --> Bool )
$action-name; the name of the action to query.
Return value; whether or not the action is currently enabled.
get-action-parameter-type
Queries the type of the parameter that must be given when activating the named action within $action-group
.
When activating the action using .activate-action()
, the Gnome::Glib::N-Variant given to that function must be of the type returned by this function.
In the case that this function returns undefined, you must not give any Gnome::Glib::N-Variant, but undefined 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.
method get-action-parameter-type ( Str $action-name --> N-Object )
$action-name; the name of the action to query.
Return value; the parameter type.
get-action-state
Queries the current state of the named action within $action-group
.
If the action is not stateful then undefined will be returned. If the action is stateful then the type of the return value is the type given by .get-action-state-type()
.
The return value (if non-undefined) should be freed with g_variant_unref() when it is no longer required.
method get-action-state ( Str $action-name --> N-Object )
$action-name; the name of the action to query.
Return value; the current state of the action.
get-action-state-hint
Requests a hint about the valid range of values for the state of the named action within $action-group
.
If undefined 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 Gnome::Glib::N-Variant array is returned then each item in the array is a possible value for the state. If a Gnome::Glib::N-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-undefined) should be freed with g_variant_unref() when it is no longer required.
method get-action-state-hint ( Str $action-name --> N-Object )
$action-name; the name of the action to query.
Return value; the state range hint.
get-action-state-type
Queries the type of the state of the named action within $action-group
.
If the action is stateful then this function returns the Gnome::Glib::N-VariantType of the state. All calls to .change-action-state()
must give a Gnome::Glib::N-Variant of this type and .get-action-state()
will return a Gnome::Glib::N-Variant of the same type.
If the action is not stateful then this function will return undefined. In that case, .get-action-state()
will return undefined and you must not call .change-action-state()
.
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.
method get-action-state-type ( Str $action-name --> N-Object )
$action-name; the name of the action to query.
Return value; the state type, if the action is stateful.
has-action
Checks if the named action exists within $action-group
.
method has-action ( Str $action-name --> Bool )
$action-name; the name of the action to check for.
Return value; whether the named action exists.
list-actions
Lists the actions contained within $action-group
.
The caller is responsible for freeing the list with g_strfreev() when it is no longer required.
method list-actions (--> Array[Str] )
Return value; a the array names of the actions in the group.
query-action
Queries all aspects of the named action within an $action-group
.
This function acquires the information available from .has-action()
, .get-action-enabled()
, .get-action-parameter-type()
, .get-action-state-type()
, .get-action-state-hint()
and .get-action-state()
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 Gnome::Gio::R-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-undefined reference passed in) are filled. If the action doesn't exist, False
is returned and the fields may or may not have been modified.
method query-action ( Str $action-name, Bool() $enabled, N-Object $parameter-type, N-Object $state-type, N-Object $state-hint, N-Object $state --> Bool )
$action-name; the name of an action in the group.
$enabled; (transfer ownership: full) if the action is presently enabled.
$parameter-type; the parameter type, or undefined if none needed
$state-type; the state type, or undefined if stateless
$state-hint; (transfer ownership: full) the state hint, or undefined if none
$state; (transfer ownership: full) the current state, or undefined if stateless
Return value; True
if the action exists, else False
.
Signals
action-added
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.
method handler ( Str $action-name, Int :$_handle_id, N-GObject :$_native-object, Gnome::Gio::ActionGroup :$_widget, *C<user>-options )
$action-name; the name of the action in
$action-group
.$_handle_id; The registered event handler id.
$_native-object; The native object provided by the Raku object which registered this event. This a native Gnome::Gio::ActionGroup object.
$_widget; The object which registered the signal. User code may have left the object going out of scope.
user
-options; A list of named arguments provided at the.register-signal()
method from Gnome::GObject::Object.
action-enabled-changed
Signals that the enabled status of the named action has changed.
method handler ( Str $action-name, gboolean $enabled, Int :$_handle_id, N-GObject :$_native-object, Gnome::Gio::ActionGroup :$_widget, *C<user>-options )
$action-name; the name of the action in
$action-group
.$enabled; whether the action is enabled or not.
$_handle_id; The registered event handler id.
$_native-object; The native object provided by the Raku object which registered this event. This a native Gnome::Gio::ActionGroup object.
$_widget; The object which registered the signal. User code may have left the object going out of scope.
user
-options; A list of named arguments provided at the.register-signal()
method from Gnome::GObject::Object.
action-removed
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.
method handler ( Str $action-name, Int :$_handle_id, N-GObject :$_native-object, Gnome::Gio::ActionGroup :$_widget, *C<user>-options )
$action-name; the name of the action in
$action-group
.$_handle_id; The registered event handler id.
$_native-object; The native object provided by the Raku object which registered this event. This a native Gnome::Gio::ActionGroup object.
$_widget; The object which registered the signal. User code may have left the object going out of scope.
user
-options; A list of named arguments provided at the.register-signal()
method from Gnome::GObject::Object.
action-state-changed
Signals that the state of the named action has changed.
method handler ( Str $action-name, $value, Int :$_handle_id, N-GObject :$_native-object, Gnome::Gio::ActionGroup :$_widget, *C<user>-options )
$action-name; the name of the action in
$action-group
.$value; the new value of the state.
$_handle_id; The registered event handler id.
$_native-object; The native object provided by the Raku object which registered this event. This a native Gnome::Gio::ActionGroup object.
$_widget; The object which registered the signal. User code may have left the object going out of scope.
user
-options; A list of named arguments provided at the.register-signal()
method from Gnome::GObject::Object.