[Bf-blender-cvs] [249ccab111a] blender-v2.83-release: Fix T76621: UILayout.prop_search() broken for data-block names

Julian Eisel noreply at git.blender.org
Mon May 11 17:13:23 CEST 2020


Commit: 249ccab111ac05158064d20ba0fbd1f618f9aa92
Author: Julian Eisel
Date:   Mon May 11 16:55:33 2020 +0200
Branches: blender-v2.83-release
https://developer.blender.org/rB249ccab111ac05158064d20ba0fbd1f618f9aa92

Fix T76621: UILayout.prop_search() broken for data-block names

If the search menu was used for a string property, and a data-block was
selected from the search, the value set would be an invalid name. The property
would get the modified UI string, not the proper data name set.

Mistake in rBd6cefef98f87.

This is more of a temporary fix to make the menu behave like before above's
commit. So the library hints this added will not be shown for string properties
anymore. This would need further changes in the UI code (see
https://developer.blender.org/P1380) but is too unsafe for 2.83 at this point.
Even if this is done, the note below still applies.

NOTE: Data-blocks should not be referenced by name only, as it's possible to
have duplicate data-block names with linking and especially with library
overriding.
Instead, pointer properties should be used, `UILayout.prop_search()` can then
properly deal with linked and overridden data-blocks.

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

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

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

diff --git a/source/blender/editors/interface/interface_utils.c b/source/blender/editors/interface/interface_utils.c
index 79a90d27373..781c8f73b0a 100644
--- a/source/blender/editors/interface/interface_utils.c
+++ b/source/blender/editors/interface/interface_utils.c
@@ -399,6 +399,11 @@ void ui_rna_collection_search_cb(const struct bContext *C,
   int i = 0, iconid = 0, flag = RNA_property_flag(data->target_prop);
   ListBase *items_list = MEM_callocN(sizeof(ListBase), "items_list");
   CollItemSearch *cis;
+  const bool is_ptr_target = (RNA_property_type(data->target_prop) == PROP_POINTER);
+  /* For non-pointer properties, UI code acts entirely based on the item's name. So the name has to
+   * match the RNA name exactly. So only for pointer properties, the name can be modified to add
+   * further UI hints. */
+  const bool requires_exact_data_name = !is_ptr_target;
   const bool skip_filter = data->search_but && !data->search_but->changed;
   char name_buf[UI_MAX_DRAW_STR];
   char *name;
@@ -413,7 +418,7 @@ void ui_rna_collection_search_cb(const struct bContext *C,
     }
 
     /* use filter */
-    if (RNA_property_type(data->target_prop) == PROP_POINTER) {
+    if (is_ptr_target) {
       if (RNA_property_pointer_poll(&data->target_ptr, data->target_prop, &itemptr) == 0) {
         continue;
       }
@@ -423,10 +428,15 @@ void ui_rna_collection_search_cb(const struct bContext *C,
     if (itemptr.type && RNA_struct_is_ID(itemptr.type)) {
       iconid = ui_id_icon_get(C, itemptr.data, false);
 
-      BKE_id_full_name_ui_prefix_get(name_buf, itemptr.data);
-      BLI_STATIC_ASSERT(sizeof(name_buf) >= MAX_ID_FULL_NAME_UI,
-                        "Name string buffer should be big enough to hold full UI ID name");
-      name = name_buf;
+      if (requires_exact_data_name) {
+        name = RNA_struct_name_get_alloc(&itemptr, name_buf, sizeof(name_buf), NULL);
+      }
+      else {
+        BKE_id_full_name_ui_prefix_get(name_buf, itemptr.data);
+        BLI_STATIC_ASSERT(sizeof(name_buf) >= MAX_ID_FULL_NAME_UI,
+                          "Name string buffer should be big enough to hold full UI ID name");
+        name = name_buf;
+      }
     }
     else {
       name = RNA_struct_name_get_alloc(&itemptr, name_buf, sizeof(name_buf), NULL);



More information about the Bf-blender-cvs mailing list