Package ch.bailu.gtk.gtk
Class ShortcutController
java.lang.Object
ch.bailu.gtk.type.Type
ch.bailu.gtk.type.Pointer
ch.bailu.gtk.gobject.Object
ch.bailu.gtk.gtk.EventController
ch.bailu.gtk.gtk.ShortcutController
- All Implemented Interfaces:
PointerInterface
`GtkShortcutController` is an event controller that manages shortcuts.
Most common shortcuts are using this controller implicitly, e.g. by
adding a mnemonic underline to a `GtkLabel`, or by installing a key
binding using [method@Gtk.WidgetClass.add_binding], or by adding accelerators
to global actions using [method@Gtk.Application.set_accels_for_action].
But it is possible to create your own shortcut controller, and add
shortcuts to it.
`GtkShortcutController` implements `GListModel` for querying the
shortcuts that have been added to it.
# GtkShortcutController as a GtkBuildable
`GtkShortcutControllers` can be creates in ui files to set up
shortcuts in the same place as the widgets.
An example of a UI definition fragment with `GtkShortcutController`:
```xml
<object class='GtkButton'>
<child>
<object class='GtkShortcutController'>
<property name='scope'>managed</property>
<child>
<object class='GtkShortcut'>
<property name='trigger'><Control>k</property>
<property name='action'>activate</property>
</object>
</child>
</object>
</child>
</object>
```
This example creates a [class@Gtk.ActivateAction] for triggering the
`activate` signal of the `GtkButton`. See [ctor@Gtk.ShortcutAction.parse_string]
for the syntax for other kinds of `GtkShortcutAction`. See
[ctor@Gtk.ShortcutTrigger.parse_string] to learn more about the syntax
for triggers.
Most common shortcuts are using this controller implicitly, e.g. by
adding a mnemonic underline to a `GtkLabel`, or by installing a key
binding using [method@Gtk.WidgetClass.add_binding], or by adding accelerators
to global actions using [method@Gtk.Application.set_accels_for_action].
But it is possible to create your own shortcut controller, and add
shortcuts to it.
`GtkShortcutController` implements `GListModel` for querying the
shortcuts that have been added to it.
# GtkShortcutController as a GtkBuildable
`GtkShortcutControllers` can be creates in ui files to set up
shortcuts in the same place as the widgets.
An example of a UI definition fragment with `GtkShortcutController`:
```xml
<object class='GtkButton'>
<child>
<object class='GtkShortcutController'>
<property name='scope'>managed</property>
<child>
<object class='GtkShortcut'>
<property name='trigger'><Control>k</property>
<property name='action'>activate</property>
</object>
</child>
</object>
</child>
</object>
```
This example creates a [class@Gtk.ActivateAction] for triggering the
`activate` signal of the `GtkButton`. See [ctor@Gtk.ShortcutAction.parse_string]
for the syntax for other kinds of `GtkShortcutAction`. See
[ctor@Gtk.ShortcutTrigger.parse_string] to learn more about the syntax
for triggers.
-
Nested Class Summary
Nested classes/interfaces inherited from class ch.bailu.gtk.gobject.Object
Object.OnBindingTransformFunc, Object.OnDestroyNotify, Object.OnDuplicateFunc, Object.OnNotify, Object.OnToggleNotify, Object.OnWeakNotify
-
Field Summary
Fields inherited from class ch.bailu.gtk.gobject.Object
SIGNAL_ON_NOTIFY
-
Constructor Summary
ConstructorDescriptionCreates a new shortcut controller.ShortcutController
(PointerContainer pointer) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addShortcut
(Shortcut shortcut) Adds @shortcut to the list of shortcuts handled by @self.Implements interfaceBuildable
.Implements interfaceListModel
.static ClassHandler
static int
int
Gets the mnemonics modifiers for when this controller activates its shortcuts.static long
static TypeSystem.TypeSize
int
getScope()
Gets the scope for when this controller activates its shortcuts.static long
static TypeSystem.TypeSize
static ShortcutController
Creates a new shortcut controller that takes its shortcuts from
the given list model.void
removeShortcut
(Shortcut shortcut) Removes @shortcut from the list of shortcuts handled by @self.void
setMnemonicsModifiers
(int modifiers) Sets the controller to use the given modifier for mnemonics.void
setScope
(int scope) Sets the controller to have the given @scope.Methods inherited from class ch.bailu.gtk.gtk.EventController
getCurrentEvent, getCurrentEventDevice, getCurrentEventState, getCurrentEventTime, getName, getPropagationLimit, getPropagationPhase, getWidget, reset, setName, setName, setPropagationLimit, setPropagationPhase, setStaticName, setStaticName
Methods inherited from class ch.bailu.gtk.gobject.Object
addToggleRef, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, disconnect, disconnect, dupData, dupData, dupQdata, forceFloating, freezeNotify, get, get, getData, getData, getProperty, getProperty, getQdata, interfaceFindProperty, interfaceInstallProperty, isFloating, notify, notify, notifyByPspec, onNotify, ref, refSink, removeToggleRef, replaceData, replaceData, replaceQdata, runDispose, set, set, setData, setData, setDataFull, setDataFull, setProperty, setProperty, setQdata, setQdataFull, stealData, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref
Methods inherited from class ch.bailu.gtk.type.Pointer
asCPointer, cast, connectSignal, disconnectSignals, disconnectSignals, equals, hashCode, throwIfNull, throwNullPointerException, toString, unregisterCallbacks, unregisterCallbacks
Methods inherited from class ch.bailu.gtk.type.Type
asCPointer, asCPointer, asCPointerNotNull, asJnaPointer, asJnaPointer, asPointer, asPointer, cast, cast, throwIfNull
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface ch.bailu.gtk.type.PointerInterface
asCPointerNotNull, asJnaPointer, asPointer, isNotNull, isNull
-
Constructor Details
-
ShortcutController
-
ShortcutController
public ShortcutController()Creates a new shortcut controller.
-
-
Method Details
-
getClassHandler
-
newForModelShortcutController
Creates a new shortcut controller that takes its shortcuts from
the given list model.
A controller created by this function does not let you add or
remove individual shortcuts using the shortcut controller api,
but you can change the contents of the model.- Parameters:
model
- a `GListModel` containing shortcuts- Returns:
- a newly created shortcut controller
-
addShortcut
Adds @shortcut to the list of shortcuts handled by @self.
If this controller uses an external shortcut list, this
function does nothing.- Parameters:
shortcut
- a `GtkShortcut`
-
getMnemonicsModifiers
public int getMnemonicsModifiers()Gets the mnemonics modifiers for when this controller activates its shortcuts.- Returns:
- the controller's mnemonics modifiers
-
getScope
public int getScope()Gets the scope for when this controller activates its shortcuts.
See [method@Gtk.ShortcutController.set_scope] for details.- Returns:
- the controller's scope
-
removeShortcut
Removes @shortcut from the list of shortcuts handled by @self.
If @shortcut had not been added to @controller or this controller
uses an external shortcut list, this function does nothing.- Parameters:
shortcut
- a `GtkShortcut`
-
setMnemonicsModifiers
public void setMnemonicsModifiers(int modifiers) Sets the controller to use the given modifier for mnemonics.
The mnemonics modifiers determines which modifiers need to be pressed to allow
activation of shortcuts with mnemonics triggers.
GTK normally uses the Alt modifier for mnemonics, except in `GtkPopoverMenu`s,
where mnemonics can be triggered without any modifiers. It should be very
rarely necessary to change this, and doing so is likely to interfere with
other shortcuts.
This value is only relevant for local shortcut controllers. Global and managed
shortcut controllers will have their shortcuts activated from other places which
have their own modifiers for activating mnemonics.- Parameters:
modifiers
- the new mnemonics_modifiers to use
-
setScope
public void setScope(int scope) Sets the controller to have the given @scope.
The scope allows shortcuts to be activated outside of the normal
event propagation. In particular, it allows installing global
keyboard shortcuts that can be activated even when a widget does
not have focus.
With %GTK_SHORTCUT_SCOPE_LOCAL, shortcuts will only be activated
when the widget has focus.- Parameters:
scope
- the new scope to use
-
asListModel
Implements interfaceListModel
. Call this to get access to interface functions.- Returns:
ListModel
-
asBuildable
Implements interfaceBuildable
. Call this to get access to interface functions.- Returns:
Buildable
-
getTypeID
public static long getTypeID() -
getParentTypeID
public static long getParentTypeID() -
getTypeSize
-
getParentTypeSize
-
getInstanceSize
public static int getInstanceSize()
-