[Bf-blender-cvs] [4669c3692cc] blender2.8: Add library-hint to datablock search menus.

Bastien Montagne noreply at git.blender.org
Tue Oct 30 11:00:35 CET 2018


Commit: 4669c3692cc4f69660c673ceccce2245d5b9fed8
Author: Bastien Montagne
Date:   Tue Oct 30 10:54:02 2018 +0100
Branches: blender2.8
https://developer.blender.org/rB4669c3692cc4f69660c673ceccce2245d5b9fed8

Add library-hint to datablock search menus.

We had those for ID templates, but it's also tremendously useful for
regular ID pointers UI, since often you can get local and linked
data-block with same exact name...

Fetaure request from Spring team (and long due TODO...).

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

M	source/blender/editors/interface/interface_templates.c
M	source/blender/editors/interface/interface_utils.c

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

diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index 8a1ebbb205c..32b942283c7 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -297,8 +297,8 @@ static bool id_search_add(
 		}
 
 		if (*str == '\0' || BLI_strcasestr(id->name + 2, str)) {
-			/* +1 is needed because BKE_id_ui_prefix used 3 letter prefix
-			 * followed by ID_NAME-2 characters from id->name
+			/* +1 is needed because BKE_id_ui_prefix uses 3 letter prefix
+			 * followed by ID_NAME-2 characters from id->name.
 			 */
 			char name_ui[MAX_ID_NAME + 1];
 			BKE_id_ui_prefix(name_ui, id);
diff --git a/source/blender/editors/interface/interface_utils.c b/source/blender/editors/interface/interface_utils.c
index 507f89f01cd..4a051b9a4e8 100644
--- a/source/blender/editors/interface/interface_utils.c
+++ b/source/blender/editors/interface/interface_utils.c
@@ -43,6 +43,7 @@
 
 #include "BLT_translation.h"
 
+#include "BKE_library.h"
 #include "BKE_report.h"
 
 #include "MEM_guardedalloc.h"
@@ -270,22 +271,28 @@ void ui_rna_collection_search_cb(const struct bContext *C, void *arg, const char
 				continue;
 		}
 
-		name = RNA_struct_name_get_alloc(&itemptr, NULL, 0, NULL); /* could use the string length here */
 		iconid = 0;
 		if (itemptr.type && RNA_struct_is_ID(itemptr.type)) {
+			name = MEM_malloc_arrayN(MAX_ID_NAME + 1, sizeof(*name), __func__);
+			BKE_id_ui_prefix(name, itemptr.data);
 			iconid = ui_id_icon_get(C, itemptr.data, false);
 		}
+		else {
+			name = RNA_struct_name_get_alloc(&itemptr, NULL, 0, NULL); /* could use the string length here */
+		}
 
 		if (name) {
 			if (skip_filter || BLI_strcasestr(name, str)) {
 				cis = MEM_callocN(sizeof(CollItemSearch), "CollectionItemSearch");
 				cis->data = itemptr.data;
-				cis->name = MEM_dupallocN(name);
+				cis->name = name;  /* Still ownership of that memory. */
 				cis->index = i;
 				cis->iconid = iconid;
 				BLI_addtail(items_list, cis);
 			}
-			MEM_freeN(name);
+			else {
+				MEM_freeN(name);
+			}
 		}
 
 		i++;



More information about the Bf-blender-cvs mailing list