diff options
author | Alexander Gavrilov <angavrilov@gmail.com> | 2019-09-06 16:26:10 +0300 |
---|---|---|
committer | Alexander Gavrilov <angavrilov@gmail.com> | 2019-09-06 22:05:20 +0300 |
commit | 9ecbd67dfb672cd13f021c82d83aeb7ae8a8cf10 (patch) | |
tree | 9edad541160077d63cd77fe9c0210d29bebad6f3 /source/blender/makesrna/intern/rna_wm.c | |
parent | b0b24b77ffc3e34b3aef24ff658826a8aeca7782 (diff) |
Python API: implement an Operator callback for dynamic description.
Blender UI Layout API allows supplying parameters to operators via
button definitions. If an operator behavior strongly depends on its
parameters, it may be difficult to write a tooltip that covers all
of its operation modes. Thus it is useful to provide a way for the
operator to produce different descriptions based on the input info.
Reviewers: campbellbarton
Differential Revision: https://developer.blender.org/D5709
Diffstat (limited to 'source/blender/makesrna/intern/rna_wm.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_wm.c | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c index c3ffeaf6f6f..5f60ecf449b 100644 --- a/source/blender/makesrna/intern/rna_wm.c +++ b/source/blender/makesrna/intern/rna_wm.c @@ -1420,6 +1420,39 @@ static void rna_operator_cancel_cb(bContext *C, wmOperator *op) RNA_parameter_list_free(&list); } +static char *rna_operator_description_cb(bContext *C, wmOperatorType *ot, PointerRNA *prop_ptr) +{ + extern FunctionRNA rna_Operator_description_func; + + PointerRNA ptr; + ParameterList list; + FunctionRNA *func; + void *ret; + char *result; + + RNA_pointer_create(NULL, ot->ext.srna, NULL, &ptr); /* dummy */ + func = &rna_Operator_description_func; /* RNA_struct_find_function(&ptr, "description"); */ + + RNA_parameter_list_create(&list, &ptr, func); + RNA_parameter_set_lookup(&list, "context", &C); + RNA_parameter_set_lookup(&list, "properties", prop_ptr); + ot->ext.call(C, &ptr, func, &list); + + RNA_parameter_get_lookup(&list, "result", &ret); + result = (char *)ret; + + if (result && result[0]) { + result = BLI_strdup(result); + } + else { + result = NULL; + } + + RNA_parameter_list_free(&list); + + return result; +} + static void rna_Operator_unregister(struct Main *bmain, StructRNA *type); /* bpy_operator_wrap.c */ @@ -1437,7 +1470,7 @@ static StructRNA *rna_Operator_register(Main *bmain, wmOperatorType dummyot = {NULL}; wmOperator dummyop = {NULL}; PointerRNA dummyotr; - int have_function[7]; + int have_function[8]; struct { char idname[OP_MAX_TYPENAME]; @@ -1531,6 +1564,7 @@ static StructRNA *rna_Operator_register(Main *bmain, dummyot.modal = (have_function[4]) ? rna_operator_modal_cb : NULL; dummyot.ui = (have_function[5]) ? rna_operator_draw_cb : NULL; dummyot.cancel = (have_function[6]) ? rna_operator_cancel_cb : NULL; + dummyot.get_description = (have_function[7]) ? rna_operator_description_cb : NULL; WM_operatortype_append_ptr(BPY_RNA_operator_wrapper, (void *)&dummyot); /* update while blender is running */ |