From 1df115d9a35af7e187352f11ee24a0f797db2cb2 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Fri, 16 Sep 2016 14:50:47 +0200 Subject: UI: Allow showing why button is disabled in tooltip Uses red alert color. Operators that failed poll check already did this. --- .../blender/editors/interface/interface_regions.c | 28 +++++++++++++++------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'source/blender/editors/interface/interface_regions.c') diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c index 4ea5e2092b6..d576f919467 100644 --- a/source/blender/editors/interface/interface_regions.c +++ b/source/blender/editors/interface/interface_regions.c @@ -453,20 +453,30 @@ static uiTooltipData *ui_tooltip_data_from_button(bContext *C, uiBut *but) } MEM_freeN(str); + } + + /* button is disabled, we may be able to tell user why */ + if ((but->flag & UI_BUT_DISABLED) || but->lock) { + const char *disabled_msg = NULL; - /* second check if we are disabled - why */ - if (but->flag & UI_BUT_DISABLED) { - const char *poll_msg; + /* if operator poll check failed, it can give pretty precise info why */ + if (but->optype) { CTX_wm_operator_poll_msg_set(C, NULL); WM_operator_poll_context(C, but->optype, but->opcontext); - poll_msg = CTX_wm_operator_poll_msg_get(C); - if (poll_msg) { - BLI_snprintf(data->lines[data->totline], sizeof(data->lines[0]), TIP_("Disabled: %s"), poll_msg); - data->format[data->totline].color_id = UI_TIP_LC_ALERT; - data->totline++; - } + disabled_msg = CTX_wm_operator_poll_msg_get(C); + } + /* alternatively, buttons can store some reasoning too */ + else if (but->lockstr && but->lockstr[0]) { + disabled_msg = but->lockstr; + } + + if (disabled_msg) { + BLI_snprintf(data->lines[data->totline], sizeof(data->lines[0]), TIP_("Disabled: %s"), disabled_msg); + data->format[data->totline].color_id = UI_TIP_LC_ALERT; + data->totline++; } } + if ((U.flag & USER_TOOLTIPS_PYTHON) == 0 && !but->optype && rna_struct.strinfo) { if (rna_prop.strinfo) { /* Struct and prop */ -- cgit v1.2.3