summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2020-04-12 08:57:17 -0600
committerPaul Davis <paul@linuxaudiosystems.com>2020-04-12 08:57:59 -0600
commit2084a3916830f3f640bcfb0e205b2aa1e1ad9750 (patch)
tree4440fefdab15a1533b7323c526c0cf873cc56635 /libs
parent920a77f6af7a35fd2b0c03d600e1d3faa9ce5951 (diff)
some tweaks to Bindings API to allow ::is_bound() to indicate the action path for an existing binding
Plus some minor comment additions and cleanups
Diffstat (limited to 'libs')
-rw-r--r--libs/gtkmm2ext/bindings.cc32
-rw-r--r--libs/gtkmm2ext/gtkmm2ext/bindings.h4
2 files changed, 27 insertions, 9 deletions
diff --git a/libs/gtkmm2ext/bindings.cc b/libs/gtkmm2ext/bindings.cc
index e54534f647..b460b6a5c4 100644
--- a/libs/gtkmm2ext/bindings.cc
+++ b/libs/gtkmm2ext/bindings.cc
@@ -583,7 +583,10 @@ bool
Bindings::replace (KeyboardKey kb, Operation op, string const & action_name, bool can_save)
{
if (is_registered(op, action_name)) {
- remove (op, action_name, can_save);
+ /* never save after the remove, because if can_save is true, we
+ will save after we add the new binding.
+ */
+ remove (op, action_name, false);
}
/* XXX need a way to get the old group name */
@@ -608,8 +611,8 @@ Bindings::add (KeyboardKey kb, Operation op, string const& action_name, XMLPrope
(void) kbm.insert (new_pair).first;
}
- DEBUG_TRACE (DEBUG::Bindings, string_compose ("add binding between %1 and %2, group [%3]\n",
- kb, action_name, (group ? group->value() : string())));
+ DEBUG_TRACE (DEBUG::Bindings, string_compose ("add binding between %1 (%3) and %2, group [%3]\n",
+ kb, action_name, (group ? group->value() : string()), op));
if (can_save) {
Keyboard::keybindings_changed ();
@@ -624,6 +627,7 @@ Bindings::remove (Operation op, std::string const& action_name, bool can_save)
{
bool erased_action = false;
KeybindingMap& kbm = get_keymap (op);
+
for (KeybindingMap::iterator k = kbm.begin(); k != kbm.end(); ++k) {
if (k->second.action_name == action_name) {
kbm.erase (k);
@@ -1054,10 +1058,17 @@ Bindings::associate_all ()
}
bool
-Bindings::is_bound (KeyboardKey const& kb, Operation op) const
+Bindings::is_bound (KeyboardKey const& kb, Operation op, std::string* path) const
{
const KeybindingMap& km = get_keymap(op);
- return km.find(kb) != km.end();
+ KeybindingMap::const_iterator i = km.find (kb);
+ if (i != km.end()) {
+ if (path) {
+ *path = i->second.action_name;
+ }
+ return true;
+ }
+ return false;
}
std::string
@@ -1065,10 +1076,17 @@ Bindings::bound_name (KeyboardKey const& kb, Operation op) const
{
const KeybindingMap& km = get_keymap(op);
KeybindingMap::const_iterator b = km.find(kb);
+
if (b == km.end()) {
- return "";
+ return string();
}
- return b->second.action->get_label();
+
+ if (!b->second.action) {
+ /* action is looked up lazily, so it may not have been set yet */
+ b->second.action = ActionManager::get_action (b->second.action_name, false);
+ }
+
+ return b->second.action->get_label ();
}
bool
diff --git a/libs/gtkmm2ext/gtkmm2ext/bindings.h b/libs/gtkmm2ext/gtkmm2ext/bindings.h
index fc1e5c39fb..34b2cd4cce 100644
--- a/libs/gtkmm2ext/gtkmm2ext/bindings.h
+++ b/libs/gtkmm2ext/gtkmm2ext/bindings.h
@@ -113,7 +113,7 @@ class LIBGTKMM2EXT_API Bindings {
std::string action_name;
std::string group_name; /* may be empty */
- Glib::RefPtr<Gtk::Action> action;
+ mutable Glib::RefPtr<Gtk::Action> action;
};
typedef std::map<KeyboardKey,ActionInfo> KeybindingMap;
@@ -140,7 +140,7 @@ class LIBGTKMM2EXT_API Bindings {
void remove (MouseButton, Operation);
bool activate (MouseButton, Operation);
- bool is_bound (KeyboardKey const&, Operation) const;
+ bool is_bound (KeyboardKey const&, Operation, std::string* path = 0) const;
std::string bound_name (KeyboardKey const&, Operation) const;
bool is_registered (Operation op, std::string const& action_name) const;