diff options
author | George Hazan <george.hazan@gmail.com> | 2014-07-19 19:12:21 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2014-07-19 19:12:21 +0000 |
commit | 4105064506a4ea89fe17ed8007073faf3ccfe08c (patch) | |
tree | da93ad39e9b8addebafcf9f0a4d22987f90a802e | |
parent | 65c4f834ce1895cf4f3127f584458cc0af15c255 (diff) |
fix for a context menu
git-svn-id: http://svn.miranda-ng.org/main/trunk@9868 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | src/modules/database/database.cpp | 44 | ||||
-rw-r--r-- | src/modules/database/profilemanager.cpp | 128 |
2 files changed, 94 insertions, 78 deletions
diff --git a/src/modules/database/database.cpp b/src/modules/database/database.cpp index 74a110ee2f..a1da139802 100644 --- a/src/modules/database/database.cpp +++ b/src/modules/database/database.cpp @@ -39,7 +39,7 @@ bool fileExist(const TCHAR *fname) return false;
FILE *fp = _tfopen(fname, _T("r+"));
- bool res = fp != NULL;
+ bool res = (fp != NULL);
if (fp) fclose(fp);
return res;
}
@@ -98,7 +98,7 @@ static bool showProfileManager(void) {
TCHAR Mgr[32];
// is control pressed?
- if (GetAsyncKeyState(VK_CONTROL)&0x8000)
+ if (GetAsyncKeyState(VK_CONTROL) & 0x8000)
return 1;
// wanna show it?
@@ -184,17 +184,15 @@ static void moveProfileDirProfiles(TCHAR *profiledir, BOOL isRootDir = TRUE) {
TCHAR pfd[MAX_PATH];
if (isRootDir)
- _tcsncpy(pfd, VARST( _T("%miranda_path%\\*.dat")), SIZEOF(pfd));
+ _tcsncpy(pfd, VARST(_T("%miranda_path%\\*.dat")), SIZEOF(pfd));
else
mir_sntprintf(pfd, SIZEOF(pfd), _T("%s\\*.dat"), profiledir);
WIN32_FIND_DATA ffd;
HANDLE hFind = FindFirstFile(pfd, &ffd);
- if (hFind != INVALID_HANDLE_VALUE)
- {
+ if (hFind != INVALID_HANDLE_VALUE) {
TCHAR *c = _tcsrchr(pfd, '\\'); if (c) *c = 0;
- do
- {
+ do {
TCHAR path[MAX_PATH], path2[MAX_PATH];
TCHAR* profile = mir_tstrdup(ffd.cFileName);
TCHAR *c = _tcsrchr(profile, '.'); if (c) *c = 0;
@@ -219,7 +217,7 @@ static void moveProfileDirProfiles(TCHAR *profiledir, BOOL isRootDir = TRUE) }
mir_free(profile);
}
- while (FindNextFile(hFind, &ffd));
+ while (FindNextFile(hFind, &ffd));
}
FindClose(hFind);
}
@@ -256,7 +254,8 @@ static int getProfile1(TCHAR *szProfile, size_t cch, TCHAR *profiledir, BOOL * n if (++found == 1 && nodprof)
_tcscpy(szProfile, newProfile);
}
- } while (FindNextFile(hFind, &ffd));
+ }
+ while (FindNextFile(hFind, &ffd));
FindClose(hFind);
}
@@ -301,8 +300,8 @@ static int getProfile(TCHAR *szProfile, size_t cch) return 0;
}
- PROFILEMANAGERDATA pd = {0};
- if ( CmdLine_GetOption( _T("ForceShowPM"))) {
+ PROFILEMANAGERDATA pd = { 0 };
+ if (CmdLine_GetOption(_T("ForceShowPM"))) {
LBL_Show:
pd.szProfile = szProfile;
pd.szProfileDir = g_profileDir;
@@ -329,9 +328,9 @@ LBL_Show: // carefully converts a file name from TCHAR* to char*
char* makeFileName(const TCHAR* tszOriginalName)
{
- char* szResult = NULL;
- char* szFileName = mir_t2a(tszOriginalName);
- TCHAR* tszFileName = mir_a2t(szFileName);
+ char *szResult = NULL;
+ char *szFileName = mir_t2a(tszOriginalName);
+ TCHAR *tszFileName = mir_a2t(szFileName);
if (_tcscmp(tszOriginalName, tszFileName)) {
TCHAR tszProfile[MAX_PATH];
if (GetShortPathName(tszOriginalName, tszProfile, MAX_PATH) != 0)
@@ -352,7 +351,7 @@ int tryOpenDatabase(const TCHAR *tszProfile) {
bool bWasOpened = false;
- for (int i=arDbPlugins.getCount()-1; i >= 0; i--) {
+ for (int i = arDbPlugins.getCount() - 1; i >= 0; i--) {
DATABASELINK *p = arDbPlugins[i];
// liked the profile?
@@ -383,12 +382,12 @@ int tryOpenDatabase(const TCHAR *tszProfile) }
// enumerate all plugins that had valid DatabasePluginInfo()
-static int tryCreateDatabase(const TCHAR* ptszProfile)
+static int tryCreateDatabase(const TCHAR *ptszProfile)
{
- TCHAR* tszProfile = NEWTSTR_ALLOCA(ptszProfile);
+ TCHAR *tszProfile = NEWTSTR_ALLOCA(ptszProfile);
CreatePathToFileT(tszProfile);
- for (int i=0; i < arDbPlugins.getCount(); i++) {
+ for (int i = 0; i < arDbPlugins.getCount(); i++) {
DATABASELINK* p = arDbPlugins[i];
int err = p->makeDatabase(tszProfile);
@@ -417,7 +416,7 @@ typedef struct { static BOOL CALLBACK EnumMirandaWindows(HWND hwnd, LPARAM lParam)
{
TCHAR classname[256];
- ENUMMIRANDAWINDOW * x = (ENUMMIRANDAWINDOW *)lParam;
+ ENUMMIRANDAWINDOW *x = (ENUMMIRANDAWINDOW *)lParam;
DWORD_PTR res = 0;
if (GetClassName(hwnd, classname, SIZEOF(classname)) && lstrcmp(_T("Miranda"), classname) == 0) {
if (SendMessageTimeout(hwnd, x->msg, (WPARAM)x->aPath, 0, SMTO_ABORTIFHUNG, 100, &res) && res) {
@@ -430,7 +429,7 @@ static BOOL CALLBACK EnumMirandaWindows(HWND hwnd, LPARAM lParam) static int FindMirandaForProfile(TCHAR *szProfile)
{
- ENUMMIRANDAWINDOW x = {0};
+ ENUMMIRANDAWINDOW x = { 0 };
x.profile = szProfile;
x.msg = RegisterWindowMessage(_T("Miranda::ProcessProfile"));
x.aPath = GlobalAddAtom(szProfile);
@@ -466,7 +465,7 @@ int LoadDatabaseModule(void) int rc;
do {
retry = false;
- if ( _taccess(szProfile, 0) && shouldAutoCreate(szProfile))
+ if (_taccess(szProfile, 0) && shouldAutoCreate(szProfile))
rc = tryCreateDatabase(szProfile);
else
rc = tryOpenDatabase(szProfile);
@@ -487,8 +486,7 @@ int LoadDatabaseModule(void) retry = MessageBox(0, buf, TranslateT("Miranda can't open that profile"), MB_RETRYCANCEL | MB_ICONERROR) == IDRETRY;
}
}
- }
- while (retry);
+ } while (retry);
if (rc == ERROR_SUCCESS) {
InitIni();
diff --git a/src/modules/database/profilemanager.cpp b/src/modules/database/profilemanager.cpp index d54e1340f8..4c1d4fec2f 100644 --- a/src/modules/database/profilemanager.cpp +++ b/src/modules/database/profilemanager.cpp @@ -82,14 +82,17 @@ static void ThemeDialogBackground(HWND hwnd) EnableThemeDialogTexture(hwnd, ETDT_ENABLETAB);
}
+/////////////////////////////////////////////////////////////////////////////////////////
+// Profile creator
+
static int findProfiles(TCHAR *szProfileDir, ENUMPROFILECALLBACK callback, LPARAM lParam)
{
// find in Miranda NG profile subfolders
- HANDLE hFind = INVALID_HANDLE_VALUE;
- WIN32_FIND_DATA ffd;
TCHAR searchspec[MAX_PATH];
mir_sntprintf(searchspec, SIZEOF(searchspec), _T("%s\\*.*"), szProfileDir);
- hFind = FindFirstFile(searchspec, &ffd);
+
+ WIN32_FIND_DATA ffd;
+ HANDLE hFind = FindFirstFile(searchspec, &ffd);
if (hFind == INVALID_HANDLE_VALUE)
return 0;
@@ -255,6 +258,9 @@ static INT_PTR CALLBACK DlgProfileNew(HWND hwndDlg, UINT msg, WPARAM wParam, LPA return FALSE;
}
+/////////////////////////////////////////////////////////////////////////////////////////
+// Profile selector
+
BOOL EnumProfilesForList(TCHAR *tszFullPath, TCHAR *profile, LPARAM lParam)
{
ProfileEnumData *ped = (ProfileEnumData*)lParam;
@@ -421,6 +427,65 @@ static void CheckRun(HWND hwndDlg, int uMsg) EndDialog(GetParent(hwndDlg), 1);
}
+static void ExecuteMenu(HWND hwndDlg, LPARAM lParam)
+{
+ HWND hwndList = GetDlgItem(hwndDlg, IDC_PROFILELIST);
+ DlgProfData *dat = (DlgProfData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
+
+ LVHITTESTINFO lvht = { 0 };
+ lvht.pt.x = GET_X_LPARAM(lParam);
+ lvht.pt.y = GET_Y_LPARAM(lParam);
+ ScreenToClient(hwndList, &lvht.pt);
+
+ bool bConvert = false;
+ if (ListView_HitTest(hwndList, &lvht) == -1)
+ return;
+
+ if (lvht.iItem == -1)
+ return;
+
+ LVITEM tvi;
+ tvi.mask = LVIF_IMAGE;
+ tvi.iItem = lvht.iItem;
+ if (!ListView_GetItem(hwndList, &tvi))
+ return;
+
+ if (tvi.iImage == 2)
+ bConvert = true;
+
+ lvht.pt.x = GET_X_LPARAM(lParam);
+ lvht.pt.y = GET_Y_LPARAM(lParam);
+
+ HMENU hMenu = CreatePopupMenu();
+ if (tvi.iImage < 2) {
+ AppendMenu(hMenu, MF_STRING, 1, TranslateT("Run"));
+ AppendMenu(hMenu, MF_SEPARATOR, 0, NULL);
+ }
+ if (tvi.iImage != 3 && ServiceExists(MS_DB_CHECKPROFILE)) {
+ if (bConvert)
+ AppendMenu(hMenu, MF_STRING, 2, TranslateT("Convert database"));
+ else
+ AppendMenu(hMenu, MF_STRING, 2, TranslateT("Check database"));
+ AppendMenu(hMenu, MF_SEPARATOR, 0, NULL);
+ }
+ AppendMenu(hMenu, MF_STRING, 3, TranslateT("Delete"));
+ int index = TrackPopupMenu(hMenu, TPM_RETURNCMD, lvht.pt.x, lvht.pt.y, 0, hwndDlg, NULL);
+ switch (index) {
+ case 1:
+ SendMessage(GetParent(hwndDlg), WM_COMMAND, IDOK, 0);
+ break;
+
+ case 2:
+ CheckProfile(hwndList, lvht.iItem, dat);
+ break;
+
+ case 3:
+ DeleteProfile(hwndList, lvht.iItem, dat);
+ break;
+ }
+ DestroyMenu(hMenu);
+}
+
static INT_PTR CALLBACK DlgProfileSelect(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
DlgProfData *dat = (DlgProfData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
@@ -501,57 +566,7 @@ static INT_PTR CALLBACK DlgProfileSelect(HWND hwndDlg, UINT msg, WPARAM wParam, break;
case WM_CONTEXTMENU:
- {
- LVHITTESTINFO lvht = { 0 };
- lvht.pt.x = GET_X_LPARAM(lParam);
- lvht.pt.y = GET_Y_LPARAM(lParam);
- ScreenToClient(hwndList, &lvht.pt);
-
- bool bConvert = false;
- if (ListView_HitTest(hwndList, &lvht) != -1) {
- if (lvht.iItem == -1)
- break;
-
- LVITEM tvi;
- tvi.mask = LVIF_IMAGE;
- tvi.iItem = lvht.iItem;
- if (!ListView_GetItem(hwndList, &tvi))
- break;
-
- if (tvi.iImage == 2)
- bConvert = true;
- }
-
- lvht.pt.x = GET_X_LPARAM(lParam);
- lvht.pt.y = GET_Y_LPARAM(lParam);
-
- HMENU hMenu = CreatePopupMenu();
- AppendMenu(hMenu, MF_STRING, 1, TranslateT("Run"));
- AppendMenu(hMenu, MF_SEPARATOR, 0, NULL);
- if (ServiceExists(MS_DB_CHECKPROFILE)) {
- if (bConvert)
- AppendMenu(hMenu, MF_STRING, 2, TranslateT("Convert database"));
- else
- AppendMenu(hMenu, MF_STRING, 2, TranslateT("Check database"));
- AppendMenu(hMenu, MF_SEPARATOR, 0, NULL);
- }
- AppendMenu(hMenu, MF_STRING, 3, TranslateT("Delete"));
- int index = TrackPopupMenu(hMenu, TPM_RETURNCMD, lvht.pt.x, lvht.pt.y, 0, hwndDlg, NULL);
- switch (index) {
- case 1:
- SendMessage(GetParent(hwndDlg), WM_COMMAND, IDOK, 0);
- break;
-
- case 2:
- CheckProfile(hwndList, lvht.iItem, dat);
- break;
-
- case 3:
- DeleteProfile(hwndList, lvht.iItem, dat);
- break;
- }
- DestroyMenu(hMenu);
- }
+ ExecuteMenu(hwndDlg, lParam);
break;
case WM_NOTIFY:
@@ -594,6 +609,9 @@ static INT_PTR CALLBACK DlgProfileSelect(HWND hwndDlg, UINT msg, WPARAM wParam, return FALSE;
}
+/////////////////////////////////////////////////////////////////////////////////////////
+// Tab manager + its envelope
+
static INT_PTR CALLBACK DlgProfileManager(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
DetailsData *dat = (DetailsData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
@@ -831,7 +849,7 @@ static int AddProfileManagerPage(struct DetailsPageInit *opi, OPTIONSDIALOGPAGE opi->odp = (OPTIONSDIALOGPAGE*)mir_realloc(opi->odp, sizeof(OPTIONSDIALOGPAGE)*(opi->pageCount + 1));
- OPTIONSDIALOGPAGE* p = opi->odp + opi->pageCount++;
+ OPTIONSDIALOGPAGE *p = opi->odp + opi->pageCount++;
p->cbSize = sizeof(OPTIONSDIALOGPAGE);
p->hInstance = odp->hInstance;
p->pfnDlgProc = odp->pfnDlgProc;
|