summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-07-25 21:10:51 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-07-25 21:10:51 +0300
commit942c498d6e8901f751b088c0adfcb8f3fc67576c (patch)
tree062f0f97d19653d2f31bd9f9047529d4346b78cb
parent51209173e695d6e866018df19588c5474c9a6848 (diff)
fixes #1524 (Options module in DB)
-rw-r--r--src/mir_app/src/options.cpp60
1 files changed, 24 insertions, 36 deletions
diff --git a/src/mir_app/src/options.cpp b/src/mir_app/src/options.cpp
index f6238af1f3..4fe2e783f2 100644
--- a/src/mir_app/src/options.cpp
+++ b/src/mir_app/src/options.cpp
@@ -408,21 +408,22 @@ class COptionsDlg : public CDlgBase
return nullptr;
}
+ void GetTreeSettingName(int idx, char *buf, size_t bufSize)
+ {
+ mir_snprintf(buf, bufSize, "%s%S", OPTSTATE_PREFIX, (idx < 0) ? m_arOpd[-idx]->ptszGroup : m_arOpd[idx]->ptszTitle);
+ }
+
void SaveOptionsTreeState()
{
- wchar_t str[128];
TVITEMEX tvi;
- tvi.mask = TVIF_TEXT | TVIF_STATE;
- tvi.pszText = str;
- tvi.cchTextMax = _countof(str);
- tvi.hItem = m_pageTree.GetRoot();
- while (tvi.hItem != nullptr) {
- if (m_pageTree.GetItem(&tvi)) {
- char buf[130];
- mir_snprintf(buf, "%s%S", OPTSTATE_PREFIX, str);
- db_set_b(0, "Options", buf, (BYTE)((tvi.state & TVIS_EXPANDED) ? 1 : 0));
- }
- tvi.hItem = m_pageTree.GetNextSibling(tvi.hItem);
+ tvi.mask = TVIF_STATE | TVIF_PARAM;
+ for (tvi.hItem = m_pageTree.GetRoot(); tvi.hItem != nullptr; tvi.hItem = m_pageTree.GetNextSibling(tvi.hItem)) {
+ if (m_pageTree.GetChild(tvi.hItem) == nullptr) continue;
+ if (!m_pageTree.GetItem(&tvi)) continue;
+
+ char buf[130];
+ GetTreeSettingName(tvi.lParam, buf, _countof(buf));
+ db_set_b(0, "Options", buf, (BYTE)((tvi.state & TVIS_EXPANDED) ? 1 : 0));
}
}
@@ -577,7 +578,7 @@ class COptionsDlg : public CDlgBase
if (ptszGroup != nullptr) {
tvis.hParent = FindNamedTreeItem(nullptr, ptszGroup);
if (tvis.hParent == nullptr) {
- tvis.item.lParam = -1;
+ tvis.item.lParam = -i;
tvis.item.pszText = ptszGroup;
tvis.hParent = m_pageTree.InsertItem(&tvis);
}
@@ -590,11 +591,8 @@ class COptionsDlg : public CDlgBase
tvi.mask = TVIF_PARAM;
m_pageTree.GetItem(&tvi);
- if (tvi.lParam == -1) {
- tvi.lParam = i;
- m_pageTree.SetItem(&tvi);
+ if (tvi.lParam < 0)
continue;
- }
}
}
@@ -605,13 +603,8 @@ class COptionsDlg : public CDlgBase
else
hItem = FindNamedTreeItem(tvis.hParent, useTitle);
if (hItem != nullptr) {
- if (i == m_currentPage) {
- tvi.hItem = hItem;
- tvi.mask = TVIF_PARAM;
- tvi.lParam = m_currentPage;
- m_pageTree.SetItem(&tvi);
+ if (i == m_currentPage)
m_hCurrentPage = hItem;
- }
continue;
}
}
@@ -623,19 +616,14 @@ class COptionsDlg : public CDlgBase
m_hCurrentPage = opd->hTreeItem;
}
- wchar_t str[128];
- tvi.mask = TVIF_TEXT | TVIF_STATE;
- tvi.pszText = str;
- tvi.cchTextMax = _countof(str);
- tvi.hItem = m_pageTree.GetRoot();
- while (tvi.hItem != nullptr) {
- if (m_pageTree.GetItem(&tvi)) {
- char buf[130];
- mir_snprintf(buf, "%s%S", OPTSTATE_PREFIX, str);
- if (!db_get_b(0, "Options", buf, 1))
- m_pageTree.Expand(tvi.hItem, TVE_COLLAPSE);
- }
- tvi.hItem = m_pageTree.GetNextSibling(tvi.hItem);
+ tvi.mask = TVIF_STATE | TVIF_PARAM;
+ for (tvi.hItem = m_pageTree.GetRoot(); tvi.hItem != nullptr; tvi.hItem = m_pageTree.GetNextSibling(tvi.hItem)) {
+ if (!m_pageTree.GetItem(&tvi)) continue;
+
+ char buf[130];
+ GetTreeSettingName(tvi.lParam, buf, _countof(buf));
+ if (!db_get_b(0, "Options", buf, 1))
+ m_pageTree.Expand(tvi.hItem, TVE_COLLAPSE);
}
if (m_hCurrentPage == nullptr) {