From d7b496062c378fea22c68aaadfa190a10ae0260c Mon Sep 17 00:00:00 2001 From: svenhoefer Date: Mon, 24 Nov 2014 10:04:02 +0100 Subject: [PATCH] - luainstance: add CKeybordInput Syntax: m:addItem { \ type="keyboardinput", \ action="_action", \ id="_id", \ value="_value", \ name="_name", \ help="help (first line)", help2="help (second line)" } --- src/gui/luainstance.cpp | 38 ++++++++++++++++++++++++++++++++++++++ src/gui/luainstance.h | 14 ++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/src/gui/luainstance.cpp b/src/gui/luainstance.cpp index a9f883b6f..7a2aebb64 100644 --- a/src/gui/luainstance.cpp +++ b/src/gui/luainstance.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -1160,6 +1161,35 @@ int CLuaMenuStringinput::exec(CMenuTarget* /*parent*/, const std::string & /*act return menu_return::RETURN_REPAINT; } +CLuaMenuKeyboardinput::CLuaMenuKeyboardinput(lua_State *_L, std::string _luaAction, std::string _luaId, const char *_name, std::string *_value, int _size, CChangeObserver *_observ, const char *_icon, std::string _help, std::string _help2) : CLuaMenuForwarder(_L, _luaAction, _luaId) +{ + name = _name; + value = _value; + size = _size; + icon = _icon; + observ = _observ; + help = _help; + help2 = _help2; +} + +int CLuaMenuKeyboardinput::exec(CMenuTarget* /*parent*/, const std::string & /*actionKey*/) +{ + CKeyboardInput *i; + i = new CKeyboardInput((char *)name, value, size, observ, icon, help, help2); + i->exec(NULL, ""); + delete i; + if (!luaAction.empty()){ + lua_pushglobaltable(L); + lua_getfield(L, -1, luaAction.c_str()); + lua_remove(L, -2); + lua_pushstring(L, luaId.c_str()); + lua_pushstring(L, value->c_str()); + lua_pcall(L, 2 /* two args */, 1 /* one result */, 0); + lua_pop(L, 2); + } + return menu_return::RETURN_REPAINT; +} + int CLuaInstance::MenuNew(lua_State *L) { CMenuWidget *m; @@ -1350,6 +1380,14 @@ int CLuaInstance::MenuAddItem(lua_State *L) CLuaMenuStringinput *stringinput = new CLuaMenuStringinput(L, action, id, b->name.c_str(), &b->str_val, size, valid_chars, m->observ, icon, sms); mi = new CMenuForwarder(b->name, enabled, b->str_val, stringinput, NULL/*ActionKey*/, directkey, icon, right_icon); m->targets.push_back(stringinput); + } else if (type == "keyboardinput") { + b->str_val = value; + int size = 0; tableLookup(L, "size", size); + std::string help = ""; tableLookup(L, "help", help); + std::string help2 = ""; tableLookup(L, "help2", help2); + CLuaMenuKeyboardinput *keyboardinput = new CLuaMenuKeyboardinput(L, action, id, b->name.c_str(), &b->str_val, size, m->observ, icon, help, help2); + mi = new CMenuForwarder(b->name, enabled, b->str_val, keyboardinput, NULL/*ActionKey*/, directkey, icon, right_icon); + m->targets.push_back(keyboardinput); } else if (type == "filebrowser") { b->str_val = value; int dirMode = 0; tableLookup(L, "dir_mode", dirMode); diff --git a/src/gui/luainstance.h b/src/gui/luainstance.h index 8b2153074..83712c872 100644 --- a/src/gui/luainstance.h +++ b/src/gui/luainstance.h @@ -103,6 +103,20 @@ class CLuaMenuStringinput : public CLuaMenuForwarder int exec(CMenuTarget* parent, const std::string & actionKey); }; +class CLuaMenuKeyboardinput : public CLuaMenuForwarder +{ + private: + std::string *value; + const char *name; + const char *icon; + int size; + CChangeObserver *observ; + std::string help, help2; + public: + CLuaMenuKeyboardinput(lua_State *_L, std::string _luaAction, std::string _luaId, const char *_name, std::string *_value, int _size, CChangeObserver *_observ, const char *_icon, std::string _help, std::string _help2); + int exec(CMenuTarget* parent, const std::string & actionKey); +}; + class CLuaHintbox { public: