From b544097135831f24da3d6b11211d19e9536005f0 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Sat, 2 Jan 2016 14:54:06 +0000 Subject: MirLua: added new settings git-svn-id: http://svn.miranda-ng.org/main/trunk@15993 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/MirLua/src/mlua_icons.cpp | 1 - plugins/MirLua/src/mlua_options.cpp | 29 ++++++----------- plugins/MirLua/src/mlua_options.h | 3 ++ plugins/MirLua/src/mlua_utils.cpp | 63 ++++++++++++++++++++++--------------- plugins/MirLua/src/resource.h | 7 +++-- plugins/MirLua/src/stdafx.h | 8 +++-- 6 files changed, 60 insertions(+), 51 deletions(-) (limited to 'plugins/MirLua/src') diff --git a/plugins/MirLua/src/mlua_icons.cpp b/plugins/MirLua/src/mlua_icons.cpp index 7b0e9c37f3..b8da8bce9e 100644 --- a/plugins/MirLua/src/mlua_icons.cpp +++ b/plugins/MirLua/src/mlua_icons.cpp @@ -4,7 +4,6 @@ IconItemT Icons[] = { { LPGENT("Script"), "script", IDI_SCRIPT }, { LPGENT("Open"), "open", IDI_OPEN }, - { LPGENT("Reload") , "reload", IDI_RELOAD }, }; void InitIcons() diff --git a/plugins/MirLua/src/mlua_options.cpp b/plugins/MirLua/src/mlua_options.cpp index 7b89599af5..9d44bbde83 100644 --- a/plugins/MirLua/src/mlua_options.cpp +++ b/plugins/MirLua/src/mlua_options.cpp @@ -18,10 +18,16 @@ BOOL CCtrlScriptList::OnNotify(int idCtrl, NMHDR *pnmh) /****************************************/ -CLuaOptions::CLuaOptions(int idDialog) : CDlgBase(g_hInstance, idDialog), - m_scripts(this, IDC_SCRIPTS), isScriptListInit(false), +CLuaOptions::CLuaOptions(int idDialog) + : CDlgBase(g_hInstance, idDialog), + m_popupOnError(this, IDC_POPUPONERROR), + m_popupOnObsolete(this, IDC_POPUPONOBSOLETE), + isScriptListInit(false), m_scripts(this, IDC_SCRIPTS), m_reload(this, IDC_RELOAD) { + CreateLink(m_popupOnError, "PopupOnError", DBVT_BYTE, 1); + CreateLink(m_popupOnObsolete, "PopupOnObsolete", DBVT_BYTE, 1); + m_scripts.OnClick = Callback(this, &CLuaOptions::OnScriptListClick); m_reload.OnClick = Callback(this, &CLuaOptions::OnReload); } @@ -59,9 +65,6 @@ void CLuaOptions::LoadScripts() if (db_get_b(NULL, MODULE, _T2A(fileName), 1)) m_scripts.SetCheckState(iItem, TRUE); m_scripts.SetItem(iItem, 1, TranslateT("Open"), 0); -//#ifdef DEBUG - m_scripts.SetItem(iItem, 2, _T(""), 1); -//#endif } } @@ -73,20 +76,14 @@ void CLuaOptions::OnInitDialog() HIMAGELIST hImageList = m_scripts.CreateImageList(LVSIL_SMALL); ImageList_AddIcon(hImageList, GetIcon(IDI_OPEN)); - ImageList_AddIcon(hImageList, GetIcon(IDI_RELOAD)); TCHAR scriptDir[MAX_PATH], relativeScriptDir[MAX_PATH], header[MAX_PATH + 100]; - FoldersGetCustomPathT(g_hCommonScriptFolder, scriptDir, _countof(scriptDir), VARST(COMMON_SCRIPTS_PATHT)); + FoldersGetCustomPathT(g_hScriptsFolder, scriptDir, _countof(scriptDir), VARST(MIRLUA_PATHT)); PathToRelativeT(scriptDir, relativeScriptDir, NULL); mir_sntprintf(header, _T("%s (%s)"), TranslateT("Common scripts"), relativeScriptDir); - //m_scripts.AddGroup(0, header); - //m_scripts.EnableGroupView(TRUE); m_scripts.AddColumn(0, _T("Script"), 420); m_scripts.AddColumn(1, NULL, 32 - GetSystemMetrics(SM_CXVSCROLL)); -//#ifdef DEBUG - //m_scripts.AddColumn(2, NULL, 32 - GetSystemMetrics(SM_CXVSCROLL)); -//#endif LoadScripts(); @@ -145,13 +142,7 @@ void CLuaOptions::OnScriptListClick(CCtrlListView::TEventInfo *evt) if (lvi.iSubItem == 1) ShellExecute(m_hwnd, _T("Open"), script->GetFilePath(), NULL, NULL, SW_SHOWNORMAL); -//#ifdef DEBUG - else if (lvi.iSubItem == 2) - { - script->Unload(); - script->Load(); - } -//#endif + mir_free(lvi.pszText); } diff --git a/plugins/MirLua/src/mlua_options.h b/plugins/MirLua/src/mlua_options.h index 25bf442ed1..b81676bfc8 100644 --- a/plugins/MirLua/src/mlua_options.h +++ b/plugins/MirLua/src/mlua_options.h @@ -19,6 +19,9 @@ public: class CLuaOptions : public CDlgBase { private: + CCtrlCheck m_popupOnError; + CCtrlCheck m_popupOnObsolete; + bool isScriptListInit; CCtrlScriptList m_scripts; CCtrlButton m_reload; diff --git a/plugins/MirLua/src/mlua_utils.cpp b/plugins/MirLua/src/mlua_utils.cpp index 99bae923d1..c253ad244c 100644 --- a/plugins/MirLua/src/mlua_utils.cpp +++ b/plugins/MirLua/src/mlua_utils.cpp @@ -1,8 +1,34 @@ #include "stdafx.h" +void ShowNotification(const char *caption, const char *message, int flags, MCONTACT hContact) +{ + if (Miranda_Terminated()) + return; + + if (ServiceExists(MS_POPUP_ADDPOPUPT) && db_get_b(NULL, "Popup", "ModuleIsEnabled", 1)) + { + POPUPDATA ppd = { 0 }; + ppd.lchContact = hContact; + mir_strncpy(ppd.lpzContactName, caption, MAX_CONTACTNAME); + mir_strncpy(ppd.lpzText, message, MAX_SECONDLINE); + + if (!PUAddPopup(&ppd)) + return; + } + + ::MessageBoxA(NULL, message, caption, MB_OK | flags); +} + +void ReportError(const char *message) +{ + CallService(MS_NETLIB_LOG, (WPARAM)hNetlib, (LPARAM)message); + if (db_get_b(NULL, MODULE, "PopupOnError", 0)) + ShowNotification(MODULE, message, MB_OK | MB_ICONERROR); +} + int luaM_atpanic(lua_State *L) { - CallService(MS_NETLIB_LOG, (WPARAM)hNetlib, (LPARAM)lua_tostring(L, -1)); + ReportError(lua_tostring(L, -1)); return 0; } @@ -20,13 +46,16 @@ int luaM_trace(lua_State *L) int luaM_pcall(lua_State *L, int n, int r) { - /*lua_pushcfunction(L, luaM_trace); - lua_insert(L, f); - const int f = -(n + 2);*/ - const int f = 0; + int f = 0; + /*if (db_get_b(NULL, MODULE, "AddTaraceback", 0)) + { + f = -(n + 2); + lua_pushcfunction(L, luaM_trace); + lua_insert(L, f); + }*/ int res = lua_pcall(L, n, r, f); if (res != LUA_OK) - CallService(MS_NETLIB_LOG, (WPARAM)hNetlib, (LPARAM)lua_tostring(L, -1)); + ReportError(lua_tostring(L, -1)); return res; } @@ -150,25 +179,6 @@ int luaM_totable(lua_State *L) return 1; } -void ShowNotification(const char *caption, const char *message, int flags, MCONTACT hContact) -{ - if (Miranda_Terminated()) - return; - - if (ServiceExists(MS_POPUP_ADDPOPUPT) && db_get_b(NULL, "Popup", "ModuleIsEnabled", 1)) - { - POPUPDATA ppd = { 0 }; - ppd.lchContact = hContact; - mir_strncpy(ppd.lpzContactName, caption, MAX_CONTACTNAME); - mir_strncpy(ppd.lpzText, message, MAX_SECONDLINE); - - if (!PUAddPopup(&ppd)) - return; - } - - ::MessageBoxA(NULL, message, caption, MB_OK | flags); -} - void ObsoleteMethod(lua_State *L, const char *message) { lua_Debug info; @@ -178,5 +188,6 @@ void ObsoleteMethod(lua_State *L, const char *message) char text[512]; mir_snprintf(text, "%s is obsolete. %s", info.name, message); CallService(MS_NETLIB_LOG, (WPARAM)hNetlib, (LPARAM)text); - ShowNotification(MODULE, text, MB_OK | MB_ICONWARNING, NULL); + if (db_get_b(NULL, MODULE, "PopupOnObsolete", 0)) + ShowNotification(MODULE, text, MB_OK | MB_ICONWARNING, NULL); } \ No newline at end of file diff --git a/plugins/MirLua/src/resource.h b/plugins/MirLua/src/resource.h index ad362f5cce..22507f4637 100644 --- a/plugins/MirLua/src/resource.h +++ b/plugins/MirLua/src/resource.h @@ -6,17 +6,18 @@ #define IDI_SCRIPT 100 #define IDI_OPEN 105 #define IDD_OPTIONS 106 -#define IDI_RELOAD 107 #define IDC_SCRIPTS 1011 #define IDC_RELOAD 1012 +#define IDC_POPUPONERROR 1013 +#define IDC_POPUPONOBSOLETE 1014 // Next default values for new objects // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 107 +#define _APS_NEXT_RESOURCE_VALUE 108 #define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1013 +#define _APS_NEXT_CONTROL_VALUE 1015 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif diff --git a/plugins/MirLua/src/stdafx.h b/plugins/MirLua/src/stdafx.h index f791f4a183..73573652ef 100644 --- a/plugins/MirLua/src/stdafx.h +++ b/plugins/MirLua/src/stdafx.h @@ -73,6 +73,8 @@ extern HANDLE hNetlib; #define MIRLUA_PATHT MIRANDA_PATH "\\Scripts" #endif +/* modules */ + #define MLUA_CORE "m_core" LUAMOD_API int (luaopen_m_core)(lua_State *L); @@ -113,6 +115,10 @@ LUAMOD_API int (luaopen_m_variables)(lua_State *L); #define MLUA_WINDOWS "m_windows" LUAMOD_API int (luaopen_m_windows)(lua_State *L); +/* utils */ + +void ShowNotification(const char *caption, const char *message, int flags = 0, MCONTACT hContact = NULL); + int luaM_atpanic(lua_State *L); int luaM_pcall(lua_State *L, int n = 0, int r = 0); @@ -131,8 +137,6 @@ void InitIcons(); HICON GetIcon(int iconId); HANDLE GetIconHandle(int iconId); -void ShowNotification(const char *caption, const char *message, int flags = 0, MCONTACT hContact = NULL); - void ObsoleteMethod(lua_State *L, const char *message); #endif //_COMMON_H_ -- cgit v1.2.3