From 7b87adc262873564dc0aab64a47c917373b76463 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 5 Jul 2015 12:11:49 +0000 Subject: menu options dialog: - recursive options' saving; - recursive options check; - CMIF_SYSTEM support git-svn-id: http://svn.miranda-ng.org/main/trunk@14492 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- src/mir_app/src/genmenu.h | 1 - src/mir_app/src/menu_options.cpp | 54 +++++++++++++++++++++----------------- src/mir_app/src/menu_utils.cpp | 56 +++++++++++++++------------------------- 3 files changed, 52 insertions(+), 59 deletions(-) diff --git a/src/mir_app/src/genmenu.h b/src/mir_app/src/genmenu.h index 36521c4189..69f51dc9d4 100644 --- a/src/mir_app/src/genmenu.h +++ b/src/mir_app/src/genmenu.h @@ -47,7 +47,6 @@ struct TMO_IntMenuItem int iCommand; int iconId; // icon index in the section's image list TMO_MenuItem mi; // user-defined data - BOOL OverrideShow; char* UniqName; // unique name TCHAR* CustomName; HANDLE hIcolibItem; // handle of iconlib item diff --git a/src/mir_app/src/menu_options.cpp b/src/mir_app/src/menu_options.cpp index 6e57e67f9d..7304f2d854 100644 --- a/src/mir_app/src/menu_options.cpp +++ b/src/mir_app/src/menu_options.cpp @@ -63,27 +63,17 @@ class CGenMenuOptionsPage : public CDlgBase int iInitMenuValue; bool bRebuild; - void SaveTree() - { - int MenuObjectId; - if (!GetCurrentMenuObjectID(MenuObjectId)) - return; - - TCHAR idstr[100]; + TCHAR idstr[100]; + void SaveTreeInternal(HTREEITEM hRootItem, const char *szModule) + { TVITEMEX tvi; - tvi.hItem = m_menuItems.GetRoot(); + tvi.hItem = hRootItem; tvi.cchTextMax = _countof(idstr); tvi.mask = TVIF_TEXT | TVIF_PARAM | TVIF_HANDLE | TVIF_IMAGE; tvi.pszText = idstr; int count = 0; - TIntMenuObject *pmo = GetMenuObjbyId(MenuObjectId); - if (pmo == NULL) - return; - - char MenuNameItems[256]; - mir_snprintf(MenuNameItems, _countof(MenuNameItems), "%s_Items", pmo->pszName); int runtimepos = 100; while (tvi.hItem != NULL) { @@ -94,17 +84,19 @@ class CGenMenuOptionsPage : public CDlgBase GetMenuItemName(iod->pimi, menuItemName, sizeof(menuItemName)); mir_snprintf(DBString, _countof(DBString), "%s_visible", menuItemName); - db_set_b(NULL, MenuNameItems, DBString, tvi.iImage != 0); + db_set_b(NULL, szModule, DBString, tvi.iImage != 0); mir_snprintf(DBString, _countof(DBString), "%s_pos", menuItemName); - db_set_dw(NULL, MenuNameItems, DBString, runtimepos); + db_set_dw(NULL, szModule, DBString, runtimepos); mir_snprintf(DBString, _countof(DBString), "%s_name", menuItemName); - if (iod->name != NULL && iod->defname != NULL && - mir_tstrcmp(iod->name, iod->defname) != 0) - db_set_ts(NULL, MenuNameItems, DBString, iod->name); + if (iod->name != NULL && iod->defname != NULL && mir_tstrcmp(iod->name, iod->defname) != 0) + db_set_ts(NULL, szModule, DBString, iod->name); else - db_unset(NULL, MenuNameItems, DBString); + db_unset(NULL, szModule, DBString); + + if (iod->pimi->submenu.first != NULL) + SaveTreeInternal(m_menuItems.GetChild(tvi.hItem), szModule); runtimepos += 100; } @@ -117,6 +109,22 @@ class CGenMenuOptionsPage : public CDlgBase } } + void SaveTree() + { + int MenuObjectId; + if (!GetCurrentMenuObjectID(MenuObjectId)) + return; + + TIntMenuObject *pmo = GetMenuObjbyId(MenuObjectId); + if (pmo == NULL) + return; + + char szModule[256]; + mir_snprintf(szModule, _countof(szModule), "%s_Items", pmo->pszName); + CallService(MS_DB_MODULE_DELETE, NULL, (LPARAM)szModule); + SaveTreeInternal(m_menuItems.GetRoot(), szModule); + } + void FreeTreeData() { HTREEITEM hItem = m_menuItems.GetRoot(); @@ -235,14 +243,14 @@ class CGenMenuOptionsPage : public CDlgBase if (pmo == NULL || pmo->m_items.first == NULL) return false; - char MenuNameItems[256]; - mir_snprintf(MenuNameItems, _countof(MenuNameItems), "%s_Items", pmo->pszName); + char szModule[256]; + mir_snprintf(szModule, _countof(szModule), "%s_Items", pmo->pszName); bRebuild = true; m_menuItems.SendMsg(WM_SETREDRAW, FALSE, 0); m_menuItems.DeleteAllItems(); - BuildTreeInternal(MenuNameItems, bReread, pmo->m_items.first, NULL); + BuildTreeInternal(szModule, bReread, pmo->m_items.first, NULL); m_menuItems.SendMsg(WM_SETREDRAW, TRUE, 0); bRebuild = false; diff --git a/src/mir_app/src/menu_utils.cpp b/src/mir_app/src/menu_utils.cpp index 758d3c8b5e..d918f8a906 100644 --- a/src/mir_app/src/menu_utils.cpp +++ b/src/mir_app/src/menu_utils.cpp @@ -713,7 +713,6 @@ MIR_APP_DLL(HGENMENU) Menu_AddItem(int hMenuObject, TMO_MenuItem *pmi, void *pUs p->iCommand = GetNextObjectMenuItemId(); p->mi = *pmi; p->iconId = -1; - p->OverrideShow = TRUE; p->originalPosition = pmi->position; p->pUserData = pUserData; @@ -862,14 +861,14 @@ void GetMenuItemName(TMO_IntMenuItem *pMenuItem, char* pszDest, size_t cbDestSiz mir_snprintf(pszDest, cbDestSize, "{%s}", pMenuItem->mi.name.t); } -static HMENU BuildRecursiveMenu(HMENU hMenu, TMO_IntMenuItem *pRootMenu, INT_PTR iRootLevel, WPARAM wParam, LPARAM lParam) +static HMENU BuildRecursiveMenu(HMENU hMenu, TMO_IntMenuItem *pRootMenu, WPARAM wParam, LPARAM lParam) { if (pRootMenu == NULL) return NULL; TIntMenuObject *pmo = pRootMenu->parent; - if (iRootLevel == 0) + if (pRootMenu->mi.root == NULL) while (GetMenuItemCount(hMenu) > 0) DeleteMenu(hMenu, 0, MF_BYPOSITION); @@ -884,54 +883,41 @@ static HMENU BuildRecursiveMenu(HMENU hMenu, TMO_IntMenuItem *pRootMenu, INT_PTR CheckParam.lParam = lParam; CheckParam.MenuItemOwnerData = pmi->pUserData; CheckParam.MenuItemHandle = pmi; - if (CallService(pmo->CheckService, (WPARAM)&CheckParam, 0) == FALSE) + if (CallService(pmo->CheckService, (WPARAM)&CheckParam, 0) == false) continue; } - /**************************************/ - if (iRootLevel == 0 && mi->root == NULL && pmo->m_bUseUserDefinedItems) { - char DBString[256]; - DBVARIANT dbv = { 0 }; - int pos; - char MenuNameItems[256]; - mir_snprintf(MenuNameItems, _countof(MenuNameItems), "%s_Items", pmo->pszName); + // if we have to check & apply database settings + if (!(mi->flags & CMIF_SYSTEM) && pmo->m_bUseUserDefinedItems) { + char szModule[256], szSetting[256]; + mir_snprintf(szModule, "%s_Items", pmo->pszName); char menuItemName[256]; GetMenuItemName(pmi, menuItemName, sizeof(menuItemName)); // check if it visible - mir_snprintf(DBString, _countof(DBString), "%s_visible", menuItemName); - if (db_get_b(NULL, MenuNameItems, DBString, -1) == -1) - db_set_b(NULL, MenuNameItems, DBString, 1); - - pmi->OverrideShow = TRUE; - if (!db_get_b(NULL, MenuNameItems, DBString, 1)) { - pmi->OverrideShow = FALSE; - continue; // find out what value to return if not getting added - } + mir_snprintf(szSetting, "%s_visible", menuItemName); + if (!db_get_b(NULL, szModule, szSetting, 1)) + continue; // mi.name.t - mir_snprintf(DBString, _countof(DBString), "%s_name", menuItemName); - if (!db_get_ts(NULL, MenuNameItems, DBString, &dbv)) { - if (mir_tstrlen(dbv.ptszVal) > 0) - replaceStrT(pmi->CustomName, dbv.ptszVal); - db_free(&dbv); + mir_snprintf(szSetting, "%s_name", menuItemName); + TCHAR *tszCustomName = db_get_tsa(NULL, szModule, szSetting); + if (tszCustomName != NULL) { + mir_free(pmi->CustomName); + pmi->CustomName = tszCustomName; } - mir_snprintf(DBString, _countof(DBString), "%s_pos", menuItemName); - if ((pos = db_get_dw(NULL, MenuNameItems, DBString, -1)) == -1) { - db_set_dw(NULL, MenuNameItems, DBString, mi->position); + mir_snprintf(szSetting, "%s_pos", menuItemName); + int pos = db_get_dw(NULL, szModule, szSetting, -1); + if (pos == -1) { + db_set_dw(NULL, szModule, szSetting, mi->position); if (pmi->submenu.first) mi->position = 0; } else mi->position = pos; } - /**************************************/ - - if (iRootLevel != (INT_PTR)pmi->mi.root) - continue; - int i = WhereToPlace(hMenu, mi); MENUITEMINFO mii = { 0 }; @@ -970,7 +956,7 @@ static HMENU BuildRecursiveMenu(HMENU hMenu, TMO_IntMenuItem *pRootMenu, INT_PTR #endif InsertMenuItemWithSeparators(hMenu, i, &mii); - BuildRecursiveMenu(mii.hSubMenu, pmi->submenu.first, LPARAM(pmi), wParam, lParam); + BuildRecursiveMenu(mii.hSubMenu, pmi->submenu.first, wParam, lParam); } else { mii.wID = pmi->iCommand; @@ -1014,7 +1000,7 @@ EXTERN_C MIR_APP_DLL(HMENU) Menu_Build(HMENU parent, int hMenuObject, WPARAM wPa // DumpMenuItem(pmo->m_items.first); #endif - return BuildRecursiveMenu(parent, pmo->m_items.first, 0, wParam, lParam); + return BuildRecursiveMenu(parent, pmo->m_items.first, wParam, lParam); } ///////////////////////////////////////////////////////////////////////////////////////// -- cgit v1.2.3