UI: show toolbar shortcuts

When toobar text is expanded, show shortcuts
(normally confined to menus).
This commit is contained in:
Campbell Barton 2018-05-13 10:25:18 +02:00
parent e7ee9cfd9e
commit 06a786f12d
Notes: blender-bot 2023-02-14 05:53:37 +01:00
Referenced by issue #55036, Tool System Todo
4 changed files with 16 additions and 4 deletions

View File

@ -142,6 +142,8 @@ enum {
#define UI_BLOCK_LIST_ITEM (1 << 19)
#define UI_BLOCK_RADIAL (1 << 20)
#define UI_BLOCK_POPOVER (1 << 21)
/** Always show keymaps, even for non-menus. */
#define UI_BLOCK_SHOW_SHORTCUT_ALWAYS (1 << 22)
/* uiPopupBlockHandle->menuretval */
#define UI_RETURN_CANCEL (1 << 0) /* cancel all menus cascading */

View File

@ -1096,7 +1096,7 @@ static void ui_menu_block_set_keymaps(const bContext *C, uiBlock *block)
uiBut *but;
char buf[128];
BLI_assert(block->flag & UI_BLOCK_LOOP);
BLI_assert(block->flag & (UI_BLOCK_LOOP | UI_BLOCK_SHOW_SHORTCUT_ALWAYS));
/* only do it before bounding */
if (block->rect.xmin != block->rect.xmax)
@ -1112,7 +1112,13 @@ static void ui_menu_block_set_keymaps(const bContext *C, uiBlock *block)
}
else {
for (but = block->buttons.first; but; but = but->next) {
if (but->dt != UI_EMBOSS_PULLDOWN) {
if (block->flag & UI_BLOCK_SHOW_SHORTCUT_ALWAYS) {
/* Skip icon-only buttons (as used in the toolbar). */
if (but->drawstr[0] == '\0') {
continue;
}
}
else if (but->dt != UI_EMBOSS_PULLDOWN) {
continue;
}
@ -1216,7 +1222,7 @@ void UI_block_end_ex(const bContext *C, uiBlock *block, const int xy[2], int r_x
ui_menu_block_set_keyaccels(block); /* could use a different flag to check */
}
if (block->flag & UI_BLOCK_LOOP) {
if (block->flag & (UI_BLOCK_LOOP | UI_BLOCK_SHOW_SHORTCUT_ALWAYS)) {
ui_menu_block_set_keymaps(C, block);
}

View File

@ -3504,6 +3504,10 @@ uiLayout *UI_block_layout(uiBlock *block, int dir, int type, int x, int y, int s
if (type == UI_LAYOUT_MENU || type == UI_LAYOUT_PIEMENU)
layout->space = 0;
if (type == UI_LAYOUT_TOOLBAR) {
block->flag |= UI_BLOCK_SHOW_SHORTCUT_ALWAYS;
}
if (dir == UI_LAYOUT_HORIZONTAL) {
layout->h = size;
layout->root->emh = em * UI_UNIT_Y;

View File

@ -1868,7 +1868,7 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b
#endif
/* cut string in 2 parts - only for menu entries */
if ((but->block->flag & UI_BLOCK_LOOP) &&
if ((but->block->flag & (UI_BLOCK_LOOP | UI_BLOCK_SHOW_SHORTCUT_ALWAYS)) &&
(but->editstr == NULL))
{
if (but->flag & UI_BUT_HAS_SEP_CHAR) {