Commit: 1df115d9a35af7e187352f11ee24a0f797db2cb2
Author: Julian Eisel
Date:   Fri Sep 16 14:50:47 2016 +0200
Branches: master
https://developer.blender.org/rB1df115d9a35af7e187352f11ee24a0f797db2cb2

UI: Allow showing why button is disabled in tooltip

Uses red alert color. Operators that failed poll check already did this.

===================================================================

M       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 4ea5e20..d576f91 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 */

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to