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/intern/wm_operators.c | |
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/intern/wm_operators.c')
-rw-r--r-- | source/blender/windowmanager/intern/wm_operators.c | 71 |
1 files changed, 53 insertions, 18 deletions
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) |