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 (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. */
|
#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_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);
|
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);
|
char *BKE_id_to_unique_string_key(const struct ID *id);
|
||||||
|
|
||||||
|
|||||||
@@ -2069,8 +2069,10 @@ void BKE_libblock_rename(Main *bmain, ID *id, const char *name)
|
|||||||
*
|
*
|
||||||
* \param name: An allocated string of minimal length #MAX_ID_FULL_NAME,
|
* \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);
|
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 idname_len = strlen(id->name + 2);
|
||||||
const size_t libname_len = strlen(id->lib->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] = '[';
|
name[idname_len + 1] = '[';
|
||||||
strcpy(name + idname_len + 2, id->lib->id.name + 2);
|
strcpy(name + idname_len + 2, id->lib->id.name + 2);
|
||||||
name[idname_len + 2 + libname_len] = ']';
|
name[idname_len + 2 + libname_len] = ']';
|
||||||
@@ -2095,14 +2097,18 @@ void BKE_id_full_name_get(char name[MAX_ID_FULL_NAME], const ID *id)
|
|||||||
*
|
*
|
||||||
* \param name: An allocated string of minimal length #MAX_ID_FULL_NAME_UI,
|
* \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[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[1] = (id->flag & LIB_FAKEUSER) ? 'F' : ((id->us == 0) ? '0' : ' ');
|
||||||
name[2] = ' ';
|
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];
|
char *name = data->items.names[a];
|
||||||
int icon = data->items.icons[a];
|
int icon = data->items.icons[a];
|
||||||
char *name_sep_test = NULL;
|
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);
|
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))) {
|
!(name_sep_test = strstr(data->items.names[a], data->sep_string))) {
|
||||||
|
|
||||||
/* Simple menu item. */
|
/* 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 {
|
else {
|
||||||
/* Split menu item, faded text before the separator. */
|
/* 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. */
|
/* The previous menu item draws the active selection. */
|
||||||
ui_draw_menu_item(
|
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 */
|
/* indicate more */
|
||||||
|
|||||||
@@ -361,11 +361,11 @@ static bool id_search_add(const bContext *C,
|
|||||||
* followed by ID_NAME-2 characters from id->name
|
* followed by ID_NAME-2 characters from id->name
|
||||||
*/
|
*/
|
||||||
char name_ui[MAX_ID_FULL_NAME_UI];
|
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);
|
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;
|
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);
|
name = RNA_struct_name_get_alloc(&itemptr, name_buf, sizeof(name_buf), NULL);
|
||||||
}
|
}
|
||||||
else {
|
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,
|
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 string buffer should be big enough to hold full UI ID name");
|
||||||
name = name_buf;
|
name = name_buf;
|
||||||
@@ -473,7 +473,7 @@ void ui_rna_collection_search_update_fn(const struct bContext *C,
|
|||||||
|
|
||||||
/* add search items from temporary list */
|
/* add search items from temporary list */
|
||||||
for (cis = items_list->first; cis; cis = cis->next) {
|
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;
|
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)
|
void rna_ID_name_full_get(PointerRNA *ptr, char *value)
|
||||||
{
|
{
|
||||||
ID *id = (ID *)ptr->data;
|
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)
|
int rna_ID_name_full_length(PointerRNA *ptr)
|
||||||
{
|
{
|
||||||
ID *id = (ID *)ptr->data;
|
ID *id = (ID *)ptr->data;
|
||||||
char name[MAX_ID_FULL_NAME];
|
char name[MAX_ID_FULL_NAME];
|
||||||
BKE_id_full_name_get(name, id);
|
BKE_id_full_name_get(name, id, 0);
|
||||||
return strlen(name);
|
return strlen(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user