From 9f27827e9b6cb1462ec4c5e306ae7eec79ba6473 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 16 Apr 2025 18:12:45 +0300 Subject: rollback to the old groups management code --- src/mir_app/src/clc.h | 2 +- src/mir_app/src/clistgroups.cpp | 28 ++++++++++++++++++---------- 2 files changed, 19 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/mir_app/src/clc.h b/src/mir_app/src/clc.h index 935baed370..1639d14692 100644 --- a/src/mir_app/src/clc.h +++ b/src/mir_app/src/clc.h @@ -177,7 +177,7 @@ struct CGroupInternal CGroupInternal(int _id, const wchar_t *_name, int _flags); ~CGroupInternal(); - int groupId, flags; + int groupId, flags, oldId; bool bSaveExpanded; wchar_t *groupName; diff --git a/src/mir_app/src/clistgroups.cpp b/src/mir_app/src/clistgroups.cpp index b8b660feed..41778fda45 100644 --- a/src/mir_app/src/clistgroups.cpp +++ b/src/mir_app/src/clistgroups.cpp @@ -152,7 +152,7 @@ static INT_PTR CreateGroupInternal(MGROUP hParent, const wchar_t *ptszName) mir_snwprintf(newName, L"%s (%d)", newBaseName, idCopy); } - int newId = arByIds.getCount() ? arByIds[arByIds.getCount() - 1]->groupId + 1 : 0; + int newId = arByIds.getCount(); CGroupInternal *pNew = new CGroupInternal(newId, newName, GROUPF_EXPANDED); arByIds.insert(pNew); arByName.insert(pNew); @@ -253,15 +253,23 @@ MIR_APP_DLL(int) Clist_GroupDelete(MGROUP hGroup, bool bSilent) NotifyEventHooks(hGroupChangeEvent, hContact, (LPARAM)&grpChg); } - // remove all child groups - for (auto &it : arByIds.rev_iter()) - if (isParentOf(wszOldName, it->groupName)) { - auto *p = it; - arByName.remove(it); - arByIds.removeItem(&it); - p->remove(); - delete p; - } + // shuffle list of groups up to fill gap + for (auto &it : arByIds) + it->oldId = it->groupId; + + for (auto &it : arByIds.rev_iter()) { + if (!isParentOf(wszOldName, it->groupName)) + continue; + + arByName.remove(it); + arByIds.removeItem(&it); + } + + for (auto &it : arByIds) { + it->groupId = arByIds.indexOf(&it); + if (it->groupId != it->oldId) + it->save(); + } SetCursor(LoadCursor(nullptr, IDC_ARROW)); Clist_LoadContactTree(); -- cgit v1.2.3