Inkscape
Vector Graphics Editor
|
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. | |
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:
Definition at line 77 of file action-accel.h.
Inkscape::Util::ActionAccel::ActionAccel | ( | Glib::ustring | action_name | ) |
Construct an ActionAccel object which will keep track of keybindings for a given action.
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().
|
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().
|
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().
|
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.
slot | - the sigc::slot representing the callback function. |
Definition at line 114 of file action-accel.h.
References _we_changed.
Referenced by Inkscape::UI::Widget::CanvasGrid::CanvasGrid().
|
inline |
Returns all keyboard shortcuts for the action.
Definition at line 102 of file action-accel.h.
References _accels.
Referenced by getShortcutText().
std::vector< Glib::ustring > Inkscape::Util::ActionAccel::getShortcutText | ( | ) | const |
Returns all keyboard shortcuts for the action in the form of text.
Definition at line 87 of file action-accel.cpp.
References getKeys().
Referenced by Inkscape::UI::Widget::CanvasGrid::CanvasGrid().
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.
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 |
Definition at line 80 of file action-accel.cpp.
References _accels, Inkscape::Shortcuts::get_from(), and Inkscape::Shortcuts::getInstance().
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.
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 |
Definition at line 72 of file action-accel.cpp.
References _accels, Inkscape::Shortcuts::get_from(), and Inkscape::Shortcuts::getInstance().
bool Inkscape::Util::ActionAccel::isTriggeredBy | ( | KeyEvent const & | key | ) | const |
Checks whether a given key event triggers this action.
key | - a pointer to a KeyEvent containing key event data. |
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().
|
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().
|
private |
|
private |
To listen to changes to the keyboard shortcuts.
Definition at line 81 of file action-accel.h.
Referenced by ActionAccel().
|
private |
Emitted when the keybindings for the action are changed.
Definition at line 80 of file action-accel.h.
Referenced by _onShortcutsModified(), and connectModified().