bugfix [#24179] Button "Loop Cut and Slide" on Mesh Tools not work
authorCampbell Barton <ideasman42@gmail.com>
Fri, 8 Oct 2010 11:33:10 +0000 (11:33 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 8 Oct 2010 11:33:10 +0000 (11:33 +0000)
also added a message in the tooltip to say `why` a buttons disabled.
depends on the operators poll setting the message.

source/blender/editors/interface/interface_regions.c
source/blender/editors/mesh/editmesh_mods.c
source/blender/editors/mesh/loopcut.c
source/blender/editors/screen/screen_ops.c

index 53981f202ed6bbb6c57c19cd0cce0ae20f2abe48..a0f852239c4cb2ef7351d75a3a2d642c7190a0e9 100644 (file)
@@ -27,6 +27,7 @@
 #include <stdarg.h>
 #include <stdlib.h>
 #include <string.h>
+#include <assert.h>
 
 #include "MEM_guardedalloc.h"
 
@@ -300,7 +301,7 @@ typedef struct uiTooltipData {
        rcti bbox;
        uiFontStyle fstyle;
        char lines[MAX_TOOLTIP_LINES][512];
-       int linedark[MAX_TOOLTIP_LINES];
+       unsigned int color[MAX_TOOLTIP_LINES];
        int totline;
        int toth, spaceh, lineh;
 } uiTooltipData;
@@ -320,9 +321,7 @@ static void ui_tooltip_region_draw(const bContext *C, ARegion *ar)
        bbox.ymin= bbox.ymax - data->lineh;
 
        for(a=0; a<data->totline; a++) {
-               if(!data->linedark[a]) glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
-               else glColor4f(0.5f, 0.5f, 0.5f, 1.0f);
-
+               cpack(data->color[a]);
                uiStyleFontDraw(&data->fstyle, &bbox, data->lines[a]);
                bbox.ymin -= data->lineh + data->spaceh;
                bbox.ymax -= data->lineh + data->spaceh;
@@ -358,6 +357,7 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but)
 
        if(but->tip && strlen(but->tip)) {
                BLI_strncpy(data->lines[data->totline], but->tip, sizeof(data->lines[0]));
+               data->color[data->totline]= 0xFFFFFF;
                data->totline++;
        }
 
@@ -367,7 +367,7 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but)
 
                if(WM_key_event_operator_string(C, but->optype->idname, but->opcontext, prop, buf, sizeof(buf))) {
                        BLI_snprintf(data->lines[data->totline], sizeof(data->lines[0]), "Shortcut: %s", buf);
-                       data->linedark[data->totline]= 1;
+                       data->color[data->totline]= 0x888888;
                        data->totline++;
                }
        }
@@ -377,7 +377,7 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but)
                ui_get_but_string(but, buf, sizeof(buf));
                if(buf[0]) {
                        BLI_snprintf(data->lines[data->totline], sizeof(data->lines[0]), "Value: %s", buf);
-                       data->linedark[data->totline]= 1;
+                       data->color[data->totline]= 0x888888;
                        data->totline++;
                }
        }
@@ -388,7 +388,7 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but)
                if (unit_type == PROP_UNIT_ROTATION) {
                        if (RNA_property_type(but->rnaprop) == PROP_FLOAT) {
                                BLI_snprintf(data->lines[data->totline], sizeof(data->lines[0]), "Radians: %f", RNA_property_float_get_index(&but->rnapoin, but->rnaprop, but->rnaindex));
-                               data->linedark[data->totline]= 1;
+                               data->color[data->totline]= 0x888888;
                                data->totline++;
                        }
                }
@@ -397,21 +397,21 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but)
                        if(ui_but_anim_expression_get(but, buf, sizeof(buf))) {
                                /* expression */
                                BLI_snprintf(data->lines[data->totline], sizeof(data->lines[0]), "Expression: %s", buf);
-                               data->linedark[data->totline]= 1;
+                               data->color[data->totline]= 0x888888;
                                data->totline++;
                        }
                }
 
                /* rna info */
                BLI_snprintf(data->lines[data->totline], sizeof(data->lines[0]), "Python: %s.%s", RNA_struct_identifier(but->rnapoin.type), RNA_property_identifier(but->rnaprop));
-               data->linedark[data->totline]= 1;
+               data->color[data->totline]= 0x888888;
                data->totline++;
                
                if(but->rnapoin.id.data) {
                        ID *id= but->rnapoin.id.data;
                        if(id->lib && id->lib->name) {
                                BLI_snprintf(data->lines[data->totline], sizeof(data->lines[0]), "Library: %s", id->lib->name);
-                               data->linedark[data->totline]= 1;
+                               data->color[data->totline]= 0x888888;
                                data->totline++;
                        }
                }
@@ -425,12 +425,27 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but)
 
                /* operator info */
                BLI_snprintf(data->lines[data->totline], sizeof(data->lines[0]), "Python: %s", str);
-               data->linedark[data->totline]= 1;
+               data->color[data->totline]= 0x888888;
                data->totline++;
 
                MEM_freeN(str);
+
+               /* second check if we are disabled - why */
+               if(but->flag & UI_BUT_DISABLED) {
+                       const char *poll_msg;
+                       CTX_wm_operator_poll_msg_set(C, NULL);
+                       WM_operator_poll(C, but->optype);
+                       poll_msg= CTX_wm_operator_poll_msg_get(C);
+                       if(poll_msg) {
+                               BLI_snprintf(data->lines[data->totline], sizeof(data->lines[0]), "Disabled: %s", poll_msg);
+                               data->color[data->totline]= 0x6666ff; /* alert */
+                               data->totline++;                        
+                       }
+               }
        }
 
+       assert(data->totline < MAX_TOOLTIP_LINES);
+       
        if(data->totline == 0) {
                MEM_freeN(data);
                return NULL;
index f8018c686f5944cff2bc16d612cc7308977ee6f6..164e8980b832e2972f2b7c96e5c1dae795ccc80b 100644 (file)
@@ -2113,7 +2113,7 @@ void MESH_OT_loop_select(wmOperatorType *ot)
        
        /* api callbacks */
        ot->invoke= mesh_select_loop_invoke;
-       ot->poll= ED_operator_editmesh_region_view3d;
+       ot->poll= ED_operator_editmesh_view3d;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
index 7f1a7d0e1fc8f5053c5e96dfa98084615751c51c..13538a6f218881a8fddbe35cb44e2ac55e5b32df 100644 (file)
@@ -506,7 +506,7 @@ void MESH_OT_loopcut (wmOperatorType *ot)
        ot->invoke= ringcut_invoke;
        ot->modal= ringcut_modal;
        ot->cancel= ringcut_cancel;
-       ot->poll= ED_operator_editmesh_region_view3d;
+       ot->poll= ED_operator_editmesh_view3d;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
index 7b9bad5945d41263e10a4b7a59d7c7cc610a337a..613c8bc01785aaecceb58bfa67a25230de30593a 100644 (file)
@@ -244,7 +244,11 @@ int ED_operator_editmesh_view3d(bContext *C)
 
 int ED_operator_editmesh_region_view3d(bContext *C)
 {
-       return ED_operator_editmesh(C) && CTX_wm_region_view3d(C);
+       if(ED_operator_editmesh(C) && CTX_wm_region_view3d(C))
+               return 1;
+
+       CTX_wm_operator_poll_msg_set(C, "expected a view3d region & editmesh");
+       return 0;
 }
 
 int ED_operator_editarmature(bContext *C)