diff options
author | Julian Eisel <eiseljulian@gmail.com> | 2017-03-01 21:56:37 +0300 |
---|---|---|
committer | Julian Eisel <eiseljulian@gmail.com> | 2017-03-01 22:13:40 +0300 |
commit | 0f7a664731eb6e22d9c838f33fb62b2a16182538 (patch) | |
tree | decefc848233fecb4c2d0050f0a9e60ad9891a4e /source/blender/blenkernel/intern/collection.c | |
parent | 18684e546f25feefa5a696b786e74fd63b590d10 (diff) |
Fix collection renaming not checking for unique name in entire hierarchy
Only checked for unique name in direct children of the master
collection.
Also added missing listener for outliner.
Diffstat (limited to 'source/blender/blenkernel/intern/collection.c')
-rw-r--r-- | source/blender/blenkernel/intern/collection.c | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c index b9a554f181f..370a5953964 100644 --- a/source/blender/blenkernel/intern/collection.c +++ b/source/blender/blenkernel/intern/collection.c @@ -24,6 +24,8 @@ * \ingroup bke */ +#include <string.h> + #include "BLI_blenlib.h" #include "BLI_ghash.h" #include "BLI_iterator.h" @@ -179,13 +181,38 @@ SceneCollection *BKE_collection_master(const Scene *scene) return scene->collection; } +struct UniqueNameCheckData { + ListBase *lb; + SceneCollection *lookup_sc; +}; + +static bool collection_unique_name_check(void *arg, const char *name) +{ + struct UniqueNameCheckData *data = arg; + + for (SceneCollection *sc = data->lb->first; sc; sc = sc->next) { + struct UniqueNameCheckData child_data = {.lb = &sc->scene_collections, .lookup_sc = data->lookup_sc}; + + if (sc != data->lookup_sc) { + if (STREQ(sc->name, name)) { + return true; + } + } + if (collection_unique_name_check(&child_data, name)) { + return true; + } + } + + return false; +} + void BKE_collection_rename(const Scene *scene, SceneCollection *sc, const char *name) { SceneCollection *sc_master = BKE_collection_master(scene); + struct UniqueNameCheckData data = {.lb = &sc_master->scene_collections, .lookup_sc = sc}; BLI_strncpy(sc->name, name, sizeof(sc->name)); - BLI_uniquename(&sc_master->scene_collections, sc, DATA_("Collection"), '.', offsetof(SceneCollection, name), - sizeof(sc->name)); + BLI_uniquename_cb(collection_unique_name_check, &data, DATA_("Collection"), '.', sc->name, sizeof(sc->name)); } /** |