Class SimpleAction
GSimpleAction
is the obvious simple implementation of the
Action
interface. This is the easiest way to create an action for
purposes of adding it to a SimpleActionGroup
.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Functional interface declaration of theActivateCallback
callback.static class
SimpleAction.Builder<B extends SimpleAction.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.static interface
Functional interface declaration of theChangeStateCallback
callback.Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
Nested classes/interfaces inherited from interface org.gnome.gio.Action
Action.ActionImpl, Action.ActionInterface
-
Constructor Summary
ConstructorDescriptionSimpleAction
(MemorySegment address) Create a SimpleAction proxy instance for the provided memory address.SimpleAction
(String name, @Nullable VariantType parameterType) Creates a new action. -
Method Summary
Modifier and TypeMethodDescriptionprotected SimpleAction
asParent()
Returns this instance as if it were its parent type.static SimpleAction.Builder
<? extends SimpleAction.Builder> builder()
ASimpleAction.Builder
object constructs aSimpleAction
with the specified properties.void
emitActivate
(@Nullable Variant parameter) Emits the "activate" signal.void
emitChangeState
(@Nullable Variant value) Emits the "change-state" signal.static Type
getType()
Get the GType of the SimpleAction classonActivate
(SimpleAction.ActivateCallback handler) Indicates that the action was just activated.Indicates that the action just received a request to change its state.void
setEnabled
(boolean enabled) Sets the action as enabled or not.void
Sets the state of the action.void
setStateHint
(@Nullable Variant stateHint) Sets the state hint for the action.static SimpleAction
stateful
(String name, @Nullable VariantType parameterType, Variant state) Creates a new stateful action.Methods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getMemoryLayout, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newInstance, newInstance, newv, notify_, notify_, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withProperties
Methods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, getPrivate, readGClass, writeGClass
Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.gnome.gio.Action
activate, changeState, getEnabled, getName, getParameterType, getState, getStateHint, getStateType
-
Constructor Details
-
SimpleAction
Create a SimpleAction proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
SimpleAction
Creates a new action.The created action is stateless. See g_simple_action_new_stateful() to create an action that has state.
- Parameters:
name
- the name of the actionparameterType
- the type of parameter that will be passed to handlers for theGSimpleAction
::activate signal, ornull
for no parameter
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuper
keyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()
doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName()
. This will call the native function pointer of this virtual method in the typeclass of the parent type. -
stateful
public static SimpleAction stateful(String name, @Nullable @Nullable VariantType parameterType, Variant state) Creates a new stateful action.All future state values must have the same
GVariantType
as the initialstate
.If the
state
GVariant
is floating, it is consumed.- Parameters:
name
- the name of the actionparameterType
- the type of the parameter that will be passed to handlers for theGSimpleAction
::activate signal, ornull
for no parameterstate
- the initial state of the action- Returns:
- a new
GSimpleAction
-
setEnabled
public void setEnabled(boolean enabled) Sets the action as enabled or not.An action must be enabled in order to be activated or in order to have its state changed from outside callers.
This should only be called by the implementor of the action. Users of the action should not attempt to modify its enabled flag.
- Parameters:
enabled
- whether the action is enabled
-
setState
Sets the state of the action.This directly updates the 'state' property to the given value.
This should only be called by the implementor of the action. Users of the action should not attempt to directly modify the 'state' property. Instead, they should call g_action_change_state() to request the change.
If the
value
GVariant is floating, it is consumed.- Parameters:
value
- the newGVariant
for the state
-
setStateHint
Sets the state hint for the action.See g_action_get_state_hint() for more information about action state hints.
- Parameters:
stateHint
- aGVariant
representing the state hint
-
onActivate
public SignalConnection<SimpleAction.ActivateCallback> 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 theGSimpleAction
::change-state signal. For stateful actions where the state type is equal to the parameter type, the default is to forward them directly toGSimpleAction
::change-state. This should allow almost all users ofGSimpleAction
to connect only one handler or the other.- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitActivate
Emits the "activate" signal. SeeonActivate(org.gnome.gio.SimpleAction.ActivateCallback)
. -
onChangeState
public SignalConnection<SimpleAction.ChangeStateCallback> 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:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitChangeState
Emits the "change-state" signal. SeeonChangeState(org.gnome.gio.SimpleAction.ChangeStateCallback)
. -
builder
ASimpleAction.Builder
object constructs aSimpleAction
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withSimpleAction.Builder.build()
.
-