Add Lua binding to query action-list
authorRobin Gareus <robin@gareus.org>
Tue, 5 Dec 2017 00:42:44 +0000 (01:42 +0100)
committerRobin Gareus <robin@gareus.org>
Tue, 5 Dec 2017 00:55:38 +0000 (01:55 +0100)
gtk2_ardour/luainstance.cc

index 68fef8920f4bb0f1c315b96794f83fb9a69b7ae4..a0f247179ef94e88df595f9c100c130041722bf1 100644 (file)
@@ -20,6 +20,9 @@
 #include <cairomm/surface.h>
 #include <pango/pangocairo.h>
 
+#include "pbd/strsplit.h"
+
+#include "gtkmm2ext/bindings.h"
 #include "gtkmm2ext/gui_thread.h"
 
 #include "ardour/audioengine.h"
@@ -424,6 +427,69 @@ lua_exec (std::string cmd)
        return 0;
 }
 #endif
+
+////////////////////////////////////////////////////////////////////////////////
+
+static int
+lua_actionlist (lua_State *L)
+{
+       using namespace std;
+
+       vector<string> paths;
+       vector<string> labels;
+       vector<string> tooltips;
+       vector<string> keys;
+       vector<Glib::RefPtr<Gtk::Action> > actions;
+       Gtkmm2ext::ActionMap::get_all_actions (paths, labels, tooltips, keys, actions);
+
+       vector<string>::iterator p;
+       vector<string>::iterator l;
+
+       luabridge::LuaRef action_tbl (luabridge::newTable (L));
+
+       for (l = labels.begin(), p = paths.begin(); l != labels.end(); ++p, ++l) {
+               if (l->empty ()) {
+                       continue;
+               }
+
+               vector<string> parts;
+               split (*p, parts, '/');
+
+               if (parts.empty()) {
+                       continue;
+               }
+
+               //kinda kludgy way to avoid displaying menu items as mappable
+               if (parts[1] == _("Main_menu"))
+                       continue;
+               if (parts[1] == _("JACK"))
+                       continue;
+               if (parts[1] == _("redirectmenu"))
+                       continue;
+               if (parts[1] == _("Editor_menus"))
+                       continue;
+               if (parts[1] == _("RegionList"))
+                       continue;
+               if (parts[1] == _("ProcessorMenu"))
+                       continue;
+
+               /* strip <Actions>/ from the start */
+               string path = (*p);
+               path = path.substr (strlen ("<Actions>/"));
+
+               if (!action_tbl[parts[1]].isTable()) {
+                       action_tbl[parts[1]] = luabridge::newTable (L);
+               }
+               assert (action_tbl[parts[1]].isTable());
+               luabridge::LuaRef tbl (action_tbl[parts[1]]);
+               assert (tbl.isTable());
+               tbl[*l] = path;
+       }
+
+       luabridge::push (L, action_tbl);
+       return 1;
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 
 // ARDOUR_UI and instance() are not exposed.
@@ -949,6 +1015,8 @@ LuaInstance::register_classes (lua_State* L)
                .addConst ("Add", Selection::Operation(Selection::Add))
                .endNamespace ()
 
+               .addCFunction ("actionlist", &lua_actionlist)
+
                .endNamespace () // end ArdourUI
 
                .beginNamespace ("os")