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/windowmanager/intern/wm_operator_type.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/windowmanager/intern/wm_operator_type.c')
-rw-r--r-- | source/blender/windowmanager/intern/wm_operator_type.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/source/blender/windowmanager/intern/wm_operator_type.c b/source/blender/windowmanager/intern/wm_operator_type.c index 8f3052ace5e..96fbac3aecc 100644 --- a/source/blender/windowmanager/intern/wm_operator_type.c +++ b/source/blender/windowmanager/intern/wm_operator_type.c @@ -595,4 +595,35 @@ const char *WM_operatortype_name(struct wmOperatorType *ot, struct PointerRNA *p return (name && name[0]) ? name : RNA_struct_ui_name(ot->srna); } +char *WM_operatortype_description(struct bContext *C, + struct wmOperatorType *ot, + struct PointerRNA *properties) +{ + if (ot->get_description && properties) { + char *description = ot->get_description(C, ot, properties); + + if (description) { + if (description[0]) { + return description; + } + else { + MEM_freeN(description); + } + } + } + + const char *info = RNA_struct_ui_description(ot->srna); + + if (!(info && info[0])) { + info = RNA_struct_ui_name(ot->srna); + } + + if (info && info[0]) { + return BLI_strdup(info); + } + else { + return NULL; + } +} + /** \} */ |