diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2015-06-15 15:52:22 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2015-06-15 15:52:22 +0000 |
commit | 27985042841f1ea60156ed532e0b9f57e9c3b369 (patch) | |
tree | dfb25c2cbdb9b1d8896ce47d9620dd9a569ecf0b | |
parent | ff55088a637a2716d1ab950b42b992cce78f4f6b (diff) |
MirLua: added options page
git-svn-id: http://svn.miranda-ng.org/main/trunk@14179 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | plugins/MirLua/MirLua.vcxproj | 5 | ||||
-rw-r--r-- | plugins/MirLua/res/resource.rc | 33 | ||||
-rw-r--r-- | plugins/MirLua/src/main.cpp | 36 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua.cpp | 5 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua_options.cpp | 87 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua_options.h | 29 | ||||
-rw-r--r-- | plugins/MirLua/src/resource.h | 8 | ||||
-rw-r--r-- | plugins/MirLua/src/stdafx.h | 8 |
8 files changed, 200 insertions, 11 deletions
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 @@ <ImportGroup Label="PropertySheets">
<Import Project="$(ProjectDir)..\..\build\vc.common\plugin.props" />
</ImportGroup>
+ <ItemDefinitionGroup>
+ <Link>
+ <AdditionalDependencies>comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ </Link>
+ </ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="src\lua\*.h" />
<ClCompile Include="src\lua\*.c">
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<class T>
+ __inline void CreateLink(CCtrlData &ctrl, CMOption<T> &option)
+ {
+ ctrl.CreateDbLink(new CMOptionLink<T>(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 <windows.h>
+#include <commctrl.h>
#include <newpluginapi.h>
#include <m_core.h>
#include <m_utils.h>
#include <m_langpack.h>
#include <m_database.h>
+#include <m_options.h>
+#include <m_gui.h>
+
#include <m_clist.h>
#include <m_genmenu.h>
#include <m_icolib.h>
@@ -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"
|