[Bf-blender-cvs] [0f7a664731] blender2.8: Fix collection renaming not checking for unique name in entire hierarchy

Julian Eisel noreply at git.blender.org
Wed Mar 1 20:16:25 CET 2017


Commit: 0f7a664731eb6e22d9c838f33fb62b2a16182538
Author: Julian Eisel
Date:   Wed Mar 1 19:56:37 2017 +0100
Branches: blender2.8
https://developer.blender.org/rB0f7a664731eb6e22d9c838f33fb62b2a16182538

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.

===================================================================

M	source/blender/blenkernel/intern/collection.c
M	source/blender/editors/space_outliner/space_outliner.c
M	source/blender/makesrna/intern/rna_scene.c

===================================================================

diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c
index b9a554f181..370a595396 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));
 }
 
 /**
diff --git a/source/blender/editors/space_outliner/space_outliner.c b/source/blender/editors/space_outliner/space_outliner.c
index 348a4488f5..0014b1f048 100644
--- a/source/blender/editors/space_outliner/space_outliner.c
+++ b/source/blender/editors/space_outliner/space_outliner.c
@@ -316,6 +316,7 @@ static void outliner_main_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(s
 				case ND_RENDER_OPTIONS:
 				case ND_SEQUENCER:
 				case ND_LAYER:
+				case ND_LAYER_CONTENT:
 				case ND_WORLD:
 					ED_region_tag_redraw(ar);
 					break;
diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c
index 86140eaaa0..cefc4a59da 100644
--- a/source/blender/makesrna/intern/rna_scene.c
+++ b/source/blender/makesrna/intern/rna_scene.c
@@ -2262,10 +2262,7 @@ static void rna_SceneCollection_name_set(PointerRNA *ptr, const char *value)
 {
 	Scene *scene = (Scene *)ptr->id.data;
 	SceneCollection *sc = (SceneCollection *)ptr->data;
-	SceneCollection *sc_master = BKE_collection_master(scene);
-
-	BLI_strncpy_utf8(sc->name, value, sizeof(sc->name));
-	BLI_uniquename(&sc_master->scene_collections, sc, DATA_("SceneCollection"), '.', offsetof(SceneCollection, name), sizeof(sc->name));
+	BKE_collection_rename(scene, sc, value);
 }
 
 static void rna_SceneCollection_filter_set(PointerRNA *ptr, const char *value)
@@ -2517,10 +2514,7 @@ static void rna_LayerCollection_name_set(PointerRNA *ptr, const char *value)
 {
 	Scene *scene = (Scene *)ptr->id.data;
 	SceneCollection *sc = ((LayerCollection *)ptr->data)->scene_collection;
-	SceneCollection *sc_master = BKE_collection_master(scene);
-
-	BLI_strncpy_utf8(sc->name, value, sizeof(sc->name));
-	BLI_uniquename(&sc_master->scene_collections, sc, DATA_("SceneCollection"), '.', offsetof(SceneCollection, name), sizeof(sc->name));
+	BKE_collection_rename(scene, sc, value);
 }
 
 static PointerRNA rna_LayerCollection_objects_get(CollectionPropertyIterator *iter)




More information about the Bf-blender-cvs mailing list