diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 11:50:49 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 11:50:49 +0000 |
commit | c853ffb5b2f75f5a889ed2e3ef89b818a736e87a (patch) | |
tree | 7d13a0883bb7936b84d6ecdd7bc332b41ed04bee /src/util/action-accel.cpp | |
parent | Initial commit. (diff) | |
download | inkscape-c853ffb5b2f75f5a889ed2e3ef89b818a736e87a.tar.xz inkscape-c853ffb5b2f75f5a889ed2e3ef89b818a736e87a.zip |
Adding upstream version 1.3+ds.upstream/1.3+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/util/action-accel.cpp')
-rw-r--r-- | src/util/action-accel.cpp | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/src/util/action-accel.cpp b/src/util/action-accel.cpp new file mode 100644 index 0000000..db20a66 --- /dev/null +++ b/src/util/action-accel.cpp @@ -0,0 +1,93 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * ActionAccel class implementation + * + * Authors: + * Rafael Siejakowski <rs@rs-math.net> + * + * Copyright (C) 2022 the Authors. + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include <gdk/gdk.h> +#include <glibmm/ustring.h> +#include <gtkmm.h> +#include <set> +#include <sigc++/sigc++.h> + +#include "inkscape-application.h" +#include "ui/shortcuts.h" +#include "util/action-accel.h" + +namespace Inkscape { +namespace Util { + +ActionAccel::ActionAccel(Glib::ustring action_name) + : _action{std::move(action_name)} +{ + auto &shortcuts = Shortcuts::getInstance(); + _query(); + _prefs_changed = shortcuts.connect_changed([this]() { _onShortcutsModified(); }); +} + +ActionAccel::~ActionAccel() +{ + _prefs_changed.disconnect(); +} + +void ActionAccel::_onShortcutsModified() +{ + if (_query()) { + _we_changed.emit(); + } +} + +bool ActionAccel::_query() +{ + auto *app = InkscapeApplication::instance(); + if (!app) { + g_warn_message("Inkscape", __FILE__, __LINE__, __func__, + "Attempt to read keyboard shortcuts while running without an InkscapeApplication!"); + return false; + } + auto *gtk_app = app->gtk_app(); + if (!gtk_app) { + g_warn_message("Inkscape", __FILE__, __LINE__, __func__, + "Attempt to read keyboard shortcuts while running without a GUI!"); + return false; + } + auto accel_strings = gtk_app->get_accels_for_action(_action); + std::set<AcceleratorKey> new_keys; + for (auto &&name : accel_strings) { + new_keys.emplace(std::move(name)); + } + + if (new_keys != _accels) + { + _accels = std::move(new_keys); + return true; + } + return false; +} + +bool ActionAccel::isTriggeredBy(GdkEventKey *key) const +{ + auto &shortcuts = Shortcuts::getInstance(); + AcceleratorKey accelerator = shortcuts.get_from_event(key); + return _accels.find(accelerator) != _accels.end(); +} + +} // namespace Util +} // namespace Inkscape + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : |