Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
Inkscape::Util::ActionAccel Class Reference

The ActionAccel class stores the keyboard shortcuts for a given action and automatically keeps track of changes in the keybindings. More...

#include <action-accel.h>

Public Member Functions

 ActionAccel (Glib::ustring action_name)
 Construct an ActionAccel object which will keep track of keybindings for a given action.
 
std::vector< Gtk::AccelKey > getKeys () const
 Returns all keyboard shortcuts for the action.
 
sigc::connection connectModified (sigc::slot< void()> const &slot)
 Connects a void callback which will run whenever the keybindings for the action change.
 
bool isTriggeredBy (KeyEvent const &key) const
 Checks whether a given key event triggers this action.
 
bool isTriggeredBy (GtkEventControllerKey const *controller, unsigned keyval, unsigned keycode, GdkModifierType state) const
 Checks whether a key controller and its signal handler arguments trigger this action.
 
bool isTriggeredBy (Gtk::EventControllerKey const &controller, unsigned keyval, unsigned keycode, Gdk::ModifierType state) const
 Checks whether a key controller and its signal handler arguments trigger this action.
 
std::vector< Glib::ustring > getShortcutText () const
 Returns all keyboard shortcuts for the action in the form of text.
 

Private Member Functions

bool _query ()
 Queries and updates the stored shortcuts, returning true if they have changed.
 
void _onShortcutsModified ()
 Runs when the keyboard shortcut settings have changed.
 

Private Attributes

sigc::signal< void()> _we_changed
 Emitted when the keybindings for the action are changed.
 
sigc::scoped_connection _prefs_changed
 To listen to changes to the keyboard shortcuts.
 
Glib::ustring _action
 Name of the action.
 
std::set< AcceleratorKey_accels
 Stores the accelerator keys for the action.
 

Detailed Description

The ActionAccel class stores the keyboard shortcuts for a given action and automatically keeps track of changes in the keybindings.

Additionally, a signal is emitted when the keybindings for the action change.

In order to create an ActionAccel object, one must pass a Glib::ustring containing the action name to the constructor. The object will automatically observe the keybindings for that action, so you always get up-to-date keyboard shortcuts. To check if a given key event triggers one of these keybindings, use isTriggeredBy().

Typical usage example:

auto accel = Inkscape::Util::ActionAccel("doc.undo");
KeyEvent const &key = get_from_somewhere();
if (accel.isTriggeredBy(key)) {
... // do stuff
}
accel.connectModified( []() { // This code will run when the user changes
// the keybindings for this action.
} );
The ActionAccel class stores the keyboard shortcuts for a given action and automatically keeps track ...
static cairo_user_data_key_t key
A key has been pressed.

Definition at line 77 of file action-accel.h.

Constructor & Destructor Documentation

◆ ActionAccel()

Inkscape::Util::ActionAccel::ActionAccel ( Glib::ustring  action_name)

Construct an ActionAccel object which will keep track of keybindings for a given action.

Parameters
action_name- the name of the action to hold and observe the keybindings of.

Definition at line 23 of file action-accel.cpp.

References _onShortcutsModified(), _prefs_changed, _query(), and Inkscape::Shortcuts::getInstance().

Member Function Documentation

◆ _onShortcutsModified()

void Inkscape::Util::ActionAccel::_onShortcutsModified ( )
private

Runs when the keyboard shortcut settings have changed.

Definition at line 33 of file action-accel.cpp.

References _query(), and _we_changed.

Referenced by ActionAccel().

◆ _query()

bool Inkscape::Util::ActionAccel::_query ( )
private

Queries and updates the stored shortcuts, returning true if they have changed.

Definition at line 40 of file action-accel.cpp.

References _accels, _action, Inkscape::Shortcuts::get_triggers(), Inkscape::Shortcuts::getInstance(), and InkscapeApplication::instance().

Referenced by _onShortcutsModified(), and ActionAccel().

◆ connectModified()

sigc::connection Inkscape::Util::ActionAccel::connectModified ( sigc::slot< void()> const &  slot)
inline

Connects a void callback which will run whenever the keybindings for the action change.

At the time when the callback runs, the values stored in the ActionAccel object will have already been updated. This means that the new keybindings can be queried by the callback.

Parameters
slot- the sigc::slot representing the callback function.
Returns
the resulting sigc::connection.

