Commit: b9c4e5bd23b080fe51785c6090b6153eef153851
Author: Hans Goudey
Date: Thu Aug 13 18:20:03 2020 -0400
Branches: property-search-ui-v2
https://developer.blender.org/rBb9c4e5bd23b080fe51785c6090b6153eef153851
Property Search: Search in pulldown button RNA enums
This introduces a memory leak when accessing the enum items.
I'll solve that later.
===================================================================
M source/blender/editors/interface/interface_layout.c
===================================================================
diff --git a/source/blender/editors/interface/interface_layout.c
b/source/blender/editors/interface/interface_layout.c
index 5164caa1e0b..466c1aca4cf 100644
--- a/source/blender/editors/interface/interface_layout.c
+++ b/source/blender/editors/interface/interface_layout.c
@@ -5175,9 +5175,13 @@ static void layout_free_and_hide_buttons(uiLayout
*layout)
MEM_freeN(layout);
}
-static bool button_matches_search_filter(uiBut *but, char *search_filter)
+/**
+ * Returns true if a button or the data / operator it represents matches the
search filter.
+ *
+ * \note It's important to do the shorter checks first for performance.
+ */
+static bool button_matches_search_filter(uiBut *but, const char *search_filter)
{
- /* Do the shorter checks first, in case the check returns true. */
if (BLI_strcasestr(but->str, search_filter)) {
return true;
}
@@ -5197,6 +5201,28 @@ static bool button_matches_search_filter(uiBut *but,
char *search_filter)
return true;
}
#endif
+
+ /* Search through labels of enum property items if they are in a dropdown
menu. */
+ if (but->type == UI_BTYPE_MENU) {
+ PointerRNA *ptr = &but->rnapoin;
+ PropertyRNA *enum_prop = but->rnaprop;
+
+ int items_len;
+ const EnumPropertyItem *enum_items = NULL;
+ bool free;
+ RNA_property_enum_items(NULL, ptr, enum_prop, &enum_items, &items_len,
&free);
+
+ if (enum_items != NULL) {
+ for (int i = 0; i < items_len; i++) {
+ if (BLI_strcasestr(enum_items[i].name, search_filter)) {
+ return true;
+ }
+ }
+ if (free) {
+ MEM_freeN((void *)enum_items);
+ }
+ }
+ }
}
return false;
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs