UI: Add template_search (version of template_ID for non-IDs)
Adds a version of template_ID that can be used for non-ID properties. The property to search for and the collection to search in has to be passed to it. Like template_ID it also takes arguments to define a 'new' and 'unlink' operator. They will be displayed as icon-only buttons then. Also added a version that can display preview thumbnails. Had to do some additional changes to make text-buttons support displaying/modifying empty RNA properties. This will be needed for workspaces, see D2451. Reviewed By: campbellbarton Differential Revision: https://developer.blender.org/D2666
This commit is contained in:
@@ -2373,7 +2373,7 @@ static void ui_but_string_free_internal(uiBut *but)
|
||||
|
||||
bool ui_but_string_set(bContext *C, uiBut *but, const char *str)
|
||||
{
|
||||
if (but->rnaprop && ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_SEARCH_MENU)) {
|
||||
if (but->rnaprop && but->rnapoin.data && ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_SEARCH_MENU)) {
|
||||
if (RNA_property_editable(&but->rnapoin, but->rnaprop)) {
|
||||
PropertyType type;
|
||||
|
||||
@@ -2420,8 +2420,15 @@ bool ui_but_string_set(bContext *C, uiBut *but, const char *str)
|
||||
}
|
||||
else if (but->type == UI_BTYPE_TEXT) {
|
||||
/* string */
|
||||
if (ui_but_is_utf8(but)) BLI_strncpy_utf8(but->poin, str, but->hardmax);
|
||||
else BLI_strncpy(but->poin, str, but->hardmax);
|
||||
if (!but->poin || (str[0] == '\0')) {
|
||||
str = "";
|
||||
}
|
||||
else if (ui_but_is_utf8(but)) {
|
||||
BLI_strncpy_utf8(but->poin, str, but->hardmax);
|
||||
}
|
||||
else {
|
||||
BLI_strncpy(but->poin, str, but->hardmax);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -2627,6 +2634,10 @@ static void ui_but_free(const bContext *C, uiBut *but)
|
||||
MEM_freeN(but->tip_argN);
|
||||
}
|
||||
|
||||
if (!but->editstr && but->free_search_arg) {
|
||||
MEM_SAFE_FREE(but->search_arg);
|
||||
}
|
||||
|
||||
if (but->active) {
|
||||
/* XXX solve later, buttons should be free-able without context ideally,
|
||||
* however they may have open tooltips or popup windows, which need to
|
||||
@@ -3499,7 +3510,7 @@ static uiBut *ui_def_but_rna(
|
||||
}
|
||||
|
||||
const char *info;
|
||||
if (!RNA_property_editable_info(&but->rnapoin, prop, &info)) {
|
||||
if (but->rnapoin.data && !RNA_property_editable_info(&but->rnapoin, prop, &info)) {
|
||||
ui_def_but_rna__disable(but, info);
|
||||
}
|
||||
|
||||
@@ -4522,7 +4533,7 @@ void UI_but_string_info_get(bContext *C, uiBut *but, ...)
|
||||
tmp = BLI_strdup(RNA_property_identifier(but->rnaprop));
|
||||
}
|
||||
else if (type == BUT_GET_RNASTRUCT_IDENTIFIER) {
|
||||
if (but->rnaprop)
|
||||
if (but->rnaprop && but->rnapoin.data)
|
||||
tmp = BLI_strdup(RNA_struct_identifier(but->rnapoin.type));
|
||||
else if (but->optype)
|
||||
tmp = BLI_strdup(but->optype->idname);
|
||||
|
||||
Reference in New Issue
Block a user