Gnome::Gtk4::ShortcutController
Description
Gnome::Gtk4::ShortcutController is an event controller that manages shortcuts.
Most common shortcuts are using this controller implicitly, e.g. by adding a mnemonic underline to a Gnome::Gtk4::Label, or by installing a key binding using .add-binding() in class Gnome::Gtk4::ShortcutController
, or by adding accelerators to global actions using .set-accels-for-action() in class Gnome::Gtk4::Application
.
But it is possible to create your own shortcut controller, and add shortcuts to it.
Gnome::Gtk4::ShortcutController implements Gnome::Gtk4::ShortcutController for querying the shortcuts that have been added to it.
GtkShortcutController as GtkBuildable
Gnome::Gtk4::ShortcutControllers can be created in Gnome::Gtk4::Builder ui files, to set up shortcuts in the same place as the widgets.
An example of a UI definition fragment with Gnome::Gtk4::ShortcutController:
This example creates a Gnome::Gtk4::ActivateAction for triggering the activate signal of the Gnome::Gtk4::Button. See .parse-string() in class Gnome::Gtk4::ShortcutAction
for the syntax for other kinds of Gnome::Gtk4::ShortcutAction. See .parse-string() in class Gnome::Gtk4::ShortcutTrigger
to learn more about the syntax for triggers.
Class initialization
new
:native-object
Create an object using a native object from elsewhere. See also Gnome::N::TopLevelSupportClass.
multi method new ( N-Object :$native-object! )
new-shortcutcontroller
Creates a new shortcut controller.
method new-shortcutcontroller ( --> Gnome::Gtk4::ShortcutController \)
new-for-model
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.
method new-for-model ( N-List() $model --> Gnome::Gtk4::ShortcutController \)
$model; a Gnome::Gio::R-ListModel containing shortcuts.
Methods
add-shortcut
Adds $shortcut
to the list of shortcuts handled by $self
.
If this controller uses an external shortcut list, this function does nothing.
method add-shortcut ( N-Object() $shortcut )
$shortcut; (transfer ownership: full) a Gnome::Gtk4::Shortcut.
get-mnemonics-modifiers
Gets the mnemonics modifiers for when this controller activates its shortcuts.
method get-mnemonics-modifiers (--> UInt )
Return value; the controller's mnemonics modifiers.
get-scope
Gets the scope for when this controller activates its shortcuts.
See .set-scope()
for details.
method get-scope (--> GtkShortcutScope )
Return value; the controller's scope.
remove-shortcut
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.
method remove-shortcut ( N-Object() $shortcut )
$shortcut; a Gnome::Gtk4::Shortcut.
set-mnemonics-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 Gnome::Gtk4::PopoverMenus, 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.
method set-mnemonics-modifiers ( UInt $modifiers )
$modifiers; the new mnemonics_modifiers to use.
set-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.
method set-scope ( GtkShortcutScope $scope )
$scope; the new scope to use.