diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2015-07-26 13:03:41 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2015-07-26 13:03:41 +0000 |
commit | b356c02a32cea58b39c4970ed67cf6ff2a218e00 (patch) | |
tree | 577963b67f7f2f92e0e994656c71a553e3d229c1 | |
parent | 4a966be3c32e745b2567e51c27766942f798f77d (diff) |
MirLua will remove message bar buttons on script reloading
git-svn-id: http://svn.miranda-ng.org/main/trunk@14725 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | plugins/MirLua/src/m_core.cpp | 2 | ||||
-rw-r--r-- | plugins/MirLua/src/m_msg_buttonsbar.cpp | 77 | ||||
-rw-r--r-- | plugins/MirLua/src/m_msg_buttonsbar.h | 9 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua.cpp | 2 | ||||
-rw-r--r-- | plugins/MirLua/src/stdafx.h | 3 |
5 files changed, 72 insertions, 21 deletions
diff --git a/plugins/MirLua/src/m_core.cpp b/plugins/MirLua/src/m_core.cpp index e3972df3d4..91fe4df070 100644 --- a/plugins/MirLua/src/m_core.cpp +++ b/plugins/MirLua/src/m_core.cpp @@ -238,7 +238,7 @@ LUAMOD_API int luaopen_m(lua_State *L) lua_setfield(L, -2, "NULL");
lua_pushlightuserdata(L, INVALID_HANDLE_VALUE);
lua_setfield(L, -2, "INVALID_HANDLE_VALUE");
- lua_setglobal(L, "m");
+ lua_setglobal(L, MLUA_CORE);
return 1;
}
\ No newline at end of file diff --git a/plugins/MirLua/src/m_msg_buttonsbar.cpp b/plugins/MirLua/src/m_msg_buttonsbar.cpp index 4b22301f97..3973badba7 100644 --- a/plugins/MirLua/src/m_msg_buttonsbar.cpp +++ b/plugins/MirLua/src/m_msg_buttonsbar.cpp @@ -1,40 +1,62 @@ #include "stdafx.h"
+static int CompareMBButtons(const BBButton* p1, const BBButton* p2)
+{
+ if (int res = mir_strcmpi(p1->pszModuleName, p2->pszModuleName))
+ return res;
+ return p1->dwButtonID - p2->dwButtonID;
+}
+
+static LIST<BBButton> MBButtons(1, CompareMBButtons);
+
+void KillModuleMBButtons()
+{
+ while (MBButtons.getCount())
+ {
+ BBButton* bbb = MBButtons[0];
+ ::CallService(MS_BB_REMOVEBUTTON, 0, (LPARAM)bbb);
+ MBButtons.remove(0);
+ mir_free(bbb->pszModuleName);
+ mir_free(bbb->ptszTooltip);
+ mir_free(bbb);
+ }
+}
+
static BBButton* MakeBBButton(lua_State *L)
{
- BBButton *tbb = (BBButton*)mir_calloc(sizeof(BBButton));
- tbb->cbSize = sizeof(BBButton);
- tbb->dwDefPos = 100;
+ BBButton *bbb = (BBButton*)mir_calloc(sizeof(BBButton));
+ bbb->cbSize = sizeof(BBButton);
+ bbb->dwDefPos = 100;
lua_pushliteral(L, "Module");
lua_gettable(L, -2);
- tbb->pszModuleName = mir_utf8decode((char*)luaL_checkstring(L, -1), NULL);
+ bbb->pszModuleName = mir_utf8decodeA(luaL_checkstring(L, -1));
lua_pop(L, 1);
lua_pushliteral(L, "ButtonID");
lua_gettable(L, -2);
- tbb->dwButtonID = luaL_checkinteger(L, -1);
+ bbb->dwButtonID = luaL_checkinteger(L, -1);
lua_pop(L, 1);
lua_pushliteral(L, "Flags");
lua_gettable(L, -2);
- tbb->bbbFlags = lua_tointeger(L, -1);
+ bbb->bbbFlags = lua_tointeger(L, -1);
lua_pop(L, 1);
- if ((tbb->bbbFlags & BBBF_ANSITOOLTIP))
- tbb->bbbFlags &= ~BBBF_ANSITOOLTIP;
+ if ((bbb->bbbFlags & BBBF_ANSITOOLTIP))
+ bbb->bbbFlags &= ~BBBF_ANSITOOLTIP;
lua_pushliteral(L, "Tooltip");
lua_gettable(L, -2);
- tbb->ptszTooltip = mir_utf8decodeT((char*)lua_tostring(L, -1));
+ bbb->ptszTooltip = mir_utf8decodeT(lua_tostring(L, -1));
lua_pop(L, 1);
lua_pushliteral(L, "Icon");
lua_gettable(L, -2);
- tbb->hIcon = (HANDLE)lua_touserdata(L, -1);
+ bbb->hIcon = (HANDLE)lua_touserdata(L, -1);
lua_pop(L, 1);
- return tbb;
+ return bbb;
}
static int lua_AddButton(lua_State *L)
@@ -45,11 +67,14 @@ static int lua_AddButton(lua_State *L) return 1;
}
- mir_ptr<BBButton> bbb(MakeBBButton(L));
+ BBButton* bbb = MakeBBButton(L);
INT_PTR res = ::CallService(MS_BB_ADDBUTTON, 0, (LPARAM)bbb);
lua_pushinteger(L, res);
+ if (!res)
+ MBButtons.insert(bbb);
+
return 1;
}
@@ -61,24 +86,40 @@ static int lua_ModifyButton(lua_State *L) return 1;
}
- mir_ptr<BBButton> bbb(MakeBBButton(L));
+ BBButton* bbb = MakeBBButton(L);
INT_PTR res = ::CallService(MS_BB_MODIFYBUTTON, 0, (LPARAM)bbb);
lua_pushinteger(L, res);
+ mir_free(bbb->pszModuleName);
+ mir_free(bbb->ptszTooltip);
+ mir_free(bbb);
+
return 1;
}
static int lua_RemoveButton(lua_State *L)
{
- BBButton bbb = { sizeof(BBButton) };
- bbb.pszModuleName = mir_utf8decode((char*)luaL_checkstring(L, 1), NULL);
- bbb.dwButtonID = luaL_checkinteger(L, 2);
+ ptrA szModuleName(mir_utf8decodeA(luaL_checkstring(L, 1)));
- INT_PTR res = ::CallService(MS_BB_REMOVEBUTTON, 0, (LPARAM)&bbb);
+ BBButton mbb = { sizeof(BBButton) };
+ mbb.pszModuleName = szModuleName;
+ mbb.dwButtonID = luaL_checkinteger(L, 2);
+
+ INT_PTR res = ::CallService(MS_BB_REMOVEBUTTON, 0, (LPARAM)&mbb);
lua_pushinteger(L, res);
- //mir_free(bbb.pszModuleName);
+ if (!res)
+ {
+ BBButton* bbb = MBButtons.find(&mbb);
+ if (bbb)
+ {
+ MBButtons.remove(bbb);
+ mir_free(bbb->pszModuleName);
+ mir_free(bbb->ptszTooltip);
+ mir_free(bbb);
+ }
+ }
return 1;
}
diff --git a/plugins/MirLua/src/m_msg_buttonsbar.h b/plugins/MirLua/src/m_msg_buttonsbar.h new file mode 100644 index 0000000000..a4cbccbbdc --- /dev/null +++ b/plugins/MirLua/src/m_msg_buttonsbar.h @@ -0,0 +1,9 @@ +#ifndef _LUA_M_MSG_BUTTONSBAR_H_
+#define _LUA_M_MSG_BUTTONSBAR_H_
+
+#define MLUA_MSGBUTTONSBAR "m_msg_buttonsbar"
+LUAMOD_API int (luaopen_m_msg_buttonsbar)(lua_State *L);
+
+void KillModuleMBButtons();
+
+#endif //_LUA_M_MSG_BUTTONSBAR_H_
\ No newline at end of file diff --git a/plugins/MirLua/src/mlua.cpp b/plugins/MirLua/src/mlua.cpp index fac6fa9307..e65ad4c8b9 100644 --- a/plugins/MirLua/src/mlua.cpp +++ b/plugins/MirLua/src/mlua.cpp @@ -64,6 +64,8 @@ void CMLua::Unload() script->Unload();
delete script;
}
+
+ ::KillModuleMBButtons();
::KillModuleIcons(hScriptsLangpack);
::KillModuleMenus(hScriptsLangpack);
diff --git a/plugins/MirLua/src/stdafx.h b/plugins/MirLua/src/stdafx.h index 62eaa25326..232d1eeef3 100644 --- a/plugins/MirLua/src/stdafx.h +++ b/plugins/MirLua/src/stdafx.h @@ -83,8 +83,7 @@ LUAMOD_API int (luaopen_m_hotkeys)(lua_State *L); #define MLUA_MESSAGE "m_message"
LUAMOD_API int (luaopen_m_message)(lua_State *L);
-#define MLUA_MSGBUTTONSBAR "m_msg_buttonsbar"
-LUAMOD_API int (luaopen_m_msg_buttonsbar)(lua_State *L);
+#include "m_msg_buttonsbar.h"
#define MLUA_POPUP "m_popup"
LUAMOD_API int (luaopen_m_popup)(lua_State *L);
|