From 27985042841f1ea60156ed532e0b9f57e9c3b369 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Mon, 15 Jun 2015 15:52:22 +0000 Subject: MirLua: added options page git-svn-id: http://svn.miranda-ng.org/main/trunk@14179 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/MirLua/MirLua.vcxproj | 5 +++ plugins/MirLua/res/resource.rc | 33 ++++++++++++++ plugins/MirLua/src/main.cpp | 36 ++++++++++++--- plugins/MirLua/src/mlua.cpp | 5 ++- plugins/MirLua/src/mlua_options.cpp | 87 +++++++++++++++++++++++++++++++++++++ plugins/MirLua/src/mlua_options.h | 29 +++++++++++++ plugins/MirLua/src/resource.h | 8 +++- plugins/MirLua/src/stdafx.h | 8 ++++ 8 files changed, 200 insertions(+), 11 deletions(-) create mode 100644 plugins/MirLua/src/mlua_options.cpp create mode 100644 plugins/MirLua/src/mlua_options.h diff --git a/plugins/MirLua/MirLua.vcxproj b/plugins/MirLua/MirLua.vcxproj index 66db483dd4..fe790d27e8 100644 --- a/plugins/MirLua/MirLua.vcxproj +++ b/plugins/MirLua/MirLua.vcxproj @@ -25,6 +25,11 @@ + + + comctl32.lib;%(AdditionalDependencies) + + diff --git a/plugins/MirLua/res/resource.rc b/plugins/MirLua/res/resource.rc index 3a6d9122bd..3cdd4f6afa 100644 --- a/plugins/MirLua/res/resource.rc +++ b/plugins/MirLua/res/resource.rc @@ -63,6 +63,39 @@ LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL // Icon with lowest ID value placed first to ensure application icon // remains consistent on all systems. IDI_ICON ICON "icon.ico" + +///////////////////////////////////////////////////////////////////////////// +// +// Dialog +// + +IDD_OPTIONS DIALOGEX 0, 0, 310, 230 +STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD +EXSTYLE WS_EX_CONTROLPARENT +FONT 8, "MS Shell Dlg", 0, 0, 0x1 +BEGIN + CONTROL "",IDC_SCRIPTS,"SysListView32",LVS_REPORT | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP | LVS_NOCOLUMNHEADER,7,20,140,172 +END + + +///////////////////////////////////////////////////////////////////////////// +// +// DESIGNINFO +// + +#ifdef APSTUDIO_INVOKED +GUIDELINES DESIGNINFO +BEGIN + IDD_OPTIONS, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 303 + TOPMARGIN, 7 + BOTTOMMARGIN, 228 + END +END +#endif // APSTUDIO_INVOKED + #endif // English resources ///////////////////////////////////////////////////////////////////////////// diff --git a/plugins/MirLua/src/main.cpp b/plugins/MirLua/src/main.cpp index 88b82af2e7..ce1fa50de9 100644 --- a/plugins/MirLua/src/main.cpp +++ b/plugins/MirLua/src/main.cpp @@ -3,10 +3,10 @@ int hLangpack; HINSTANCE g_hInstance; -CMLua *mLua; -HANDLE hCommonFolderPath; -HANDLE hCustomFolderPath; +HANDLE g_hCommonFolderPath; +HANDLE g_hCustomFolderPath; +CMLua *mLua; HANDLE hConsole = NULL; PLUGININFOEX pluginInfo = @@ -63,6 +63,26 @@ void LoadScripts(const TCHAR *scriptDir) } } +int OnOptionsInit(WPARAM wParam, LPARAM) +{ + OPTIONSDIALOGPAGE odp = { 0 }; + odp.flags = ODPF_BOLDGROUPS | ODPF_TCHAR | ODPF_DONTTRANSLATE; + odp.ptszGroup = LPGENT("Customize"); + odp.ptszTitle = LPGENT("Scripts"); + odp.ptszTab = _T("Lua"); + odp.pDialog = CLuaOptions::CreateOptionsPage(); + Options_AddPage(wParam, &odp); + + return 0; +} + +int OnModulesLoaded(WPARAM wParam, LPARAM) +{ + HookEvent(ME_OPT_INITIALISE, OnOptionsInit); + + return 0; +} + extern "C" int __declspec(dllexport) Load(void) { mir_getLP(&pluginInfo); @@ -80,17 +100,19 @@ extern "C" int __declspec(dllexport) Load(void) mLua = new CMLua(); - hCommonFolderPath = FoldersRegisterCustomPathT("MirLua", Translate("Common scripts folder"), COMMON_SCRIPTS_PATHT); - hCustomFolderPath = FoldersRegisterCustomPathT("MirLua", Translate("Custom scripts folder"), CUSTOM_SCRIPTS_PATHT); + g_hCommonFolderPath = FoldersRegisterCustomPathT("MirLua", Translate("Common scripts folder"), COMMON_SCRIPTS_PATHT); + g_hCustomFolderPath = FoldersRegisterCustomPathT("MirLua", Translate("Custom scripts folder"), CUSTOM_SCRIPTS_PATHT); TCHAR commonScriptDir[MAX_PATH]; - FoldersGetCustomPathT(hCommonFolderPath, commonScriptDir, SIZEOF(commonScriptDir), VARST(COMMON_SCRIPTS_PATHT)); + FoldersGetCustomPathT(g_hCommonFolderPath, commonScriptDir, SIZEOF(commonScriptDir), VARST(COMMON_SCRIPTS_PATHT)); LoadScripts(commonScriptDir); TCHAR customScriptDir[MAX_PATH]; - FoldersGetCustomPathT(hCustomFolderPath, customScriptDir, SIZEOF(customScriptDir), VARST(CUSTOM_SCRIPTS_PATHT)); + FoldersGetCustomPathT(g_hCustomFolderPath, customScriptDir, SIZEOF(customScriptDir), VARST(CUSTOM_SCRIPTS_PATHT)); LoadScripts(customScriptDir); + HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded); + return 0; } diff --git a/plugins/MirLua/src/mlua.cpp b/plugins/MirLua/src/mlua.cpp index a389e155f1..e67caf6272 100644 --- a/plugins/MirLua/src/mlua.cpp +++ b/plugins/MirLua/src/mlua.cpp @@ -1,6 +1,6 @@ #include "stdafx.h" -CMLua::CMLua() +CMLua::CMLua() : L(NULL) { L = luaL_newstate(); luaL_openlibs(L); @@ -24,7 +24,8 @@ CMLua::CMLua() CMLua::~CMLua() { - lua_close(L); + if(L) + lua_close(L); } void CMLua::AddPath(const char *path) diff --git a/plugins/MirLua/src/mlua_options.cpp b/plugins/MirLua/src/mlua_options.cpp new file mode 100644 index 0000000000..1a93789f52 --- /dev/null +++ b/plugins/MirLua/src/mlua_options.cpp @@ -0,0 +1,87 @@ +#include "stdafx.h" + +CLuaOptions::CLuaOptions(int idDialog) + : CDlgBase(g_hInstance, idDialog), m_scripts(this, IDC_SCRIPTS) +{ +} + +void CLuaOptions::CreateLink(CCtrlData& ctrl, const char *szSetting, BYTE type, DWORD iValue) +{ + ctrl.CreateDbLink(MODULE, szSetting, type, iValue); +} + +void CLuaOptions::CreateLink(CCtrlData& ctrl, const char *szSetting, TCHAR *szValue) +{ + ctrl.CreateDbLink(MODULE, szSetting, szValue); +} + +void CLuaOptions::LoadScripts(const TCHAR *scriptDir) +{ + TCHAR searchMask[MAX_PATH]; + mir_sntprintf(searchMask, _T("%s\\%s"), scriptDir, _T("*.lua")); + + TCHAR fullPath[MAX_PATH], path[MAX_PATH]; + + WIN32_FIND_DATA fd; + HANDLE hFind = FindFirstFile(searchMask, &fd); + if (hFind != INVALID_HANDLE_VALUE) + { + do + { + if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) + { + mir_sntprintf(fullPath, _T("%s\\%s"), scriptDir, fd.cFileName); + PathToRelativeT(fullPath, path); + + m_scripts.AddItem(fd.cFileName, -1, NULL, 0); + } + } while (FindNextFile(hFind, &fd)); + FindClose(hFind); + } +} + +void CLuaOptions::OnInitDialog() +{ + CDlgBase::OnInitDialog(); + + m_scripts.EnableGroupView(TRUE); + m_scripts.AddGroup(0, TranslateT("Common scripts")); + m_scripts.AddGroup(1, TranslateT("Custom scripts")); + + m_scripts.AddColumn(0, _T("Script"), 300); + + WIN32_FIND_DATA fd; + HANDLE hFind = NULL; + TCHAR scriptDir[MAX_PATH]; + TCHAR searchMask[MAX_PATH]; + + FoldersGetCustomPathT(g_hCommonFolderPath, scriptDir, SIZEOF(scriptDir), VARST(COMMON_SCRIPTS_PATHT)); + mir_sntprintf(searchMask, _T("%s\\%s"), scriptDir, _T("*.lua")); + hFind = FindFirstFile(searchMask, &fd); + if (hFind != INVALID_HANDLE_VALUE) + { + do + { + if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) + { + m_scripts.AddItem(fd.cFileName, -1, NULL, 0); + } + } while (FindNextFile(hFind, &fd)); + FindClose(hFind); + } + + FoldersGetCustomPathT(g_hCustomFolderPath, scriptDir, SIZEOF(scriptDir), VARST(CUSTOM_SCRIPTS_PATHT)); + mir_sntprintf(searchMask, _T("%s\\%s"), scriptDir, _T("*.lua")); + hFind = FindFirstFile(searchMask, &fd); + if (hFind != INVALID_HANDLE_VALUE) + { + do + { + if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) + { + m_scripts.AddItem(fd.cFileName, -1, NULL, 1); + } + } while (FindNextFile(hFind, &fd)); + FindClose(hFind); + } +} \ No newline at end of file diff --git a/plugins/MirLua/src/mlua_options.h b/plugins/MirLua/src/mlua_options.h new file mode 100644 index 0000000000..7311cf5df6 --- /dev/null +++ b/plugins/MirLua/src/mlua_options.h @@ -0,0 +1,29 @@ +#ifndef _LUA_OPTIONS_H_ +#define _LUA_OPTIONS_H_ + +class CLuaOptions : public CDlgBase +{ +private: + CCtrlListView m_scripts; + + void LoadScripts(const TCHAR *scriptDir); + +protected: + void OnInitDialog(); + +public: + CLuaOptions(int idDialog); + + void CreateLink(CCtrlData& ctrl, const char *szSetting, BYTE type, DWORD iValue); + void CreateLink(CCtrlData& ctrl, const char *szSetting, TCHAR *szValue); + + template + __inline void CreateLink(CCtrlData &ctrl, CMOption &option) + { + ctrl.CreateDbLink(new CMOptionLink(option)); + } + + static CDlgBase *CreateOptionsPage() { return new CLuaOptions(IDD_OPTIONS_MAIN); } +}; + +#endif //_LUA_OPTIONS_H_ \ No newline at end of file diff --git a/plugins/MirLua/src/resource.h b/plugins/MirLua/src/resource.h index 6a43423102..6adee66c1c 100644 --- a/plugins/MirLua/src/resource.h +++ b/plugins/MirLua/src/resource.h @@ -1,8 +1,12 @@ //{{NO_DEPENDENCIES}} // Microsoft Visual C++ generated include file. -// Used by E:\Projects\C++\MirandaNG\plugins\MirLua\res\resource.rc +// Used by D:\Projects\MirandaNG\plugins\MirLua\res\resource.rc // #define IDI_ICON 100 +#define IDD_OPTIONS_MAIN 106 +#define IDD_OPTIONS 106 +#define IDC_LIST1 1011 +#define IDC_SCRIPTS 1011 // Next default values for new objects // @@ -10,7 +14,7 @@ #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 105 #define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1011 +#define _APS_NEXT_CONTROL_VALUE 1012 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif diff --git a/plugins/MirLua/src/stdafx.h b/plugins/MirLua/src/stdafx.h index b26ae3db4e..26296fedc8 100644 --- a/plugins/MirLua/src/stdafx.h +++ b/plugins/MirLua/src/stdafx.h @@ -2,12 +2,16 @@ #define _COMMON_H_ #include +#include #include #include #include #include #include +#include +#include + #include #include #include @@ -29,11 +33,15 @@ extern "C" class CMLua; #include "mlua.h" +#include "mlua_options.h" #define MODULE "MirLua" extern HINSTANCE g_hInstance; +extern HANDLE g_hCommonFolderPath; +extern HANDLE g_hCustomFolderPath; + #ifdef _UNICODE #define COMMON_SCRIPTS_PATHT MIRANDA_PATHW L"\\Scripts" #define CUSTOM_SCRIPTS_PATHT MIRANDA_USERDATAW L"\\Scripts" -- cgit v1.2.3