X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Fluainstance.cc;h=8f9572b98e7da461365eaa4c17461bfe7fd41eea;hb=efc858dc8149f3b3456781451ef42dc69eee2d5e;hp=a20405a5995e490b3f9aeab9f11de9a91b7d62e8;hpb=30b087ab3d28f1585987fa3f6ae006562ae192e3;p=ardour.git diff --git a/gtk2_ardour/luainstance.cc b/gtk2_ardour/luainstance.cc index a20405a599..8f9572b98e 100644 --- a/gtk2_ardour/luainstance.cc +++ b/gtk2_ardour/luainstance.cc @@ -20,6 +20,9 @@ #include #include +#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 paths; + vector labels; + vector tooltips; + vector keys; + vector > actions; + Gtkmm2ext::ActionMap::get_all_actions (paths, labels, tooltips, keys, actions); + + vector::iterator p; + vector::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 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 / from the start */ + string path = (*p); + path = path.substr (strlen ("/")); + + 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. @@ -728,14 +794,14 @@ LuaInstance::register_classes (lua_State* L) .beginClass ("RegionSelection") .addFunction ("start", &RegionSelection::start) - .addFunction ("end_frame", &RegionSelection::end_sample) + .addFunction ("end_sample", &RegionSelection::end_sample) .addFunction ("n_midi_regions", &RegionSelection::n_midi_regions) .addFunction ("regionlist", &RegionSelection::regionlist) // XXX check windows binding (libardour) .endClass () .deriveClass > ("TimeSelection") .addFunction ("start", &TimeSelection::start) - .addFunction ("end_frame", &TimeSelection::end_sample) + .addFunction ("end_sample", &TimeSelection::end_sample) .addFunction ("length", &TimeSelection::length) .endClass () @@ -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") @@ -1290,7 +1358,7 @@ LuaInstance::interactive_add (LuaScriptInfo::ScriptType type, int id) switch (type) { case LuaScriptInfo::EditorAction: reg = lua_action_names (); - title = _("Add Lua Action"); + title = _("Add Shortcut or Lua Script"); break; case LuaScriptInfo::EditorHook: reg = lua_slot_names (); @@ -1323,18 +1391,27 @@ LuaInstance::interactive_add (LuaScriptInfo::ScriptType type, int id) try { script = Glib::file_get_contents (spi->path); - } catch (Glib::FileError e) { + } catch (Glib::FileError const& e) { string msg = string_compose (_("Cannot read script '%1': %2"), spi->path, e.what()); Gtk::MessageDialog am (msg); am.run (); return false; } - LuaScriptParamList lsp = LuaScriptParams::script_params (spi, param_function); + LuaState ls; + register_classes (ls.getState ()); + LuaScriptParamList lsp = LuaScriptParams::script_params (ls, spi->path, param_function); + + /* allow cancel */ + for (size_t i = 0; i < lsp.size(); ++i) { + if (lsp[i]->preseeded && lsp[i]->name == "x-script-abort") { + return false; + } + } ScriptParameterDialog spd (_("Set Script Parameters"), spi, reg, lsp); - if (!spd.need_interation ()) { + if (spd.need_interation ()) { switch (spd.run ()) { case Gtk::RESPONSE_ACCEPT: break; @@ -1343,7 +1420,7 @@ LuaInstance::interactive_add (LuaScriptInfo::ScriptType type, int id) } } - LuaScriptParamPtr lspp (new LuaScriptParam("x-script-origin", "", spi->path, false)); + LuaScriptParamPtr lspp (new LuaScriptParam("x-script-origin", "", spi->path, false, true)); lsp.push_back (lspp); switch (type) { @@ -1360,7 +1437,7 @@ LuaInstance::interactive_add (LuaScriptInfo::ScriptType type, int id) string msg = string_compose (_("Session script '%1' instantiation failed: %2"), spd.name(), e.what ()); Gtk::MessageDialog am (msg); am.run (); - } catch (SessionException e) { + } catch (SessionException const& e) { string msg = string_compose (_("Loading Session script '%1' failed: %2"), spd.name(), e.what ()); Gtk::MessageDialog am (msg); am.run ();