diff options
Diffstat (limited to 'plugins/Folders/src/dlg_handlers.cpp')
-rw-r--r-- | plugins/Folders/src/dlg_handlers.cpp | 292 |
1 files changed, 132 insertions, 160 deletions
diff --git a/plugins/Folders/src/dlg_handlers.cpp b/plugins/Folders/src/dlg_handlers.cpp index 8bd851f207..4419aeb6e1 100644 --- a/plugins/Folders/src/dlg_handlers.cpp +++ b/plugins/Folders/src/dlg_handlers.cpp @@ -4,45 +4,13 @@ PFolderItem lastItem = NULL; static int bInitializing = 0;
-int GetCurrentItemSelection(HWND hWnd)
+static PFolderItem GetSelectedItem(HWND hWnd)
{
- return SendDlgItemMessage(hWnd, IDC_FOLDERS_ITEMS_LIST, LB_GETCURSEL, 0, 0);
-}
-
-int GetCurrentSectionSelection(HWND hWnd)
-{
- return SendDlgItemMessage(hWnd, IDC_FOLDERS_SECTIONS_LIST, LB_GETCURSEL, 0, 0);
-}
-
-int GetCurrentItemText(HWND hWnd, TCHAR *buffer, int count)
-{
- int index = GetCurrentItemSelection(hWnd);
- if (index != LB_ERR) {
- SendDlgItemMessage(hWnd, IDC_FOLDERS_ITEMS_LIST, LB_GETTEXT, index, (LPARAM)buffer);
- return 1;
- }
-
- buffer[0] = L'\0';
- return 0;
-}
-
-int GetCurrentSectionText(HWND hWnd, char *buffer, int count)
-{
- int index = GetCurrentSectionSelection(hWnd);
- if (index != LB_ERR)
- SendDlgItemMessageA(hWnd, IDC_FOLDERS_SECTIONS_LIST, LB_GETTEXT, index, (LPARAM)buffer);
- else
- buffer[0] = L'0';
- return index;
-}
-
-PFolderItem GetSelectedItem(HWND hWnd)
-{
- char section[MAX_FOLDER_SIZE];
- TCHAR item[MAX_FOLDER_SIZE];
- GetCurrentItemText(hWnd, item, MAX_FOLDER_SIZE);
- GetCurrentSectionText(hWnd, section, MAX_FOLDER_SIZE);
- return lstRegisteredFolders.GetTranslated(section, item);
+ int index = SendDlgItemMessage(hWnd, IDC_FOLDERS_ITEMS_LIST, LB_GETCURSEL, 0, 0);
+ if (index == LB_ERR)
+ return NULL;
+
+ return (PFolderItem)SendDlgItemMessage(hWnd, IDC_FOLDERS_ITEMS_LIST, LB_GETITEMDATA, index, 0);
}
static void GetEditText(HWND hWnd, TCHAR *buffer, int size)
@@ -50,60 +18,72 @@ static void GetEditText(HWND hWnd, TCHAR *buffer, int size) GetWindowText( GetDlgItem(hWnd, IDC_FOLDER_EDIT), buffer, size);
}
-void SetEditText(HWND hWnd, const TCHAR *buffer)
+static void SetEditText(HWND hWnd, const TCHAR *buffer)
{
bInitializing = 1;
SetWindowText(GetDlgItem(hWnd, IDC_FOLDER_EDIT), buffer);
bInitializing = 0;
}
-int ContainsSection(HWND hWnd, const WCHAR *section)
+static int ContainsSection(HWND hWnd, const TCHAR *section)
{
- int index = SendDlgItemMessage(hWnd, IDC_FOLDERS_SECTIONS_LIST, LB_FINDSTRINGEXACT, -1, (LPARAM) section);
+ int index = SendDlgItemMessage(hWnd, IDC_FOLDERS_SECTIONS_LIST, LB_FINDSTRINGEXACT, -1, (LPARAM)section);
return (index != LB_ERR);
}
-void LoadRegisteredFolderSections(HWND hWnd)
+static void LoadRegisteredFolderSections(HWND hWnd)
{
HWND hwndList = GetDlgItem(hWnd, IDC_FOLDERS_SECTIONS_LIST);
- for (int i = 0; i < lstRegisteredFolders.Count(); i++) {
- PFolderItem tmp = lstRegisteredFolders.Get(i + 1);
- TCHAR *translated = mir_a2t( tmp->GetSection());
+ for (int i=0; i < lstRegisteredFolders.getCount(); i++) {
+ CFolderItem &tmp = lstRegisteredFolders[i];
+ TCHAR *translated = mir_a2t( tmp.GetSection());
if ( !ContainsSection(hWnd, TranslateTS(translated))) {
int idx = SendMessage(hwndList, LB_ADDSTRING, 0, (LPARAM)TranslateTS(translated));
- SendMessage(hwndList, LB_SETITEMDATA, idx, (LPARAM)tmp->GetSection());
+ SendMessage(hwndList, LB_SETITEMDATA, idx, (LPARAM)tmp.GetSection());
}
mir_free(translated);
}
}
-void LoadRegisteredFolderItems(HWND hWnd)
+static void LoadRegisteredFolderItems(HWND hWnd)
{
- int idx = GetCurrentSectionSelection(hWnd);
+ int idx = SendDlgItemMessage(hWnd, IDC_FOLDERS_SECTIONS_LIST, LB_GETCURSEL, 0, 0);
char* szSection = (char*)SendDlgItemMessage(hWnd, IDC_FOLDERS_SECTIONS_LIST, LB_GETITEMDATA, idx, 0);
- SendDlgItemMessage(hWnd, IDC_FOLDERS_ITEMS_LIST, LB_RESETCONTENT, 0, 0);
+ HWND hwndItems = GetDlgItem(hWnd, IDC_FOLDERS_ITEMS_LIST);
+ SendMessage(hwndItems, LB_RESETCONTENT, 0, 0);
- for (int i = 0; i < lstRegisteredFolders.Count(); i++) {
- PFolderItem item = lstRegisteredFolders.Get(i + 1);
- if ( !strcmp(szSection, item->GetSection()))
- SendDlgItemMessage(hWnd, IDC_FOLDERS_ITEMS_LIST, LB_ADDSTRING, 0, (LPARAM)TranslateTS(item->GetUserName()));
+ for (int i=0; i < lstRegisteredFolders.getCount(); i++) {
+ CFolderItem &item = lstRegisteredFolders[i];
+ if ( !strcmp(szSection, item.GetSection())) {
+ int idx = SendMessage(hwndItems, LB_ADDSTRING, 0, (LPARAM)TranslateTS(item.GetUserName()));
+ SendMessage(hwndItems, LB_SETITEMDATA, idx, (LPARAM)&item);
+ }
}
- SendDlgItemMessage(hWnd, IDC_FOLDERS_ITEMS_LIST, LB_SETCURSEL, 0, 0); //select the first item
+ SendMessage(hwndItems, LB_SETCURSEL, 0, 0); //select the first item
PostMessage(hWnd, WM_COMMAND, MAKEWPARAM(IDC_FOLDERS_ITEMS_LIST, LBN_SELCHANGE), 0); //tell the dialog to refresh the preview
}
-void LoadItem(HWND hWnd, PFolderItem item)
+static void RefreshPreview(HWND hWnd)
{
- if (item) {
- SetEditText(hWnd, item->GetFormat());
- RefreshPreview(hWnd);
- }
+ TCHAR tmp[MAX_FOLDER_SIZE], res[MAX_FOLDER_SIZE];
+ GetEditText(hWnd, tmp, MAX_FOLDER_SIZE);
+ ExpandPath(res, tmp, MAX_FOLDER_SIZE);
+ SetWindowText(GetDlgItem(hWnd, IDC_PREVIEW_EDIT), res);
+}
+
+static void LoadItem(HWND hWnd, PFolderItem item)
+{
+ if (!item)
+ return;
+
+ SetEditText(hWnd, item->GetFormat());
+ RefreshPreview(hWnd);
}
-void SaveItem(HWND hWnd, PFolderItem item, int bEnableApply)
+static void SaveItem(HWND hWnd, PFolderItem item, int bEnableApply)
{
if (!item)
return;
@@ -116,44 +96,84 @@ void SaveItem(HWND hWnd, PFolderItem item, int bEnableApply) SendMessage(GetParent(hWnd), PSM_CHANGED, 0, 0);
}
-int ChangesNotSaved(HWND hWnd, PFolderItem item)
+static int ChangesNotSaved(HWND hWnd, PFolderItem item)
{
- int res = 0;
- if (item) {
- TCHAR buffer[MAX_FOLDER_SIZE];
- GetEditText(hWnd, buffer, MAX_FOLDER_SIZE);
- res = _tcscmp(item->GetFormat(), buffer) != 0;
- }
-
- return res;
+ if (!item)
+ return 0;
+
+ TCHAR buffer[MAX_FOLDER_SIZE];
+ GetEditText(hWnd, buffer, MAX_FOLDER_SIZE);
+ return _tcscmp(item->GetFormat(), buffer) != 0;
}
-void CheckForChanges(HWND hWnd, int bNeedConfirmation = 1)
+static void CheckForChanges(HWND hWnd, int bNeedConfirmation = 1)
{
if (ChangesNotSaved(hWnd, lastItem))
if ((!bNeedConfirmation) || MessageBox(hWnd, TranslateT("Some changes weren't saved. Apply the changes now ?"), TranslateT("Changes not saved"), MB_YESNO | MB_ICONINFORMATION) == IDYES)
- SaveItem(hWnd, lastItem);
+ SaveItem(hWnd, lastItem, TRUE);
}
-void RefreshPreview(HWND hWnd)
+/************************************** DIALOG HANDLERS *************************************/
+
+static INT_PTR CALLBACK DlgProcVariables(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
- TCHAR tmp[MAX_FOLDER_SIZE], res[MAX_FOLDER_SIZE];
- GetEditText(hWnd, tmp, MAX_FOLDER_SIZE);
- ExpandPath(res, tmp, MAX_FOLDER_SIZE);
- SetWindowText(GetDlgItem(hWnd, IDC_PREVIEW_EDIT), res);
-}
+ TCHAR tszMessage[2048];
+ switch (msg) {
+ case WM_INITDIALOG:
+ mir_sntprintf(tszMessage, SIZEOF(tszMessage), _T("%s\r\n%s\r\n\r\n%s\t\t%s\r\n%%miranda_path%%\t\t%s\r\n%%profile_path%%\t\t%s\r\n\t\t\t%s\r\n%%current_profile%%\t\t%s\r\n\t\t\t%s\r\n\r\n\r\n%s\r\n%s\r\n%s\r\n%s\r\n%s\r\n%s\r\n\r\n%s\r\n%s\r\n%s\r\n%%miranda_path%%\t\t\t%s\r\n%%profile_path%%\t\t\t%s\r\n%%current_profile%%\t\t\t%s\r\n%%temp%%\t\t\t\t%s\r\n%%profile_path%%\\%%current_profile%%\t%s\r\n%%miranda_path%%\\plugins\\config\t%s\r\n\' %%miranda_path%%\\\\\\\\ \'\t\t%s\r\n\r\n%s"),
+ TranslateT("Don\'t forget to click on Apply to save the changes. If you don\'t then the changes won\'t"),
+ TranslateT("be saved to the database, they will only be valid for this session."),
+ TranslateT("Variable string"),
+ TranslateT("What it expands to:"),
+ TranslateT("Expands to your miranda path (e.g: c:\\program files\\miranda ng)."),
+ TranslateT("Expands to your profile path - the value found in mirandaboot.ini,"),
+ TranslateT("ProfileDir section (usually inside miranda\'s folder)."),
+ TranslateT("Expands to your current profile name without the extenstion."),
+ TranslateT("(e.g.default if your your profile is default.dat)."),
+ TranslateT("Environment variables"),
+ TranslateT("The plugin can also expand environment variables; the variables are specified like in any other"),
+ TranslateT("program that can use environment variables, i.e. %<env variable>%."),
+ TranslateT("Note: Environment variables are expanded before any Miranda variables. So if you have, for"),
+ TranslateT("example, %profile_path% defined as a system variable then it will be expanded to that value"),
+ TranslateT("instead of expanding to Miranda\'s profile path."),
+ TranslateT("Examples:"),
+ TranslateT("If the value for the ProfileDir inside mirandaboot.ini, ProfileDir section is \'.\\profiles\\', current"),
+ TranslateT("profile is \'default.dat\' and miranda\'s path is \'c:\\program files\\miranda ng\\' then:"),
+ TranslateT("will expand to \'c:\\program files\\miranda ng\'"),
+ TranslateT("will expand to \'c:\\program files\\miranda ng\\profiles\'"),
+ TranslateT("will expand to \'default\'"),
+ TranslateT("will expand to the temp folder of the current user."),
+ TranslateT("will expand to \'c:\\program files\\miranda ng\\profiles\\default\'"),
+ TranslateT("will expand to \'c:\\program files\\miranda ng\\plugins\\config\'"),
+ TranslateT("will expand to \'c:\\program files\\miranda ng\'"),
+ TranslateT("Notice that the spaces at the beginning and the end of the string are trimmed, as well as the last."));
+ SetDlgItemText(hWnd, IDC_HELP_RICHEDIT, tszMessage);
+ TranslateDialogDefault(hWnd);
+ break;
-/************************************** DIALOG HANDLERS *************************************/
-#include "commctrl.h"
+ case WM_CLOSE:
+ DestroyWindow(hWnd);
+ break;
+
+ case WM_COMMAND:
+ if (LOWORD(wParam) == IDCLOSE)
+ DestroyWindow(hWnd);
+ break;
+ }
+
+ return 0;
+}
-INT_PTR CALLBACK DlgProcOpts(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
+static INT_PTR CALLBACK DlgProcOpts(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
+ PFolderItem item;
+
switch (msg) {
case WM_INITDIALOG:
- bInitializing = 1;
lastItem = NULL;
TranslateDialogDefault(hWnd);
+ bInitializing = 1;
LoadRegisteredFolderSections(hWnd);
bInitializing = 0;
break;
@@ -174,10 +194,7 @@ INT_PTR CALLBACK DlgProcOpts(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) break;
case IDC_HELP_BUTTON:
- {
- HWND helpDlg = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_VARIABLES_HELP), hWnd, DlgProcVariables);
- ShowWindow(helpDlg, SW_SHOW);
- }
+ ShowWindow( CreateDialog(hInstance, MAKEINTRESOURCE(IDD_VARIABLES_HELP), hWnd, DlgProcVariables), SW_SHOW);
break;
case IDC_FOLDERS_SECTIONS_LIST:
@@ -188,29 +205,20 @@ INT_PTR CALLBACK DlgProcOpts(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) lastItem = NULL;
SetEditText(hWnd, L"");
RefreshPreview(hWnd);
- break;
}
-
break;
case IDC_FOLDERS_ITEMS_LIST:
switch (HIWORD(wParam)) {
case LBN_SELCHANGE:
- {
- PFolderItem item = GetSelectedItem(hWnd);
- if (item != NULL) {
- CheckForChanges(hWnd);
- LoadItem(hWnd, item);
- }
- lastItem = item;
-
- break;
+ item = GetSelectedItem(hWnd);
+ if (item != NULL) {
+ CheckForChanges(hWnd);
+ LoadItem(hWnd, item);
}
+ lastItem = item;
}
-
- break;
}
-
break;
case WM_NOTIFY:
@@ -218,18 +226,15 @@ INT_PTR CALLBACK DlgProcOpts(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) case 0:
switch (((LPNMHDR)lParam)->code) {
case PSN_APPLY:
- {
- PFolderItem item = GetSelectedItem(hWnd);
- if (item) {
- SaveItem(hWnd, item, FALSE);
- LoadItem(hWnd, item);
- }
-
- lstRegisteredFolders.Save();
- CallPathChangedEvents();
-
- break;
+ item = GetSelectedItem(hWnd);
+ if (item) {
+ SaveItem(hWnd, item, FALSE);
+ LoadItem(hWnd, item);
}
+
+ for (int i=0; i < lstRegisteredFolders.getCount(); i++)
+ lstRegisteredFolders[i].Save();
+ CallPathChangedEvents();
}
}
break;
@@ -238,56 +243,23 @@ INT_PTR CALLBACK DlgProcOpts(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) return 0;
}
-INT_PTR CALLBACK DlgProcVariables(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
+static int OnOptionsInitialize(WPARAM wParam, LPARAM lParam)
{
- switch (msg) {
- case WM_INITDIALOG:
- {
- TCHAR tszMessage[2048];
- mir_sntprintf(tszMessage, SIZEOF(tszMessage), _T("%s\r\n%s\r\n\r\n%s\t\t%s\r\n%%miranda_path%%\t\t%s\r\n%%profile_path%%\t\t%s\r\n\t\t\t%s\r\n%%current_profile%%\t\t%s\r\n\t\t\t%s\r\n\r\n\r\n%s\r\n%s\r\n%s\r\n%s\r\n%s\r\n%s\r\n\r\n%s\r\n%s\r\n%s\r\n%%miranda_path%%\t\t\t%s\r\n%%profile_path%%\t\t\t%s\r\n%%current_profile%%\t\t\t%s\r\n%%temp%%\t\t\t\t%s\r\n%%profile_path%%\\%%current_profile%%\t%s\r\n%%miranda_path%%\\plugins\\config\t%s\r\n\' %%miranda_path%%\\\\\\\\ \'\t\t%s\r\n\r\n%s"),
- TranslateT("Don\'t forget to click on Apply to save the changes. If you don\'t then the changes won\'t"),
- TranslateT("be saved to the database, they will only be valid for this session."),
- TranslateT("Variable string"),
- TranslateT("What it expands to:"),
- TranslateT("Expands to your miranda path (e.g: c:\\program files\\miranda ng)."),
- TranslateT("Expands to your profile path - the value found in mirandaboot.ini,"),
- TranslateT("ProfileDir section (usually inside miranda\'s folder)."),
- TranslateT("Expands to your current profile name without the extenstion."),
- TranslateT("(e.g.default if your your profile is default.dat)."),
- TranslateT("Environment variables"),
- TranslateT("The plugin can also expand environment variables; the variables are specified like in any other"),
- TranslateT("program that can use environment variables, i.e. %<env variable>%."),
- TranslateT("Note: Environment variables are expanded before any Miranda variables. So if you have, for"),
- TranslateT("example, %profile_path% defined as a system variable then it will be expanded to that value"),
- TranslateT("instead of expanding to Miranda\'s profile path."),
- TranslateT("Examples:"),
- TranslateT("If the value for the ProfileDir inside mirandaboot.ini, ProfileDir section is \'.\\profiles\\', current"),
- TranslateT("profile is \'default.dat\' and miranda\'s path is \'c:\\program files\\miranda ng\\' then:"),
- TranslateT("will expand to \'c:\\program files\\miranda ng\'"),
- TranslateT("will expand to \'c:\\program files\\miranda ng\\profiles\'"),
- TranslateT("will expand to \'default\'"),
- TranslateT("will expand to the temp folder of the current user."),
- TranslateT("will expand to \'c:\\program files\\miranda ng\\profiles\\default\'"),
- TranslateT("will expand to \'c:\\program files\\miranda ng\\plugins\\config\'"),
- TranslateT("will expand to \'c:\\program files\\miranda ng\'"),
- TranslateT("Notice that the spaces at the beginning and the end of the string are trimmed, as well as the last."));
- SetDlgItemText(hWnd, IDC_HELP_RICHEDIT, tszMessage);
- TranslateDialogDefault(hWnd);
- }
- break;
-
- case WM_CLOSE:
- DestroyWindow(hWnd);
- break;
-
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDCLOSE:
- DestroyWindow(hWnd);
- break;
- }
- break;
- }
-
+ OPTIONSDIALOGPAGE odp = { sizeof(odp) };
+ odp.position = 100000000;
+ odp.hInstance = hInstance;
+ odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_FOLDERS);
+ odp.pszTitle = LPGEN("Folders");
+ odp.pszGroup = LPGEN("Customize");
+ odp.groupPosition = 910000000;
+ odp.flags = ODPF_BOLDGROUPS;
+ odp.pfnDlgProc = DlgProcOpts;
+ Options_AddPage(wParam, &odp);
+
return 0;
}
+
+void InitOptions()
+{
+ HookEvent(ME_OPT_INITIALISE, OnOptionsInitialize);
+}
|