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/editors/interface | |
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/editors/interface')
-rw-r--r-- | source/blender/editors/interface/interface.c | 5 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_region_tooltip.c | 14 |
2 files changed, 9 insertions, 10 deletions
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index 78b190a59e0..7bfd0200362 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -4250,7 +4250,7 @@ static uiBut *ui_def_but_operator_ptr(uiBlock *block, } } - if ((!tip || tip[0] == '\0') && ot && ot->srna) { + if ((!tip || tip[0] == '\0') && ot && ot->srna && !ot->get_description) { tip = RNA_struct_ui_description(ot->srna); } @@ -6350,6 +6350,9 @@ void UI_but_string_info_get(bContext *C, uiBut *but, ...) else if (but->tip && but->tip[0]) { tmp = BLI_strdup(but->tip); } + else if (but->optype && but->optype->get_description) { + tmp = WM_operatortype_description(C, but->optype, but->opptr); + } else { type = BUT_GET_RNA_TIP; /* Fail-safe solution... */ } diff --git a/source/blender/editors/interface/interface_region_tooltip.c b/source/blender/editors/interface/interface_region_tooltip.c index 7387fe5eb1c..3f20e8247b9 100644 --- a/source/blender/editors/interface/interface_region_tooltip.c +++ b/source/blender/editors/interface/interface_region_tooltip.c @@ -932,18 +932,14 @@ static uiTooltipData *ui_tooltip_data_from_gizmo(bContext *C, wmGizmo *gz) NULL; if (gzop != NULL) { /* Description */ - const char *info = RNA_struct_ui_description(gzop->type->srna); - if (!(info && info[0])) { - info = RNA_struct_ui_name(gzop->type->srna); - } + char *info = WM_operatortype_description(C, gzop->type, &gzop->ptr); + + if (info != NULL) { + char *text = info; - if (info && info[0]) { - char *text = NULL; if (gzop_actions[i].prefix != NULL) { text = BLI_sprintfN("%s: %s", gzop_actions[i].prefix, info); - } - else { - text = BLI_strdup(info); + MEM_freeN(info); } if (text != NULL) { |