diff options
Diffstat (limited to 'indra')
-rw-r--r-- | indra/llui/llmenugl.h | 10 | ||||
-rw-r--r-- | indra/newview/llluamanager.cpp | 89 | ||||
-rw-r--r-- | indra/newview/skins/default/xui/en/floater_lua_debug.xml | 11 |
3 files changed, 86 insertions, 24 deletions
diff --git a/indra/llui/llmenugl.h b/indra/llui/llmenugl.h index 9d3be8d94f..1a330b18cc 100644 --- a/indra/llui/llmenugl.h +++ b/indra/llui/llmenugl.h @@ -555,11 +555,12 @@ public: // add a context menu branch BOOL appendContextSubMenu(LLMenuGL *menu); + // Add the menu item to this menu. + virtual BOOL append( LLMenuItemGL* item ); + protected: void createSpilloverBranch(); void cleanupSpilloverBranch(); - // Add the menu item to this menu. - virtual BOOL append( LLMenuItemGL* item ); // add a menu - this will create a cascading menu virtual BOOL appendMenu( LLMenuGL* menu ); @@ -798,9 +799,10 @@ public: void resetMenuTrigger() { mAltKeyTrigger = FALSE; } + // add a menu - this will create a drop down menu. + virtual BOOL appendMenu(LLMenuGL *menu); + private: - // add a menu - this will create a drop down menu. - virtual BOOL appendMenu( LLMenuGL* menu ); // rearrange the child rects so they fit the shape of the menu // bar. virtual void arrange( void ); diff --git a/indra/newview/llluamanager.cpp b/indra/newview/llluamanager.cpp index 92a012c921..03a5d10975 100644 --- a/indra/newview/llluamanager.cpp +++ b/indra/newview/llluamanager.cpp @@ -79,6 +79,25 @@ bool checkLua(lua_State *L, int r, std::string &error_msg) return true; } +LLSD luatable_to_llsd(lua_State *L, S32 idx) +{ + LLSD args; + + // push first key + lua_pushnil(L); + while (lua_next(L, idx) != 0) + { + // right now -2 is key, -1 is value + lua_rawgeti(L, -1, 1); + lua_rawgeti(L, -2, 2); + std::string key = lua_tostring(L, -2); + std::string value = lua_tostring(L, -1); + args[key] = value; + lua_pop(L, 3); + } + return args; +} + int lua_avatar_sit(lua_State *L) { gAgent.sitDown(); @@ -258,20 +277,7 @@ int lua_show_notification(lua_State *L) if (lua_type(L, 2) == LUA_TTABLE) { - LLSD args; - - // push first key - lua_pushnil(L); - while (lua_next(L, 2) != 0) - { - // right now -2 is key, -1 is value - lua_rawgeti(L, -1, 1); - lua_rawgeti(L, -2, 2); - std::string key = lua_tostring(L, -2); - std::string value = lua_tostring(L, -1); - args[key] = value; - lua_pop(L, 3); - } + LLSD args = luatable_to_llsd(L, 2); std::string response_cb; if (lua_type(L, 3) == LUA_TSTRING) @@ -294,6 +300,57 @@ int lua_show_notification(lua_State *L) return 1; } +int lua_add_menu_item(lua_State *L) +{ + std::string menu(lua_tostring(L, 1)); + if (lua_type(L, 2) == LUA_TTABLE) + { + LLSD args = luatable_to_llsd(L, 2); + + LLMenuItemCallGL::Params item_params; + item_params.name = args["name"]; + item_params.label = args["label"]; + + LLUICtrl::CommitCallbackParam item_func; + item_func.function_name = args["function"]; + if (args.has("parameter")) + { + item_func.parameter = args["parameter"]; + } + item_params.on_click = item_func; + + LLMenuItemCallGL *menu_item = LLUICtrlFactory::create<LLMenuItemCallGL>(item_params); + gMenuBarView->findChildMenuByName(menu, true)->append(menu_item); + } + + return 1; +} + +int lua_add_menu_separator(lua_State *L) +{ + std::string menu(lua_tostring(L, 1)); + gMenuBarView->findChildMenuByName(menu, true)->addSeparator(); + + return 1; +} + +int lua_add_menu(lua_State *L) +{ + if (lua_type(L, 1) == LUA_TTABLE) + { + LLSD args = luatable_to_llsd(L, 1); + + LLMenuGL::Params item_params; + item_params.name = args["name"]; + item_params.label = args["label"]; + + LLMenuGL *menu = LLUICtrlFactory::create<LLMenuGL>(item_params); + gMenuBarView->appendMenu(menu); + } + + return 1; +} + int lua_run_ui_command(lua_State *L) { int top = lua_gettop(L); @@ -343,6 +400,10 @@ void initLUA(lua_State *L) lua_register(L, "set_debug_setting_bool", lua_set_debug_setting_bool); lua_register(L, "show_notification", lua_show_notification); + lua_register(L, "add_menu_separator", lua_add_menu_separator); + lua_register(L, "add_menu_item", lua_add_menu_item); + lua_register(L, "add_menu", lua_add_menu); + lua_register(L, "run_ui_command", lua_run_ui_command); } diff --git a/indra/newview/skins/default/xui/en/floater_lua_debug.xml b/indra/newview/skins/default/xui/en/floater_lua_debug.xml index 05f4db009e..0de26161e7 100644 --- a/indra/newview/skins/default/xui/en/floater_lua_debug.xml +++ b/indra/newview/skins/default/xui/en/floater_lua_debug.xml @@ -10,7 +10,7 @@ save_rect="true" title="LUA DEBUG" single_instance="true" - width="530"> + width="535"> <text type="string" length="1" @@ -37,7 +37,7 @@ name="lua_cmd" select_on_focus="true" top_delta="30" - width="415" /> + width="435" /> <button follows="left|bottom" height="25" @@ -55,7 +55,7 @@ layout="topleft" name="result_text" follows="left|top" - width="495" + width="515" top_delta="40" word_wrap="true" /> <text @@ -84,7 +84,7 @@ name="script_path" select_on_focus="true" top_delta="-2" - width="315" /> + width="320" /> <button follows="left|bottom" height="25" @@ -94,7 +94,7 @@ left_pad="5" name="browse_btn" top_delta="-2" - width="75" /> + width="70" /> <button follows="left|bottom" height="25" @@ -103,6 +103,5 @@ layout="topleft" left_pad="5" name="run_btn" - top_delta="-2" width="50" /> </floater> |