summaryrefslogtreecommitdiff
path: root/src/mir_app
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2015-12-01 20:17:06 +0000
committerGeorge Hazan <george.hazan@gmail.com>2015-12-01 20:17:06 +0000
commite11fbeaf4ec32501aaa8a472ca15e8b630815572 (patch)
treeac3a8e6ac61822cbf2362d888d4dbdd3bdb7a49a /src/mir_app
parent91a46d8c66ce4d185e2cc1d12338a07cbb198c0a (diff)
new UUID-based menu editor & convertor
git-svn-id: http://svn.miranda-ng.org/main/trunk@15797 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'src/mir_app')
-rw-r--r--src/mir_app/src/menu_options.cpp74
-rw-r--r--src/mir_app/src/menu_utils.cpp94
2 files changed, 108 insertions, 60 deletions
diff --git a/src/mir_app/src/menu_options.cpp b/src/mir_app/src/menu_options.cpp
index 2b7fafaa97..b67cf8c99b 100644
--- a/src/mir_app/src/menu_options.cpp
+++ b/src/mir_app/src/menu_options.cpp
@@ -24,6 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "stdafx.h"
#include "genmenu.h"
+#include "plugins.h"
#define STR_SEPARATOR _T("-----------------------------------")
@@ -79,23 +80,23 @@ class CGenMenuOptionsPage : public CDlgBase
while (tvi.hItem != NULL) {
m_menuItems.GetItem(&tvi);
MenuItemOptData *iod = (MenuItemOptData*)tvi.lParam;
- if (iod->pimi) {
- char menuItemName[256], DBString[300];
- GetMenuItemName(iod->pimi, menuItemName, sizeof(menuItemName));
-
- mir_snprintf(DBString, "%s_visible", menuItemName);
- db_set_b(NULL, szModule, DBString, tvi.iImage != 0);
-
- mir_snprintf(DBString, "%s_pos", menuItemName);
- db_set_dw(NULL, szModule, DBString, runtimepos);
-
- mir_snprintf(DBString, "%s_name", menuItemName);
- 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, szModule, DBString);
-
- if (iod->pimi->submenu.first != NULL)
+ if (TMO_IntMenuItem *pimi = iod->pimi) {
+ if (!equalUUID(pimi->mi.uid, MIID_LAST)) {
+ char menuItemName[256];
+ bin2hex(&pimi->mi.uid, sizeof(pimi->mi.uid), menuItemName);
+
+ int visible = tvi.iImage != 0;
+ TCHAR *ptszCustomName;
+ if (iod->name != NULL && iod->defname != NULL && mir_tstrcmp(iod->name, iod->defname) != 0)
+ ptszCustomName = iod->name;
+ else
+ ptszCustomName = _T("");
+
+ CMString tszValue(FORMAT, _T("%d;%d;%s"), visible, pimi->mi.position, ptszCustomName);
+ db_set_ts(NULL, (char*)szModule, menuItemName, tszValue);
+ }
+
+ if (pimi->submenu.first != NULL)
SaveTreeInternal(m_menuItems.GetChild(tvi.hItem), szModule);
runtimepos += 100;
@@ -123,6 +124,7 @@ class CGenMenuOptionsPage : public CDlgBase
mir_snprintf(szModule, "%s_Items", pmo->pszName);
CallService(MS_DB_MODULE_DELETE, NULL, (LPARAM)szModule);
SaveTreeInternal(m_menuItems.GetRoot(), szModule);
+ db_set_b(NULL, szModule, "MenuFormat", 1);
}
void FreeTreeData()
@@ -155,33 +157,35 @@ class CGenMenuOptionsPage : public CDlgBase
for (TMO_IntMenuItem *p = pFirst; p != NULL; p = p->next) {
// filter out items whose presence & position might not be changed
- if (p->mi.flags & CMIF_SYSTEM)
+ if (p->mi.flags & CMIF_SYSTEM)
continue;
- char menuItemName[256];
- GetMenuItemName(p, menuItemName, _countof(menuItemName));
+ TCHAR customName[201]; customName[0] = 0;
+ int visible = 1, pos = 0;
+ if (!equalUUID(p->mi.uid, MIID_LAST)) {
+ char menuItemName[256];
+ bin2hex(&p->mi.uid, sizeof(p->mi.uid), menuItemName);
+ ptrT tszSettings(db_get_tsa(NULL, pszModule, menuItemName));
+ if (tszSettings == NULL)
+ continue;
+
+ if (_stscanf(tszSettings, _T("%d;%d;%200s"), &visible, &pos, customName) < 2)
+ continue;
+ }
MenuItemOptData *PD = new MenuItemOptData();
-
- char buf[256];
- mir_snprintf(buf, "%s_name", menuItemName);
- ptrT tszName(db_get_tsa(NULL, pszModule, buf));
- if (tszName != 0)
- PD->name = tszName.detach();
+ if (customName[0] != 0)
+ PD->name = mir_tstrdup(customName);
else
PD->name = mir_tstrdup(GetMenuItemText(p));
PD->pimi = p;
PD->defname = mir_tstrdup(GetMenuItemText(p));
-
- mir_snprintf(buf, "%s_visible", menuItemName);
- PD->bShow = db_get_b(NULL, pszModule, buf, 1) != 0;
-
- if (bReread) {
- mir_snprintf(buf, "%s_pos", menuItemName);
- PD->pos = db_get_dw(NULL, pszModule, buf, 1);
- }
- else PD->pos = (PD->pimi) ? PD->pimi->originalPosition : 0;
+ PD->bShow = visible != 0;
+ if (bReread)
+ PD->pos = pos;
+ else
+ PD->pos = (PD->pimi) ? PD->pimi->originalPosition : 0;
PD->id = p->iCommand;
diff --git a/src/mir_app/src/menu_utils.cpp b/src/mir_app/src/menu_utils.cpp
index 28d0934878..a91876d1ff 100644
--- a/src/mir_app/src/menu_utils.cpp
+++ b/src/mir_app/src/menu_utils.cpp
@@ -24,6 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "stdafx.h"
#include "genmenu.h"
+#include "plugins.h"
static bool bIsGenMenuInited;
bool bIconsDisabled;
@@ -851,12 +852,33 @@ void GetMenuItemName(TMO_IntMenuItem *pMenuItem, char* pszDest, size_t cbDestSiz
mir_snprintf(pszDest, cbDestSize, "{%s}", pMenuItem->mi.name.t);
}
+static int sttDumpItem(TMO_IntMenuItem *pmi, void *szModule)
+{
+ if (!equalUUID(pmi->mi.uid, MIID_LAST)) {
+ char menuItemName[200];
+ bin2hex(&pmi->mi.uid, sizeof(pmi->mi.uid), menuItemName);
+
+ int visible = (pmi->mi.flags & CMIF_HIDDEN) == 0;
+ TCHAR *ptszName = (pmi->CustomName != NULL) ? pmi->CustomName : _T("");
+
+ CMString szNewValue(FORMAT, _T("%d;%d;%s"), visible, pmi->mi.position, ptszName);
+ db_set_ts(NULL, (char*)szModule, menuItemName, szNewValue);
+
+ Netlib_Logf(NULL, "MENU[%s] => %s, %d, %d", menuItemName, pmi->UniqName, visible, pmi->mi.position);
+ }
+ return 0;
+}
+
static HMENU BuildRecursiveMenu(HMENU hMenu, TMO_IntMenuItem *pRootMenu, WPARAM wParam, LPARAM lParam)
{
if (pRootMenu == NULL)
return NULL;
+ char szModule[256];
TIntMenuObject *pmo = pRootMenu->parent;
+ mir_snprintf(szModule, "%s_Items", pmo->pszName);
+
+ bool bOldMenuFormat = db_get_b(NULL, szModule, "MenuFormat", false) == 0;
if (pRootMenu->mi.root == NULL)
while (GetMenuItemCount(hMenu) > 0)
@@ -879,33 +901,47 @@ static HMENU BuildRecursiveMenu(HMENU hMenu, TMO_IntMenuItem *pRootMenu, WPARAM
// 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(szSetting, "%s_visible", menuItemName);
- if (!db_get_b(NULL, szModule, szSetting, 1))
- continue;
-
- // mi.name.t
- mir_snprintf(szSetting, "%s_name", menuItemName);
- TCHAR *tszCustomName = db_get_tsa(NULL, szModule, szSetting);
- if (tszCustomName != NULL) {
- mir_free(pmi->CustomName);
- pmi->CustomName = tszCustomName;
+ char szSetting[256], menuItemName[256];
+ int visible = 0, pos = 0;
+ if (bOldMenuFormat) {
+ GetMenuItemName(pmi, menuItemName, sizeof(menuItemName));
+
+ // check if it visible
+ mir_snprintf(szSetting, "%s_visible", menuItemName);
+ visible = db_get_b(NULL, szModule, szSetting, 1);
+
+ // mi.name.t
+ 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(szSetting, "%s_pos", menuItemName);
+ pos = db_get_dw(NULL, szModule, szSetting, -1);
+ if (pos == -1) {
+ if (pmi->submenu.first)
+ mi->position = 0;
+ }
+ else mi->position = pos;
}
-
- 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 {
+ if (!equalUUID(mi->uid, MIID_LAST)) {
+ bin2hex(&mi->uid, sizeof(mi->uid), menuItemName);
+ ptrT szValue(db_get_tsa(NULL, szModule, menuItemName));
+ if (szValue != NULL) {
+ TCHAR tszCustomName[201]; tszCustomName[0] = 0;
+ _stscanf(szValue, _T("%d;%d;%200s"), &visible, &pos, tszCustomName);
+ if (tszCustomName[0])
+ replaceStrT(pmi->CustomName, tszCustomName);
+ }
+ }
+ else if (pmi->submenu.first != NULL)
+ visible = 1;
}
- else mi->position = pos;
+ if (!visible)
+ continue;
}
int i = WhereToPlace(hMenu, mi);
@@ -967,6 +1003,14 @@ static HMENU BuildRecursiveMenu(HMENU hMenu, TMO_IntMenuItem *pRootMenu, WPARAM
}
}
+ if (bOldMenuFormat && pRootMenu->mi.root == NULL && pmo->m_bUseUserDefinedItems) {
+ // wipe out old trash, write new data & compatibility flag
+ CallService(MS_DB_MODULE_DELETE, 0, (LPARAM)szModule);
+ db_set_b(NULL, szModule, "MenuFormat", true);
+
+ MO_RecursiveWalkMenu(pmo->m_items.first, sttDumpItem, szModule);
+ }
+
return hMenu;
}