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. --- source/blender/windowmanager/WM_api.h | 3 +++ .../windowmanager/intern/wm_operator_type.c | 22 +++++++++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) (limited to 'source/blender/windowmanager') diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index 07746af4b60..c57fe6d4ba1 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -578,6 +578,9 @@ const char *WM_operatortype_name(struct wmOperatorType *ot, struct PointerRNA *p char *WM_operatortype_description(struct bContext *C, struct wmOperatorType *ot, struct PointerRNA *properties); +char *WM_operatortype_description_or_name(struct bContext *C, + struct wmOperatorType *ot, + struct PointerRNA *properties); /* wm_operator_utils.c */ void WM_operator_type_modal_from_exec_for_object_edit_coords(struct wmOperatorType *ot); 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