summaryrefslogtreecommitdiff
path: root/plugins/MirLua
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2015-06-11 14:02:29 +0000
committerAlexander Lantsev <aunsane@gmail.com>2015-06-11 14:02:29 +0000
commit8ecb995a281008dbbc83ba8ea04ef28dbdc3d2e2 (patch)
tree753f5970ffbd881d60e7a633c255008e4401cf7d /plugins/MirLua
parent5778345f250585d701e34bbc1458f8c92a6166d2 (diff)
MirLua: added ModifyMenuItem to m_genmenu
git-svn-id: http://svn.miranda-ng.org/main/trunk@14116 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/MirLua')
-rw-r--r--plugins/MirLua/docs/examples/menus.lua13
-rw-r--r--plugins/MirLua/src/m_genmenu.cpp45
2 files changed, 36 insertions, 22 deletions
diff --git a/plugins/MirLua/docs/examples/menus.lua b/plugins/MirLua/docs/examples/menus.lua
index ee1ca258a8..fd20f92fe1 100644
--- a/plugins/MirLua/docs/examples/menus.lua
+++ b/plugins/MirLua/docs/examples/menus.lua
@@ -41,15 +41,12 @@ local CMIF_ROOTHANDLE = 384
local hRoot = genmenu.AddMainMenuItem({ Name = "Main menu root", Flags = CMIF_ROOTHANDLE })
--- Add child menu item
-menuItem.Name = "Main menu child"
+menuItem.Name = "Main menu child wierd"
menuItem.Flags = CMIF_ROOTHANDLE
menuItem.Service = 'Srv/SMI'
menuItem.Parent = hRoot
-genmenu.AddMainMenuItem(menuItem)
+local hChild = genmenu.AddMainMenuItem(menuItem)
---- Add child menu item
-menuItem.Name = "Main menu child 2"
-menuItem.Flags = CMIF_ROOTHANDLE
-menuItem.Service = 'Srv/SMI'
-menuItem.Parent = "&Help"
-genmenu.AddMainMenuItem(menuItem)
+--- Modify menu item
+local CMIM_NAME = tonumber("80000000", 16)
+genmenu.ModifyMenuItem(hChild, { Name = "Main menu child", Flags = CMIM_NAME })
diff --git a/plugins/MirLua/src/m_genmenu.cpp b/plugins/MirLua/src/m_genmenu.cpp
index 43e1b2a36f..83001cd27b 100644
--- a/plugins/MirLua/src/m_genmenu.cpp
+++ b/plugins/MirLua/src/m_genmenu.cpp
@@ -5,27 +5,33 @@ static CLISTMENUITEM* MakeMenuItem(lua_State *L)
CLISTMENUITEM *pmi = (CLISTMENUITEM*)mir_calloc(sizeof(CLISTMENUITEM));
pmi->cbSize = sizeof(CLISTMENUITEM);
- lua_getfield(L, 1, "Name");
+ lua_pushstring(L, "Name");
+ lua_gettable(L, -2);
pmi->pszName = LPGEN((char*)luaL_checkstring(L, -1));
lua_pop(L, 1);
- lua_getfield(L, 1, "Flags");
+ lua_pushstring(L, "Flags");
+ lua_gettable(L, -2);
pmi->flags = lua_tointeger(L, -1);
lua_pop(L, 1);
- lua_getfield(L, 1, "Position");
+ lua_pushstring(L, "Position");
+ lua_gettable(L, -2);
pmi->position = lua_tointeger(L, -1);
lua_pop(L, 1);
- lua_getfield(L, 1, "Icon");
+ lua_pushstring(L, "Icon");
+ lua_gettable(L, -2);
pmi->icolibItem = (HANDLE)lua_touserdata(L, -1);
lua_pop(L, 1);
- lua_getfield(L, 1, "Service");
+ lua_pushstring(L, "Service");
+ lua_gettable(L, -2);
pmi->pszService = (char*)lua_tostring(L, -1);
lua_pop(L, 1);
- lua_getfield(L, 1, "Parent");
+ lua_pushstring(L, "Parent");
+ lua_gettable(L, -2);
pmi->hParentMenu = (HGENMENU)lua_touserdata(L, -1);
lua_pop(L, 1);
@@ -40,12 +46,8 @@ static int lua_AddMainMenuItem(lua_State *L)
return 1;
}
- lua_settop(L, 1);
-
mir_ptr<CLISTMENUITEM> pmi(MakeMenuItem(L));
- lua_pop(L, 1);
-
HGENMENU res = ::Menu_AddMainMenuItem(pmi);
lua_pushlightuserdata(L, res);
@@ -60,18 +62,32 @@ static int lua_AddContactMenuItem(lua_State *L)
return 1;
}
- lua_settop(L, 1);
-
mir_ptr<CLISTMENUITEM> pmi(MakeMenuItem(L));
- lua_pop(L, 1);
-
HGENMENU res = ::Menu_AddContactMenuItem(pmi);
lua_pushlightuserdata(L, res);
return 1;
}
+static int lua_ModifyMenuItem(lua_State *L)
+{
+ HGENMENU hMenuItem = (HGENMENU)lua_touserdata(L, 1);
+
+ if (lua_type(L, 2) != LUA_TTABLE)
+ {
+ lua_pushlightuserdata(L, 0);
+ return 1;
+ }
+
+ mir_ptr<CLISTMENUITEM> pmi(MakeMenuItem(L));
+
+ INT_PTR res = ::CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuItem, (LPARAM)pmi);
+ lua_pushinteger(L, res);
+
+ return 1;
+}
+
static int lua_RemoveMenuItem(lua_State *L)
{
HGENMENU hMenuItem = (HGENMENU)lua_touserdata(L, 1);
@@ -86,6 +102,7 @@ static luaL_Reg genmenuApi[] =
{
{ "AddMainMenuItem", lua_AddMainMenuItem },
{ "AddContactMenuItem", lua_AddContactMenuItem },
+ { "ModifyMenuItem", lua_ModifyMenuItem },
{ "RemoveMenuItem", lua_RemoveMenuItem },
{ NULL, NULL }