Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/interface/interface_layout.c
| Show First 20 Lines • Show All 1,568 Lines • ▼ Show 20 Lines | void uiItemsEnumR(uiLayout *layout, struct PointerRNA *ptr, const char *propname) | ||||
| } | } | ||||
| /* intentionally don't touch UI_BLOCK_IS_FLIP here, | /* intentionally don't touch UI_BLOCK_IS_FLIP here, | ||||
| * we don't know the context this is called in */ | * we don't know the context this is called in */ | ||||
| } | } | ||||
| /* Pointer RNA button with search */ | /* Pointer RNA button with search */ | ||||
| typedef struct CollItemSearch { | |||||
| struct CollItemSearch *next, *prev; | |||||
| char *name; | |||||
| int index; | |||||
| int iconid; | |||||
| } CollItemSearch; | |||||
| static int sort_search_items_list(const void *a, const void *b) | |||||
| { | |||||
| const CollItemSearch *cis1 = a; | |||||
| const CollItemSearch *cis2 = 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, const char *str, uiSearchItems *items) | |||||
| { | |||||
| uiBut *but = arg_but; | |||||
| char *name; | |||||
| int i = 0, iconid = 0, flag = RNA_property_flag(but->rnaprop); | |||||
| ListBase *items_list = MEM_callocN(sizeof(ListBase), "items_list"); | |||||
| CollItemSearch *cis; | |||||
| const bool skip_filter = !but->changed; | |||||
| /* 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; | |||||
| /* use filter */ | |||||
| if (RNA_property_type(but->rnaprop) == PROP_POINTER) { | |||||
| if (RNA_property_pointer_poll(&but->rnapoin, but->rnaprop, &itemptr) == 0) | |||||
| continue; | |||||
| } | |||||
| if (itemptr.type && RNA_struct_is_ID(itemptr.type)) { | |||||
| ID *id = itemptr.data; | |||||
| char name_ui[MAX_ID_NAME]; | |||||
| #if 0 /* this name is used for a string comparison and can't be modified, TODO */ | |||||
| /* if ever enabled, make name_ui be MAX_ID_NAME+1 */ | |||||
| BKE_id_ui_prefix(name_ui, id); | |||||
| #else | |||||
| BLI_strncpy(name_ui, id->name + 2, sizeof(name_ui)); | |||||
| #endif | |||||
| name = BLI_strdup(name_ui); | |||||
| iconid = ui_id_icon_get(C, id, false); | |||||
| } | |||||
| else { | |||||
| name = RNA_struct_name_get_alloc(&itemptr, NULL, 0, NULL); /* could use the string length here */ | |||||
| iconid = 0; | |||||
| } | |||||
| if (name) { | |||||
| if (skip_filter || BLI_strcasestr(name, str)) { | |||||
| 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); | |||||
| } | |||||
| i++; | |||||
| } | |||||
| RNA_PROP_END; | |||||
| BLI_listbase_sort(items_list, sort_search_items_list); | |||||
| /* add search items from temporary list */ | |||||
| for (cis = items_list->first; cis; cis = cis->next) { | |||||
| if (false == UI_search_item_add(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) | static void search_id_collection(StructRNA *ptype, PointerRNA *ptr, PropertyRNA **prop) | ||||
| { | { | ||||
| StructRNA *srna; | StructRNA *srna; | ||||
| /* look for collection property in Main */ | /* look for collection property in Main */ | ||||
| RNA_main_pointer_create(G.main, ptr); | RNA_main_pointer_create(G.main, ptr); | ||||
| *prop = NULL; | *prop = NULL; | ||||
| Show All 24 Lines | if (RNA_property_type(prop) == PROP_POINTER) { | ||||
| ptype = RNA_property_pointer_type(ptr, prop); | ptype = RNA_property_pointer_type(ptr, prop); | ||||
| search_id_collection(ptype, &sptr, &searchprop); | search_id_collection(ptype, &sptr, &searchprop); | ||||
| searchptr = &sptr; | searchptr = &sptr; | ||||
| } | } | ||||
| } | } | ||||
| /* turn button into search button */ | /* turn button into search button */ | ||||
| if (searchprop) { | if (searchprop) { | ||||
| uiRNACollectionSearch *coll_search = MEM_mallocN(sizeof(*coll_search), __func__); | |||||
| but->type = UI_BTYPE_SEARCH_MENU; | but->type = UI_BTYPE_SEARCH_MENU; | ||||
| but->hardmax = MAX2(but->hardmax, 256.0f); | but->hardmax = MAX2(but->hardmax, 256.0f); | ||||
| but->rnasearchpoin = *searchptr; | but->rnasearchpoin = *searchptr; | ||||
| but->rnasearchprop = searchprop; | but->rnasearchprop = searchprop; | ||||
| but->drawflag |= UI_BUT_ICON_LEFT | UI_BUT_TEXT_LEFT; | but->drawflag |= UI_BUT_ICON_LEFT | UI_BUT_TEXT_LEFT; | ||||
| if (RNA_property_is_unlink(prop)) { | if (RNA_property_is_unlink(prop)) { | ||||
| but->flag |= UI_BUT_VALUE_CLEAR; | but->flag |= UI_BUT_VALUE_CLEAR; | ||||
| } | } | ||||
| coll_search->target_ptr = *ptr; | |||||
| coll_search->target_prop = prop; | |||||
| coll_search->search_ptr = *searchptr; | |||||
| coll_search->search_prop = searchprop; | |||||
| coll_search->but_changed = SET_INT_IN_POINTER(but->changed); | |||||
| if (RNA_property_type(prop) == PROP_ENUM) { | if (RNA_property_type(prop) == PROP_ENUM) { | ||||
| /* XXX, this will have a menu string, | /* XXX, this will have a menu string, | ||||
| * but in this case we just want the text */ | * but in this case we just want the text */ | ||||
| but->str[0] = 0; | but->str[0] = 0; | ||||
| } | } | ||||
| UI_but_func_search_set(but, ui_searchbox_create_generic, rna_search_cb, but, NULL, NULL); | UI_but_func_search_set( | ||||
| but, ui_searchbox_create_generic, ui_rna_collection_search_cb, | |||||
| coll_search, NULL, NULL); | |||||
| but->free_search_arg = true; | |||||
| } | } | ||||
| } | } | ||||
| void uiItemPointerR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, struct PointerRNA *searchptr, const char *searchpropname, const char *name, int icon) | void uiItemPointerR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, struct PointerRNA *searchptr, const char *searchpropname, const char *name, int icon) | ||||
| { | { | ||||
| PropertyRNA *prop, *searchprop; | PropertyRNA *prop, *searchprop; | ||||
| PropertyType type; | PropertyType type; | ||||
| uiBut *but; | uiBut *but; | ||||
| ▲ Show 20 Lines • Show All 1,934 Lines • Show Last 20 Lines | |||||