From 89ed6b12936bc2a89b18cf6dbd7b86e0fbc760d3 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 2 Sep 2020 12:54:06 +1000 Subject: UI: simplify tool-tip logic for operators - Use WM_operatortype_description to get the operator description. - Pass properties to WM_operatortype_name, so the operator name callback is used. - Add UI_but_operatortype_get_from_enum_menu function to access the operator from enum menus. - Change WM_operatortype_description to return NULL when there is no description, use WM_operatortype_description_or_name when either can be used. --- .../windowmanager/intern/wm_operator_type.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'source/blender/windowmanager/intern') diff --git a/source/blender/windowmanager/intern/wm_operator_type.c b/source/blender/windowmanager/intern/wm_operator_type.c index 457cd0f16be..7cc20baf606 100644 --- a/source/blender/windowmanager/intern/wm_operator_type.c +++ b/source/blender/windowmanager/intern/wm_operator_type.c @@ -611,15 +611,27 @@ char *WM_operatortype_description(struct bContext *C, } 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); } return NULL; } +/** + * Use when we want a label, preferring the description. + */ +char *WM_operatortype_description_or_name(struct bContext *C, + struct wmOperatorType *ot, + struct PointerRNA *properties) +{ + char *text = WM_operatortype_description(C, ot, properties); + if (text == NULL) { + const char *text_orig = WM_operatortype_name(ot, properties); + if (text_orig != NULL) { + text = BLI_strdup(text_orig); + } + } + return text; +} + /** \} */ -- cgit v1.2.3