diff options
author | Matt Ebb <matt@mke3.net> | 2009-12-10 04:29:43 +0300 |
---|---|---|
committer | Matt Ebb <matt@mke3.net> | 2009-12-10 04:29:43 +0300 |
commit | 653593b5748eb7ca78c74336bca1166ade0bbc75 (patch) | |
tree | 272e9a6b1cc7d3f65a8eb37006c24401529d9d6a /source/blender/editors/interface/interface_layout.c | |
parent | ef8706c4ea6eff84ddf5ddaad27c0d036d789821 (diff) |
Fix for [#20216] Search List is unordered
This sorts RNA collection (bones, vgroups, etc) search lists alphabetically like ID data search lists are already.
Diffstat (limited to 'source/blender/editors/interface/interface_layout.c')
-rw-r--r-- | source/blender/editors/interface/interface_layout.c | 60 |
1 files changed, 47 insertions, 13 deletions
diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index ceb5ac10486..168b1532db8 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -1057,38 +1057,72 @@ void uiItemsEnumR(uiLayout *layout, struct PointerRNA *ptr, char *propname) /* Pointer RNA button with search */ +typedef struct CollItemSearch { + struct CollItemSearch *next, *prev; + char *name; + int index; + int iconid; +} CollItemSearch; + +int sort_search_items_list(void *a, void *b) +{ + CollItemSearch *cis1 = (CollItemSearch *)a; + CollItemSearch *cis2 = (CollItemSearch *)b; + + if (BLI_strcasecmp(cis1->name, cis2->name)>0) + return 1; + else + return 0; +} + static void rna_search_cb(const struct bContext *C, void *arg_but, char *str, uiSearchItems *items) { uiBut *but= arg_but; char *name; - int i, iconid, flag= RNA_property_flag(but->rnaprop); + int i=0, iconid=0, flag= RNA_property_flag(but->rnaprop); + ListBase *items_list= MEM_callocN(sizeof(ListBase), "items_list"); + CollItemSearch *cis; - i = 0; + /* build a temporary list of relevant items first */ RNA_PROP_BEGIN(&but->rnasearchpoin, itemptr, but->rnasearchprop) { if(flag & PROP_ID_SELF_CHECK) if(itemptr.data == but->rnapoin.id.data) continue; - - iconid= 0; + if(RNA_struct_is_ID(itemptr.type)) iconid= ui_id_icon_get((bContext*)C, itemptr.data); - + name= RNA_struct_name_get_alloc(&itemptr, NULL, 0); - + if(name) { if(BLI_strcasestr(name, str)) { - if(!uiSearchItemAdd(items, name, SET_INT_IN_POINTER(i), iconid)) { - MEM_freeN(name); - break; - } + cis = MEM_callocN(sizeof(CollItemSearch), "CollectionItemSearch"); + cis->name = MEM_dupallocN(name); + cis->index = i; + cis->iconid = iconid; + BLI_addtail(items_list, cis); } - - MEM_freeN(name); } - + MEM_freeN(name); + i++; } RNA_PROP_END; + + BLI_sortlist(items_list, sort_search_items_list); + + /* add search items from temporary list */ + for (cis=items_list->first; cis; cis=cis->next) { + if (!uiSearchItemAdd(items, cis->name, SET_INT_IN_POINTER(cis->index), cis->iconid)) { + break; + } + } + + for (cis=items_list->first; cis; cis=cis->next) { + MEM_freeN(cis->name); + } + BLI_freelistN(items_list); + MEM_freeN(items_list); } static void search_id_collection(StructRNA *ptype, PointerRNA *ptr, PropertyRNA **prop) |