UI: Show library names grayed out and right-aligned in menus
Should separate the data-block name better from the library name and improve readability.
This commit is contained in:
@@ -250,8 +250,10 @@ void BKE_main_id_repair_duplicate_names_listbase(struct ListBase *lb);
|
||||
|
||||
#define MAX_ID_FULL_NAME (64 + 64 + 3 + 1) /* 64 is MAX_ID_NAME - 2 */
|
||||
#define MAX_ID_FULL_NAME_UI (MAX_ID_FULL_NAME + 3) /* Adds 'keycode' two letters at beginning. */
|
||||
void BKE_id_full_name_get(char name[MAX_ID_FULL_NAME], const struct ID *id);
|
||||
void BKE_id_full_name_ui_prefix_get(char name[MAX_ID_FULL_NAME_UI], const struct ID *id);
|
||||
void BKE_id_full_name_get(char name[MAX_ID_FULL_NAME], const struct ID *id, char separator_str);
|
||||
void BKE_id_full_name_ui_prefix_get(char name[MAX_ID_FULL_NAME_UI],
|
||||
const struct ID *id,
|
||||
char separator_char);
|
||||
|
||||
char *BKE_id_to_unique_string_key(const struct ID *id);
|
||||
|
||||
|
||||
@@ -2068,9 +2068,11 @@ void BKE_libblock_rename(Main *bmain, ID *id, const char *name)
|
||||
* \note Result is unique to a given ID type in a given Main database.
|
||||
*
|
||||
* \param name: An allocated string of minimal length #MAX_ID_FULL_NAME,
|
||||
* will be filled with generated string.
|
||||
* will be filled with generated string.
|
||||
* \param separator_char: Character to use for separating name and library name. Can be 0 to use
|
||||
* default (' ').
|
||||
*/
|
||||
void BKE_id_full_name_get(char name[MAX_ID_FULL_NAME], const ID *id)
|
||||
void BKE_id_full_name_get(char name[MAX_ID_FULL_NAME], const ID *id, char separator_char)
|
||||
{
|
||||
strcpy(name, id->name + 2);
|
||||
|
||||
@@ -2078,7 +2080,7 @@ void BKE_id_full_name_get(char name[MAX_ID_FULL_NAME], const ID *id)
|
||||
const size_t idname_len = strlen(id->name + 2);
|
||||
const size_t libname_len = strlen(id->lib->id.name + 2);
|
||||
|
||||
name[idname_len] = ' ';
|
||||
name[idname_len] = separator_char ? separator_char : ' ';
|
||||
name[idname_len + 1] = '[';
|
||||
strcpy(name + idname_len + 2, id->lib->id.name + 2);
|
||||
name[idname_len + 2 + libname_len] = ']';
|
||||
@@ -2094,15 +2096,19 @@ void BKE_id_full_name_get(char name[MAX_ID_FULL_NAME], const ID *id)
|
||||
* \note Result is unique to a given ID type in a given Main database.
|
||||
*
|
||||
* \param name: An allocated string of minimal length #MAX_ID_FULL_NAME_UI,
|
||||
* will be filled with generated string.
|
||||
* will be filled with generated string.
|
||||
* \param separator_char: Character to use for separating name and library name. Can be 0 to use
|
||||
* default (' ').
|
||||
*/
|
||||
void BKE_id_full_name_ui_prefix_get(char name[MAX_ID_FULL_NAME_UI], const ID *id)
|
||||
void BKE_id_full_name_ui_prefix_get(char name[MAX_ID_FULL_NAME_UI],
|
||||
const ID *id,
|
||||
char separator_char)
|
||||
{
|
||||
name[0] = id->lib ? (ID_MISSING(id) ? 'M' : 'L') : ID_IS_OVERRIDE_LIBRARY(id) ? 'O' : ' ';
|
||||
name[1] = (id->flag & LIB_FAKEUSER) ? 'F' : ((id->us == 0) ? '0' : ' ');
|
||||
name[2] = ' ';
|
||||
|
||||
BKE_id_full_name_get(name + 3, id);
|
||||
BKE_id_full_name_get(name + 3, id, separator_char);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -555,6 +555,7 @@ static void ui_searchbox_region_draw_cb(const bContext *C, ARegion *region)
|
||||
char *name = data->items.names[a];
|
||||
int icon = data->items.icons[a];
|
||||
char *name_sep_test = NULL;
|
||||
const bool use_sep_char = data->use_sep || (state & UI_BUT_HAS_SEP_CHAR);
|
||||
|
||||
ui_searchbox_butrect(&rect, data, a);
|
||||
|
||||
@@ -563,7 +564,7 @@ static void ui_searchbox_region_draw_cb(const bContext *C, ARegion *region)
|
||||
!(name_sep_test = strstr(data->items.names[a], data->sep_string))) {
|
||||
|
||||
/* Simple menu item. */
|
||||
ui_draw_menu_item(&data->fstyle, &rect, name, icon, state, data->use_sep, NULL);
|
||||
ui_draw_menu_item(&data->fstyle, &rect, name, icon, state, use_sep_char, NULL);
|
||||
}
|
||||
else {
|
||||
/* Split menu item, faded text before the separator. */
|
||||
@@ -590,7 +591,7 @@ static void ui_searchbox_region_draw_cb(const bContext *C, ARegion *region)
|
||||
|
||||
/* The previous menu item draws the active selection. */
|
||||
ui_draw_menu_item(
|
||||
&data->fstyle, &rect, name_sep, icon, state & ~UI_ACTIVE, data->use_sep, NULL);
|
||||
&data->fstyle, &rect, name_sep, icon, state & ~UI_ACTIVE, use_sep_char, NULL);
|
||||
}
|
||||
}
|
||||
/* indicate more */
|
||||
|
||||
@@ -361,11 +361,11 @@ static bool id_search_add(const bContext *C,
|
||||
* followed by ID_NAME-2 characters from id->name
|
||||
*/
|
||||
char name_ui[MAX_ID_FULL_NAME_UI];
|
||||
BKE_id_full_name_ui_prefix_get(name_ui, id);
|
||||
BKE_id_full_name_ui_prefix_get(name_ui, id, UI_SEP_CHAR);
|
||||
|
||||
int iconid = ui_id_icon_get(C, id, template_ui->preview);
|
||||
|
||||
if (!UI_search_item_add(items, name_ui, id, iconid, 0)) {
|
||||
if (!UI_search_item_add(items, name_ui, id, iconid, UI_BUT_HAS_SEP_CHAR)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -441,7 +441,7 @@ void ui_rna_collection_search_update_fn(const struct bContext *C,
|
||||
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);
|
||||
BKE_id_full_name_ui_prefix_get(name_buf, itemptr.data, UI_SEP_CHAR);
|
||||
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;
|
||||
@@ -473,7 +473,7 @@ 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, 0)) {
|
||||
if (!UI_search_item_add(items, cis->name, cis->data, cis->iconid, UI_BUT_HAS_SEP_CHAR)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,14 +184,14 @@ static int rna_ID_name_editable(PointerRNA *ptr, const char **UNUSED(r_info))
|
||||
void rna_ID_name_full_get(PointerRNA *ptr, char *value)
|
||||
{
|
||||
ID *id = (ID *)ptr->data;
|
||||
BKE_id_full_name_get(value, id);
|
||||
BKE_id_full_name_get(value, id, 0);
|
||||
}
|
||||
|
||||
int rna_ID_name_full_length(PointerRNA *ptr)
|
||||
{
|
||||
ID *id = (ID *)ptr->data;
|
||||
char name[MAX_ID_FULL_NAME];
|
||||
BKE_id_full_name_get(name, id);
|
||||
BKE_id_full_name_get(name, id, 0);
|
||||
return strlen(name);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user