diff options
author | Campbell Barton <ideasman42@gmail.com> | 2021-04-20 04:57:28 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2021-04-20 05:07:01 +0300 |
commit | ebe04bd3cafaa1f88bd51eee5b3e7bef38ae69bc (patch) | |
tree | 7af16c8b05e7732b939ed40816ce9388364576af /source/blender/editors/interface/interface_region_tooltip.c | |
parent | 985ccba77c6e907ae55ac47d8ac56d1e84b46286 (diff) |
PyAPI: support Operator.poll functions 'disabled' hint
Python scripts can now define the reason it's poll function fails using:
`Operator.poll_message_set(message, ...)`
This supports both regular text as well as delaying message creation
using a callback which should be used in situations where constructing
detailed messages is too much overhead for a poll function.
Ref D11001
Diffstat (limited to 'source/blender/editors/interface/interface_region_tooltip.c')
-rw-r--r-- | source/blender/editors/interface/interface_region_tooltip.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/source/blender/editors/interface/interface_region_tooltip.c b/source/blender/editors/interface/interface_region_tooltip.c index e5287ee6733..accfb78ab94 100644 --- a/source/blender/editors/interface/interface_region_tooltip.c +++ b/source/blender/editors/interface/interface_region_tooltip.c @@ -947,12 +947,13 @@ static uiTooltipData *ui_tooltip_data_from_button(bContext *C, uiBut *but) /* button is disabled, we may be able to tell user why */ if (but->flag & UI_BUT_DISABLED) { const char *disabled_msg = NULL; + bool disabled_msg_free = false; /* if operator poll check failed, it can give pretty precise info why */ if (but->optype) { CTX_wm_operator_poll_msg_clear(C); WM_operator_poll_context(C, but->optype, but->opcontext); - disabled_msg = CTX_wm_operator_poll_msg_get(C); + disabled_msg = CTX_wm_operator_poll_msg_get(C, &disabled_msg_free); } /* alternatively, buttons can store some reasoning too */ else if (but->disabled_info) { @@ -967,6 +968,9 @@ static uiTooltipData *ui_tooltip_data_from_button(bContext *C, uiBut *but) }); field->text = BLI_sprintfN(TIP_("Disabled: %s"), disabled_msg); } + if (disabled_msg_free) { + MEM_freeN((void *)disabled_msg); + } } if ((U.flag & USER_TOOLTIPS_PYTHON) && !but->optype && rna_struct.strinfo) { |