better blender doesnt look idiot for siggraph with tips wider then the screen.
authorCampbell Barton <ideasman42@gmail.com>
Wed, 29 Jul 2009 23:48:06 +0000 (23:48 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 29 Jul 2009 23:48:06 +0000 (23:48 +0000)
only show operator args in the tooltip that are different from the defaults.

source/blender/editors/interface/interface_regions.c
source/blender/windowmanager/WM_api.h
source/blender/windowmanager/intern/wm.c
source/blender/windowmanager/intern/wm_event_system.c
source/blender/windowmanager/intern/wm_operators.c

index a6822618f0f8eb0c5569bdadd94ad19eee725104..b59db0556471ff2d8555b1fa8f3b8498c6772983 100644 (file)
@@ -396,7 +396,7 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but)
                char *str;
                opptr= uiButGetOperatorPtrRNA(but); /* allocated when needed, the button owns it */
 
-               str= WM_operator_pystring(but->optype, opptr);
+               str= WM_operator_pystring(but->optype, opptr, 0);
 
                /* operator info */
                BLI_snprintf(data->lines[data->totline], sizeof(data->lines[0]), "Python: %s", str);
index 3670f1a613f48b00fa671a2b2d61c9352ee67c81..decd855eae06685c960cbc6b63b02488841f21c4 100644 (file)
@@ -172,7 +172,7 @@ void                WM_operator_properties_free(struct PointerRNA *ptr);
 void           WM_operator_properties_filesel(struct wmOperatorType *ot, int filter);
 
                /* operator as a python command (resultuing string must be free'd) */
-char           *WM_operator_pystring(struct wmOperatorType *ot, struct PointerRNA *opptr);
+char           *WM_operator_pystring(struct wmOperatorType *ot, struct PointerRNA *opptr, int all_args);
 void           WM_operator_bl_idname(char *to, const char *from);
 void           WM_operator_py_idname(char *to, const char *from);
 
index 46cf13f7d75824dbc9b0bc79b7ee9bc4a214ab31..1315737805712f02669ba15f8c1c84ab073dadfd 100644 (file)
@@ -103,7 +103,7 @@ void wm_operator_register(bContext *C, wmOperator *op)
        
        
        /* Report the string representation of the operator */
-       buf = WM_operator_pystring(op->type, op->ptr);
+       buf = WM_operator_pystring(op->type, op->ptr, 1);
        BKE_report(CTX_wm_reports(C), RPT_OPERATOR, buf);
        MEM_freeN(buf);
        
index 86de5498ce95cb049275cd01738fca457e5ebda6..d40e6c60bfddb51f0d2e224b844bde0eeb3edf1b 100644 (file)
@@ -362,7 +362,7 @@ static wmOperator *wm_operator_create(wmWindowManager *wm, wmOperatorType *ot, P
 
 static void wm_operator_print(wmOperator *op)
 {
-       char *buf = WM_operator_pystring(op->type, op->ptr);
+       char *buf = WM_operator_pystring(op->type, op->ptr, 1);
        printf("%s\n", buf);
        MEM_freeN(buf);
 }
index d0d50810fdcdd3e639b78d15faf58d30d7967da4..41613d0ab78131a849b2cd9dfd8c438a1e0b3fba 100644 (file)
@@ -345,7 +345,7 @@ void WM_operator_bl_idname(char *to, const char *from)
  * When calling from an existing wmOperator do.
  * WM_operator_pystring(op->type, op->ptr);
  */
-char *WM_operator_pystring(wmOperatorType *ot, PointerRNA *opptr)
+char *WM_operator_pystring(wmOperatorType *ot, PointerRNA *opptr, int all_args)
 {
        const char *arg_name= NULL;
        char idname_py[OP_MAX_TYPENAME];
@@ -355,7 +355,17 @@ char *WM_operator_pystring(wmOperatorType *ot, PointerRNA *opptr)
        /* for building the string */
        DynStr *dynstr= BLI_dynstr_new();
        char *cstring, *buf;
-       int first_iter=1;
+       int first_iter=1, ok= 1;
+
+
+       /* only to get the orginal props for comparisons */
+       PointerRNA opptr_default;
+       PropertyRNA *prop_default;
+       char *buf_default;
+       if(!all_args) {
+               WM_operator_properties_create(&opptr_default, ot->idname);
+       }
+
 
        WM_operator_py_idname(idname_py, ot->idname);
        BLI_dynstr_appendf(dynstr, "bpy.ops.%s(", idname_py);
@@ -370,13 +380,36 @@ char *WM_operator_pystring(wmOperatorType *ot, PointerRNA *opptr)
 
                buf= RNA_property_as_string(opptr, prop);
                
-               BLI_dynstr_appendf(dynstr, first_iter?"%s=%s":", %s=%s", arg_name, buf);
+               ok= 1;
+
+               if(!all_args) {
+                       /* not verbose, so only add in attributes that use non-default values
+                        * slow but good for tooltips */
+                       prop_default= RNA_struct_find_property(&opptr_default, arg_name);
+
+                       if(prop_default) {
+                               buf_default= RNA_property_as_string(&opptr_default, prop_default);
+
+                               if(strcmp(buf, buf_default)==0)
+                                       ok= 0; /* values match, dont bother printing */
+
+                               MEM_freeN(buf_default);
+                       }
+
+               }
+               if(ok) {
+                       BLI_dynstr_appendf(dynstr, first_iter?"%s=%s":", %s=%s", arg_name, buf);
+                       first_iter = 0;
+               }
 
                MEM_freeN(buf);
-               first_iter = 0;
+
        }
        RNA_PROP_END;
 
+       if(all_args==0)
+               WM_operator_properties_free(&opptr_default);
+
        BLI_dynstr_append(dynstr, ")");
 
        cstring = BLI_dynstr_get_cstring(dynstr);