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...).
This commit is contained in:
Bastien Montagne 2018-10-30 10:54:02 +01:00
parent 76a047893c
commit 4669c3692c
Notes: blender-bot 2023-02-14 09:33:11 +01:00
Referenced by commit f57fce3534, Revert "Add library-hint to datablock search menus."
Referenced by commit 456e3f00e0, Fix broken 'search pointer' UI since this morning.
Referenced by issue #73156, ID search menu issue with linked data-blocks
Referenced by issue #62033, Can't access bpy.data.screens by name.
Referenced by issue #61998, bpy.data.* name lookups are no longer reliable
2 changed files with 12 additions and 5 deletions

View File

@ -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);

View File

@ -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++;