containers: Fix creating new iconboxes

When creating a new iconbox without giving a name (eesh ibox new) as
done by the desktop menu this would not work if an iconbox named _IB_<N>
(<N> being the number of containers) already existed.
This commit is contained in:
Kim Woelders 2022-05-24 07:19:52 +02:00
parent 556fadb3c1
commit c35690b4a4
1 changed files with 15 additions and 5 deletions

View File

@ -1920,6 +1920,19 @@ ContainersGetList(int *pnum)
return LIST_GET_ITEMS(Container, &container_list, pnum);
}
static void
_ContainersNewName(char *nbuf, unsigned int nlen, const char *pfx)
{
int i;
for (i = 1;; i++)
{
Esnprintf(nbuf, nlen, "%s%i", pfx, i);
if (!_ContainerFind(nbuf))
break;
}
}
/*
* IPC functions
*/
@ -1928,7 +1941,7 @@ _ContainerIpc(const char *params)
{
const char *p;
char cmd[128], prm[128];
int len, num;
int len;
cmd[0] = prm[0] = '\0';
p = params;
@ -1954,10 +1967,7 @@ _ContainerIpc(const char *params)
Container *ct;
if (!prm[0])
{
num = LIST_GET_COUNT(&container_list);
Esnprintf(prm, sizeof(prm), "_IB_%i", num);
}
_ContainersNewName(prm, sizeof(prm), "_IB_");
ct = _ContainerCreate(prm);
_ContainerShow(ct);
_ContainersConfigSave();