diff --git a/libs/gtkmm2ext/bindings.cc b/libs/gtkmm2ext/bindings.cc index ea1214cb21..a09a90fb75 100644 --- a/libs/gtkmm2ext/bindings.cc +++ b/libs/gtkmm2ext/bindings.cc @@ -848,43 +848,6 @@ Bindings::get_all_actions (std::vector& paths, } } -void -Bindings::get_all_actions (std::vector& names, - std::vector& paths, - std::vector& keys) -{ - if (!_action_map) { - return; - } - - /* build a reverse map from actions to bindings */ - - typedef map,KeyboardKey> ReverseMap; - ReverseMap rmap; - - for (KeybindingMap::const_iterator k = press_bindings.begin(); k != press_bindings.end(); ++k) { - rmap.insert (make_pair (k->second.action, k->first)); - } - - /* get a list of all actions */ - - ActionMap::Actions all_actions; - _action_map->get_actions (all_actions); - - for (ActionMap::Actions::const_iterator act = all_actions.begin(); act != all_actions.end(); ++act) { - - names.push_back ((*act)->get_name()); - paths.push_back ((*act)->get_accel_path()); - - ReverseMap::iterator r = rmap.find (*act); - if (r != rmap.end()) { - keys.push_back (r->second.display_label()); - } else { - keys.push_back (string()); - } - } -} - Bindings* Bindings::get_bindings (string const& name, ActionMap& map) { @@ -1078,6 +1041,48 @@ ActionMap::register_toggle_action (RefPtr group, return RefPtr(); } +void +ActionMap::get_all_actions (std::vector& paths, + std::vector& labels, + std::vector& tooltips, + std::vector& keys, + std::vector >& actions) +{ + for (list::const_iterator map = action_maps.begin(); map != action_maps.end(); ++map) { + + ActionMap::Actions these_actions; + (*map)->get_actions (these_actions); + + for (ActionMap::Actions::const_iterator act = these_actions.begin(); act != these_actions.end(); ++act) { + + paths.push_back ((*act)->get_accel_path()); + labels.push_back ((*act)->get_label()); + tooltips.push_back ((*act)->get_tooltip()); + actions.push_back (*act); + + Bindings* bindings = (*map)->bindings(); + + if (bindings) { + + KeyboardKey key; + Bindings::Operation op; + + key = bindings->get_binding_for_action (*act, op); + + if (key == KeyboardKey::null_key()) { + keys.push_back (string()); + } else { + keys.push_back (key.display_label()); + } + } else { + keys.push_back (string()); + } + } + + these_actions.clear (); + } +} + std::ostream& operator<<(std::ostream& out, Gtkmm2ext::KeyboardKey const & k) { char const *gdk_name = gdk_keyval_name (k.key()); return out << "Key " << k.key() << " (" << (gdk_name ? gdk_name : "no-key") << ") state " << k.state(); diff --git a/libs/gtkmm2ext/gtkmm2ext/bindings.h b/libs/gtkmm2ext/gtkmm2ext/bindings.h index a9b2d7bf5d..cf9d0b8d13 100644 --- a/libs/gtkmm2ext/gtkmm2ext/bindings.h +++ b/libs/gtkmm2ext/gtkmm2ext/bindings.h @@ -104,14 +104,21 @@ class LIBGTKMM2EXT_API ActionMap { Glib::RefPtr find_action (const std::string& name); - typedef std::vector > Actions; - void get_actions (Actions&); - - static std::list action_maps; - void set_bindings (Bindings*); Bindings* bindings() const { return _bindings; } + typedef std::vector > Actions; + void get_actions (Actions&); + + static std::list action_maps; + + /* used by control surface protocols and other UIs */ + static void get_all_actions (std::vector& paths, + std::vector& labels, + std::vector& tooltips, + std::vector& keys, + std::vector >& actions); + private: std::string _name; @@ -198,17 +205,12 @@ class LIBGTKMM2EXT_API Bindings { void set_action_map (ActionMap&); - /* used to list all actions */ - void get_all_actions (std::vector& names, - std::vector& paths, - std::vector& keys); - /* used for editing bindings */ - void get_all_actions (std::vector& paths, - std::vector& labels, - std::vector& tooltips, - std::vector& keys, - std::vector >& actions); + void get_all_actions (std::vector& paths, + std::vector& labels, + std::vector& tooltips, + std::vector& keys, + std::vector >& actions); /* all bindings currently in existence, as grouped into Bindings */ static std::list bindings;