summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mir_app/src/clc.h2
-rw-r--r--src/mir_app/src/clistgroups.cpp28
2 files changed, 19 insertions, 11 deletions
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();