diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2013-11-07 00:56:18 +0400 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2013-11-07 00:56:18 +0400 |
commit | ad34a5cc1b344abc152f14183e2a3436b1737e50 (patch) | |
tree | fb40b1e8d7e47816fabf85562a32d6d71e1718de /source/blender/windowmanager | |
parent | 5cd28bbe8071e4e83fe0baafe8e04360f65c1778 (diff) |
Fix [#34675] *AFTER 2.69* Info view shows duplicate operators with incorrect values of args
Refactored a bit WM api to generate operator's pystring, now it can also handle correctly macro operators. Thanks to Campbell for the review!
Diffstat (limited to 'source/blender/windowmanager')
-rw-r--r-- | source/blender/windowmanager/WM_api.h | 4 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_event_system.c | 6 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_operators.c | 71 |
3 files changed, 59 insertions, 22 deletions
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index 75a6e4465bf..1f38368399a 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -272,7 +272,9 @@ bool WM_operator_last_properties_store(struct wmOperator *op); /* operator as a python command (resultuing string must be freed) */ -char *WM_operator_pystring(struct bContext *C, struct wmOperatorType *ot, struct PointerRNA *opptr, int all_args); +char *WM_operator_pystring_ex(struct bContext *C, struct wmOperator *op, const bool all_args, + struct wmOperatorType *ot, struct PointerRNA *opptr); +char *WM_operator_pystring(struct bContext *C, struct wmOperator *op, const bool all_args); char *WM_prop_pystring_assign(struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA *prop, int index); void WM_operator_bl_idname(char *to, const char *from); void WM_operator_py_idname(char *to, const char *from); diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 825c1ca9252..d60901f1325 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -491,7 +491,7 @@ int WM_operator_poll_context(bContext *C, wmOperatorType *ot, short context) static void wm_operator_print(bContext *C, wmOperator *op) { /* context is needed for enum function */ - char *buf = WM_operator_pystring(C, op->type, op->ptr, false); + char *buf = WM_operator_pystring(C, op, false); printf("%s\n", buf); MEM_freeN(buf); } @@ -626,7 +626,7 @@ static void wm_operator_reports(bContext *C, wmOperator *op, int retval, int cal if (op->type->flag & OPTYPE_REGISTER) { if (G.background == 0) { /* ends up printing these in the terminal, gets annoying */ /* Report the python string representation of the operator */ - char *buf = WM_operator_pystring(C, op->type, op->ptr, false); + char *buf = WM_operator_pystring(C, op, false); BKE_report(CTX_wm_reports(C), RPT_OPERATOR, buf); MEM_freeN(buf); } @@ -660,7 +660,7 @@ static void wm_operator_finished(bContext *C, wmOperator *op, int repeat) if (repeat == 0) { if (G.debug & G_DEBUG_WM) { - char *buf = WM_operator_pystring(C, op->type, op->ptr, false); + char *buf = WM_operator_pystring(C, op, false); BKE_report(CTX_wm_reports(C), RPT_OPERATOR, buf); MEM_freeN(buf); } diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index eb42f44b696..ab8dac396c5 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -521,13 +521,14 @@ void WM_operator_bl_idname(char *to, const char *from) to[0] = 0; } -/* print a string representation of the operator, with the args that it runs - * so python can run it again, +/* Print a string representation of the operator, with the args that it runs so python can run it again. * - * When calling from an existing wmOperator do. - * WM_operator_pystring(op->type, op->ptr); + * When calling from an existing wmOperator, better to use simple version: + * WM_operator_pystring(C, op); + * + * Note: both op and opptr may be NULL (op is only used for macro operators). */ -char *WM_operator_pystring(bContext *C, wmOperatorType *ot, PointerRNA *opptr, int all_args) +char *WM_operator_pystring_ex(bContext *C, wmOperator *op, const bool all_args, wmOperatorType *ot, PointerRNA *opptr) { char idname_py[OP_MAX_TYPENAME]; @@ -539,24 +540,53 @@ char *WM_operator_pystring(bContext *C, wmOperatorType *ot, PointerRNA *opptr, i /* arbitrary, but can get huge string with stroke painting otherwise */ int max_prop_length = 10; - /* only to get the orginal props for comparisons */ - PointerRNA opptr_default; + WM_operator_py_idname(idname_py, ot->idname); + BLI_dynstr_appendf(dynstr, "bpy.ops.%s(", idname_py); + + if (op && op->macro.first) { + /* Special handling for macros, else we only get default values in this case... */ + wmOperator *opm; + bool first_op = true; + for (opm = op->macro.first; opm; opm = opm->next) { + PointerRNA *opmptr = opm->ptr; + PointerRNA opmptr_default; + if (opmptr == NULL) { + WM_operator_properties_create_ptr(&opmptr_default, opm->type); + opmptr = &opmptr_default; + } + + cstring_args = RNA_pointer_as_string_id(C, opmptr); + if (first_op) { + BLI_dynstr_appendf(dynstr, "%s=%s", opm->type->idname, cstring_args); + first_op = false; + } + else { + BLI_dynstr_appendf(dynstr, ", %s=%s", opm->type->idname, cstring_args); + } + MEM_freeN(cstring_args); - if (opptr == NULL) { - WM_operator_properties_create_ptr(&opptr_default, ot); - opptr = &opptr_default; + if (opmptr == &opmptr_default) { + WM_operator_properties_free(&opmptr_default); + } + } } + else { + /* only to get the orginal props for comparisons */ + PointerRNA opptr_default; - WM_operator_py_idname(idname_py, ot->idname); - BLI_dynstr_appendf(dynstr, "bpy.ops.%s(", idname_py); + if (opptr == NULL) { + WM_operator_properties_create_ptr(&opptr_default, ot); + opptr = &opptr_default; + } - cstring_args = RNA_pointer_as_string_keywords(C, opptr, false, - all_args, max_prop_length); - BLI_dynstr_append(dynstr, cstring_args); - MEM_freeN(cstring_args); + cstring_args = RNA_pointer_as_string_keywords(C, opptr, false, all_args, max_prop_length); + BLI_dynstr_append(dynstr, cstring_args); + MEM_freeN(cstring_args); - if (opptr == &opptr_default) - WM_operator_properties_free(&opptr_default); + if (opptr == &opptr_default) { + WM_operator_properties_free(&opptr_default); + } + } BLI_dynstr_append(dynstr, ")"); @@ -565,6 +595,11 @@ char *WM_operator_pystring(bContext *C, wmOperatorType *ot, PointerRNA *opptr, i return cstring; } +char *WM_operator_pystring(bContext *C, wmOperator *op, const bool all_args) +{ + return WM_operator_pystring_ex(C, op, all_args, op->type, op->ptr); +} + /* return NULL if no match is found */ #if 0 static char *wm_prop_pystring_from_context(bContext *C, PointerRNA *ptr, PropertyRNA *prop, int index) |