UI: always return shortcuts from UI_but_string_info_get on request

Change the behavior of UI_but_string_info_get to fill in shortcuts
when requested.

Previously shortcuts were ignored for menus, because showing shortcuts
in tool-tips which are already displayed in the menu isn't needed.

Move this logic to tool-tip creation so other the shortcuts may be
accessed in other contexts.
This commit is contained in:
Campbell Barton
2024-01-18 10:52:58 +11:00
parent a3b4078be3
commit b8a340e630
3 changed files with 24 additions and 14 deletions
@@ -1413,16 +1413,24 @@ void UI_but_unit_type_set(uiBut *but, int unit_type);
int UI_but_unit_type_get(const uiBut *but);
enum uiStringInfoType {
BUT_GET_RNAPROP_IDENTIFIER = 1,
/**
* Ignore this item, use when accessing the data should be done conditionally.
*/
BUT_GET_NOP = 0,
BUT_GET_RNAPROP_IDENTIFIER,
BUT_GET_RNASTRUCT_IDENTIFIER,
BUT_GET_RNAENUM_IDENTIFIER,
BUT_GET_LABEL,
/** Query the result of #uiBut::tip_label_func(). Meant to allow overriding the label to be
* displayed in the tooltip. */
/**
* Query the result of #uiBut::tip_label_func().
* Meant to allow overriding the label to be displayed in the tool-tip.
*/
BUT_GET_TIP_LABEL,
BUT_GET_RNA_LABEL,
BUT_GET_RNAENUM_LABEL,
BUT_GET_RNA_LABEL_CONTEXT, /* Context specified in CTX_XXX_ macros are just unreachable! */
/** Context specified in `CTX_*_` macros are just unreachable! */
BUT_GET_RNA_LABEL_CONTEXT,
BUT_GET_TIP,
BUT_GET_RNA_TIP,
BUT_GET_RNAENUM_TIP,
+6 -10
View File
@@ -6788,19 +6788,15 @@ void UI_but_string_info_get(bContext *C, uiBut *but, ...)
* Pie menus are an exception as they already have a shortcut on display
* however this is only used within the context of the pie menu. */
else if (type == BUT_GET_OP_KEYMAP) {
if (!(ui_block_is_menu(but->block) && !ui_block_is_pie_menu(but->block))) {
char buf[128];
if (ui_but_event_operator_string(C, but, buf, sizeof(buf))) {
tmp = buf;
}
char buf[128];
if (ui_but_event_operator_string(C, but, buf, sizeof(buf))) {
tmp = buf;
}
}
else if (type == BUT_GET_PROP_KEYMAP) {
if (!(ui_block_is_menu(but->block) && !ui_block_is_pie_menu(but->block))) {
char buf[128];
if (ui_but_event_property_operator_string(C, but, buf, sizeof(buf))) {
tmp = buf;
}
char buf[128];
if (ui_but_event_property_operator_string(C, but, buf, sizeof(buf))) {
tmp = buf;
}
}
@@ -845,6 +845,12 @@ static uiTooltipData *ui_tooltip_data_from_button_or_extra_icon(bContext *C,
/* create tooltip data */
uiTooltipData *data = MEM_cnew<uiTooltipData>(__func__);
/* Menus already show shortcuts, don't show them in the tool-tips. */
if (ui_block_is_menu(but->block) && !ui_block_is_pie_menu(but->block)) {
op_keymap.type = BUT_GET_NOP;
prop_keymap.type = BUT_GET_NOP;
}
if (extra_icon) {
if (is_label) {
UI_but_extra_icon_string_info_get(