Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/interface/interface_utils.c')
-rw-r--r--source/blender/editors/interface/interface_utils.c74
1 files changed, 50 insertions, 24 deletions
diff --git a/source/blender/editors/interface/interface_utils.c b/source/blender/editors/interface/interface_utils.c
index 15db947bff6..208fd7136da 100644
--- a/source/blender/editors/interface/interface_utils.c
+++ b/source/blender/editors/interface/interface_utils.c
@@ -45,6 +45,7 @@
#include "RNA_access.h"
#include "UI_interface.h"
+#include "UI_interface_icons.h"
#include "UI_resources.h"
#include "WM_api.h"
@@ -59,13 +60,9 @@ bool ui_str_has_word_prefix(const char *haystack, const char *needle, size_t nee
if ((match == haystack) || (*(match - 1) == ' ') || ispunct(*(match - 1))) {
return true;
}
- else {
- return ui_str_has_word_prefix(match + 1, needle, needle_len);
- }
- }
- else {
- return false;
+ return ui_str_has_word_prefix(match + 1, needle, needle_len);
}
+ return false;
}
/*************************** RNA Utilities ******************************/
@@ -384,6 +381,9 @@ typedef struct CollItemSearch {
char *name;
int index;
int iconid;
+ bool is_id;
+ int name_prefix_offset;
+ uint has_sep_char : 1;
} CollItemSearch;
static int sort_search_items_list(const void *a, const void *b)
@@ -394,9 +394,7 @@ static int sort_search_items_list(const void *a, const void *b)
if (BLI_strcasecmp(cis1->name, cis2->name) > 0) {
return 1;
}
- else {
- return 0;
- }
+ return 0;
}
void ui_rna_collection_search_update_fn(const struct bContext *C,
@@ -405,7 +403,8 @@ void ui_rna_collection_search_update_fn(const struct bContext *C,
uiSearchItems *items)
{
uiRNACollectionSearch *data = arg;
- int i = 0, iconid = 0, flag = RNA_property_flag(data->target_prop);
+ const int flag = RNA_property_flag(data->target_prop);
+ int i = 0;
ListBase *items_list = MEM_callocN(sizeof(ListBase), "items_list");
CollItemSearch *cis;
const bool is_ptr_target = (RNA_property_type(data->target_prop) == PROP_POINTER);
@@ -416,6 +415,7 @@ void ui_rna_collection_search_update_fn(const struct bContext *C,
const bool skip_filter = data->search_but && !data->search_but->changed;
char name_buf[UI_MAX_DRAW_STR];
char *name;
+ bool has_id_icon = false;
/* build a temporary list of relevant items first */
RNA_PROP_BEGIN (&data->search_ptr, itemptr, data->search_prop) {
@@ -433,18 +433,28 @@ void ui_rna_collection_search_update_fn(const struct bContext *C,
}
}
- iconid = 0;
- if (itemptr.type && RNA_struct_is_ID(itemptr.type)) {
+ int name_prefix_offset = 0;
+ int iconid = ICON_NONE;
+ bool has_sep_char = false;
+ bool is_id = itemptr.type && RNA_struct_is_ID(itemptr.type);
+
+ if (is_id) {
iconid = ui_id_icon_get(C, itemptr.data, false);
+ if (!ELEM(iconid, 0, ICON_BLANK1)) {
+ has_id_icon = true;
+ }
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, UI_SEP_CHAR);
+ const ID *id = itemptr.data;
+ BKE_id_full_name_ui_prefix_get(
+ name_buf, itemptr.data, true, UI_SEP_CHAR, &name_prefix_offset);
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;
+ has_sep_char = (id->lib != NULL);
}
}
else {
@@ -452,12 +462,15 @@ void ui_rna_collection_search_update_fn(const struct bContext *C,
}
if (name) {
- if (skip_filter || BLI_strcasestr(name, str)) {
+ if (skip_filter || BLI_strcasestr(name + name_prefix_offset, str)) {
cis = MEM_callocN(sizeof(CollItemSearch), "CollectionItemSearch");
cis->data = itemptr.data;
cis->name = BLI_strdup(name);
cis->index = i;
cis->iconid = iconid;
+ cis->is_id = is_id;
+ cis->name_prefix_offset = name_prefix_offset;
+ cis->has_sep_char = has_sep_char;
BLI_addtail(items_list, cis);
}
if (name != name_buf) {
@@ -473,7 +486,24 @@ void ui_rna_collection_search_update_fn(const struct bContext *C,
/* add search items from temporary list */
for (cis = items_list->first; cis; cis = cis->next) {
- if (!UI_search_item_add(items, cis->name, cis->data, cis->iconid, UI_BUT_HAS_SEP_CHAR)) {
+ /* If no item has an own icon to display, libraries can use the library icons rather than the
+ * name prefix for showing the library status. */
+ int name_prefix_offset = cis->name_prefix_offset;
+ if (!has_id_icon && cis->is_id) {
+ cis->iconid = UI_library_icon_get(cis->data);
+ /* No need to re-allocate, string should be shorter than before (lib status prefix is
+ * removed). */
+ BKE_id_full_name_ui_prefix_get(name_buf, cis->data, false, UI_SEP_CHAR, &name_prefix_offset);
+ BLI_assert(strlen(name_buf) <= MEM_allocN_len(cis->name));
+ strcpy(cis->name, name_buf);
+ }
+
+ if (!UI_search_item_add(items,
+ cis->name,
+ cis->data,
+ cis->iconid,
+ cis->has_sep_char ? UI_BUT_HAS_SEP_CHAR : 0,
+ name_prefix_offset)) {
break;
}
}
@@ -505,9 +535,7 @@ int UI_icon_from_id(ID *id)
if (ob->type == OB_EMPTY) {
return ICON_EMPTY_DATA;
}
- else {
- return UI_icon_from_id(ob->data);
- }
+ return UI_icon_from_id(ob->data);
}
/* otherwise get it through RNA, creating the pointer
@@ -523,15 +551,13 @@ int UI_icon_from_report_type(int type)
if (type & RPT_ERROR_ALL) {
return ICON_ERROR;
}
- else if (type & RPT_WARNING_ALL) {
+ if (type & RPT_WARNING_ALL) {
return ICON_ERROR;
}
- else if (type & RPT_INFO_ALL) {
+ if (type & RPT_INFO_ALL) {
return ICON_INFO;
}
- else {
- return ICON_NONE;
- }
+ return ICON_NONE;
}
/********************************** Misc **************************************/
@@ -602,7 +628,7 @@ bool UI_but_online_manual_id(const uiBut *but, char *r_str, size_t maxlength)
RNA_property_identifier(but->rnaprop));
return true;
}
- else if (but->optype) {
+ if (but->optype) {
WM_operator_py_idname(r_str, but->optype->idname);
return true;
}