cleanup Bindings/ActionMap API to get all actions for various purposes
authorPaul Davis <paul@linuxaudiosystems.com>
Tue, 1 Sep 2015 19:46:30 +0000 (15:46 -0400)
committerPaul Davis <paul@linuxaudiosystems.com>
Mon, 22 Feb 2016 20:31:24 +0000 (15:31 -0500)
libs/gtkmm2ext/bindings.cc
libs/gtkmm2ext/gtkmm2ext/bindings.h

index ea1214cb21fa83c33d3f8b5224091b2429cbfdde..a09a90fb7586615f2ae3619a841b96520dc0a5c5 100644 (file)
@@ -848,43 +848,6 @@ Bindings::get_all_actions (std::vector<std::string>& paths,
        }
 }
 
-void
-Bindings::get_all_actions (std::vector<std::string>& names,
-                           std::vector<std::string>& paths,
-                           std::vector<std::string>& keys)
-{
-       if (!_action_map) {
-               return;
-       }
-
-       /* build a reverse map from actions to bindings */
-
-       typedef map<Glib::RefPtr<Gtk::Action>,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<ActionGroup> group,
         return RefPtr<Action>();
 }
 
+void
+ActionMap::get_all_actions (std::vector<std::string>& paths,
+                           std::vector<std::string>& labels,
+                           std::vector<std::string>& tooltips,
+                           std::vector<std::string>& keys,
+                           std::vector<RefPtr<Action> >& actions)
+{
+       for (list<ActionMap*>::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();
index a9b2d7bf5d5075854f7035a8960c302cca9899b4..cf9d0b8d137b4229acd7ffd993bebeb0e3c95588 100644 (file)
@@ -104,14 +104,21 @@ class LIBGTKMM2EXT_API ActionMap {
 
         Glib::RefPtr<Gtk::Action> find_action (const std::string& name);
 
-        typedef std::vector<Glib::RefPtr<Gtk::Action> > Actions;
+       void set_bindings (Bindings*);
+       Bindings* bindings() const { return _bindings; }
+
+       typedef std::vector<Glib::RefPtr<Gtk::Action> > Actions;
        void get_actions (Actions&);
 
        static std::list<ActionMap*> action_maps;
-       
-       void set_bindings (Bindings*);
-       Bindings* bindings() const { return _bindings; }
 
+        /* used by control surface protocols and other UIs */
+       static void get_all_actions (std::vector<std::string>& paths,
+                                    std::vector<std::string>& labels,
+                                    std::vector<std::string>& tooltips,
+                                    std::vector<std::string>& keys,
+                                    std::vector<Glib::RefPtr<Gtk::Action> >& 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<std::string>& names,
-                              std::vector<std::string>& paths,
-                              std::vector<std::string>& keys);
-
         /* used for editing bindings */
-       void get_all_actions (std::vector<std::string>& paths,
-                             std::vector<std::string>& labels,
-                             std::vector<std::string>& tooltips,
-                             std::vector<std::string>& keys,
-                             std::vector<Glib::RefPtr<Gtk::Action> >& actions);
+        void get_all_actions (std::vector<std::string>& paths,
+                              std::vector<std::string>& labels,
+                              std::vector<std::string>& tooltips,
+                              std::vector<std::string>& keys,
+                              std::vector<Glib::RefPtr<Gtk::Action> >& actions);
 
        /* all bindings currently in existence, as grouped into Bindings */
        static std::list<Bindings*> bindings;