Definition at line 114 of file action-accel.h.

References _we_changed.

Referenced by Inkscape::UI::Widget::CanvasGrid::CanvasGrid().

◆ getKeys()

std::vector< Gtk::AccelKey > Inkscape::Util::ActionAccel::getKeys ( ) const
inline

Returns all keyboard shortcuts for the action.

Returns
a vector containing a Gtk::AccelKey for each of the keybindings present for the action.

Definition at line 102 of file action-accel.h.

References _accels.

Referenced by getShortcutText().

◆ getShortcutText()

std::vector< Glib::ustring > Inkscape::Util::ActionAccel::getShortcutText ( ) const

Returns all keyboard shortcuts for the action in the form of text.

Returns
a vector containing a Glib::ustring for each of the keybindings present for the action.

Definition at line 87 of file action-accel.cpp.

References getKeys().

Referenced by Inkscape::UI::Widget::CanvasGrid::CanvasGrid().

◆ isTriggeredBy() [1/3]

bool Inkscape::Util::ActionAccel::isTriggeredBy ( Gtk::EventControllerKey const &  controller,
unsigned  keyval,
unsigned  keycode,
Gdk::ModifierType  state 
) const

Checks whether a key controller and its signal handler arguments trigger this action.

Parameters
controller- Gtk::EventController emitting key-pressed or released signal
keyval- the keyval received by the signal handler
keycode- the hardware key code received by the signal handler
state- the keyboard modifier state received by the signal handler
Returns
true if one of the keyboard shortcuts for the action is triggered by the arguments, false otherwise.

Definition at line 80 of file action-accel.cpp.

References _accels, Inkscape::Shortcuts::get_from(), and Inkscape::Shortcuts::getInstance().

◆ isTriggeredBy() [2/3]

bool Inkscape::Util::ActionAccel::isTriggeredBy ( GtkEventControllerKey const *  controller,
unsigned  keyval,
unsigned  keycode,
GdkModifierType  state 
) const

Checks whether a key controller and its signal handler arguments trigger this action.

Parameters
controller- pointer to GtkEventController emitting key-pressed or released signal
keyval- the keyval received by the signal handler
keycode- the hardware key code received by the signal handler
state- the keyboard modifier state received by the signal handler
Returns
true if one of the keyboard shortcuts for the action is triggered by the arguments, false otherwise.

Definition at line 72 of file action-accel.cpp.

References _accels, Inkscape::Shortcuts::get_from(), and Inkscape::Shortcuts::getInstance().

◆ isTriggeredBy() [3/3]

bool Inkscape::Util::ActionAccel::isTriggeredBy ( KeyEvent const &  key) const

Checks whether a given key event triggers this action.

Parameters
key- a pointer to a KeyEvent containing key event data.
Returns
true if one of the keyboard shortcuts for the action is triggered by the passed event, false otherwise.

Definition at line 66 of file action-accel.cpp.

References _accels, Inkscape::Shortcuts::get_from_event(), Inkscape::Shortcuts::getInstance(), and key.

Referenced by Inkscape::UI::Tools::PenTool::_handleKeyPress(), and Inkscape::UI::Tools::InteractiveBooleansTool::event_key_press_handler().

Member Data Documentation

◆ _accels

std::set<AcceleratorKey> Inkscape::Util::ActionAccel::_accels
private

Stores the accelerator keys for the action.

Definition at line 83 of file action-accel.h.

Referenced by _query(), getKeys(), isTriggeredBy(), isTriggeredBy(), and isTriggeredBy().

◆ _action

Glib::ustring Inkscape::Util::ActionAccel::_action
private

Name of the action.

Definition at line 82 of file action-accel.h.

Referenced by _query().

◆ _prefs_changed

sigc::scoped_connection Inkscape::Util::ActionAccel::_prefs_changed
private

To listen to changes to the keyboard shortcuts.

Definition at line 81 of file action-accel.h.

Referenced by ActionAccel().

◆ _we_changed

sigc::signal<void ()> Inkscape::Util::ActionAccel::_we_changed
private

Emitted when the keybindings for the action are changed.

Definition at line 80 of file action-accel.h.

Referenced by _onShortcutsModified(), and connectModified().


The documentation for this class was generated from the following files: