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
Nested ClassesModifier and TypeClassDescriptionstatic interfaceFunctional interface declaration of theActivateCallbackcallback.static classSimpleAction.Builder<B extends SimpleAction.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.static interfaceFunctional interface declaration of theChangeStateCallbackcallback.Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClassNested classes/interfaces inherited from interface org.gnome.gio.Action
Action.Action$Impl, Action.ActionInterface -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new SimpleAction.SimpleAction(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 SimpleActionasParent()Returns this instance as if it were its parent type.static SimpleAction.Builder<? extends SimpleAction.Builder> builder()ASimpleAction.Builderobject constructs aSimpleActionwith the specified properties.voidemitActivate(@Nullable Variant parameter) Emits the "activate" signal.voidemitChangeState(@Nullable Variant value) Emits the "change-state" signal.static @Nullable TypegetType()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.voidsetEnabled(boolean enabled) Sets the action as enabled or not.voidSets the state of the action.voidsetStateHint(@Nullable Variant stateHint) Sets the state hint for the action.static SimpleActionstateful(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, 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, withPropertiesMethods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class org.javagi.base.ProxyInstance
equals, handle, hashCodeMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods 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, ornullfor no parameter- Since:
- 2.28
-
SimpleAction
public SimpleAction()Creates a new SimpleAction.
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuperkeyword, 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 VariantType parameterType, Variant state) Creates a new stateful action.All future state values must have the same
GVariantTypeas the initialstate.If the
stateGVariantis 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, ornullfor no parameterstate- the initial state of the action- Returns:
- a new
GSimpleAction - Since:
- 2.28
-
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- Since:
- 2.28
-
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
valueGVariant is floating, it is consumed.- Parameters:
value- the newGVariantfor the state- Since:
- 2.30
-
setStateHint
Sets the state hint for the action.See g_action_get_state_hint() for more information about action state hints.
- Parameters:
stateHint- aGVariantrepresenting the state hint- Since:
- 2.44
-
onActivate
public SignalConnection<SimpleAction.ActivateCallback> onActivate(SimpleAction.ActivateCallback handler) Indicates that the action was just activated.parameterwill 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
nullparameter 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 ofGSimpleActionto connect only one handler or the other.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- Since:
- 2.28
- 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.valuewill 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
- Since:
- 2.30
- See Also:
-
emitChangeState
Emits the "change-state" signal. SeeonChangeState(org.gnome.gio.SimpleAction.ChangeStateCallback). -
builder
ASimpleAction.Builderobject constructs aSimpleActionwith the specified properties. Use the variousset...()methods to set properties, and finish construction withSimpleAction.Builder.build().- Returns:
- the builder object
-