diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-03-15 04:45:41 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-03-15 06:53:08 +0300 |
commit | 3400fe3ecee99cb6a74455943f2755e6f22ef047 (patch) | |
tree | d38e6d65b73f32d4b7685f2010e3f70df45994a0 /source/blender/editors/interface/interface_region_tooltip.c | |
parent | 388ff003e28bb8077d3dbd300e7e1f6beccea263 (diff) |
Tool System: split UI label from tool identifiers
Prepare for exposing tool registration to the Python API.
- Generated tools can use their own prefix so naming collisions
won't happen between hard coded & generated tools.
- Add-on authors can use the add-on name as a prefix.
Currently the names match, renaming will happen next.
Diffstat (limited to 'source/blender/editors/interface/interface_region_tooltip.c')
-rw-r--r-- | source/blender/editors/interface/interface_region_tooltip.c | 68 |
1 files changed, 49 insertions, 19 deletions
diff --git a/source/blender/editors/interface/interface_region_tooltip.c b/source/blender/editors/interface/interface_region_tooltip.c index 0da96cc09c6..629de557a2d 100644 --- a/source/blender/editors/interface/interface_region_tooltip.c +++ b/source/blender/editors/interface/interface_region_tooltip.c @@ -364,7 +364,7 @@ static uiTooltipData *ui_tooltip_data_from_tool(bContext *C, uiBut *but, bool is return NULL; } - if (!STREQ(but->optype->idname, "WM_OT_tool_set_by_name")) { + if (!STREQ(but->optype->idname, "WM_OT_tool_set_by_id")) { return NULL; } @@ -373,9 +373,9 @@ static uiTooltipData *ui_tooltip_data_from_tool(bContext *C, uiBut *but, bool is return NULL; } - char tool_name[MAX_NAME]; - RNA_string_get(but->opptr, "name", tool_name); - BLI_assert(tool_name[0] != '\0'); + char tool_id[MAX_NAME]; + RNA_string_get(but->opptr, "name", tool_id); + BLI_assert(tool_id[0] != '\0'); /* We have a tool, now extract the info. */ uiTooltipData *data = MEM_callocN(sizeof(uiTooltipData), "uiTooltipData"); @@ -387,13 +387,43 @@ static uiTooltipData *ui_tooltip_data_from_tool(bContext *C, uiBut *but, bool is /* Title (when icon-only). */ if (but->drawstr[0] == '\0') { - uiTooltipField *field = text_field_add( - data, &(uiTooltipFormat){ - .style = UI_TIP_STYLE_NORMAL, - .color_id = UI_TIP_LC_MAIN, - .is_pad = true, - }); - field->text = BLI_strdup(tool_name); + const char *expr_imports[] = {"bpy", "bl_ui", NULL}; + char expr[256]; + SNPRINTF( + expr, + "bl_ui.space_toolsystem_common.item_from_id(" + "bpy.context, " + "bpy.context.space_data.type, " + "'%s').label", + tool_id); + char *expr_result = NULL; + bool is_error = false; + if (BPY_execute_string_as_string(C, expr_imports, expr, true, &expr_result)) { + if (STREQ(expr_result, "")) { + MEM_freeN(expr_result); + expr_result = NULL; + } + } + else { + /* Note, this is an exceptional case, we could even remove it + * however there have been reports of tooltips failing, so keep it for now. */ + expr_result = BLI_strdup("Internal error!"); + is_error = true; + } + + if (expr_result != NULL) { + uiTooltipField *field = text_field_add( + data, &(uiTooltipFormat){ + .style = UI_TIP_STYLE_NORMAL, + .color_id = UI_TIP_LC_MAIN, + .is_pad = true, + }); + field->text = expr_result; + + if (UNLIKELY(is_error)) { + field->format.color_id = UI_TIP_LC_ALERT; + } + } } /* Tip. */ @@ -402,11 +432,11 @@ static uiTooltipData *ui_tooltip_data_from_tool(bContext *C, uiBut *but, bool is char expr[256]; SNPRINTF( expr, - "bl_ui.space_toolsystem_common.description_from_name(" + "bl_ui.space_toolsystem_common.description_from_id(" "bpy.context, " "bpy.context.space_data.type, " "'%s') + '.'", - tool_name); + tool_id); char *expr_result = NULL; bool is_error = false; @@ -461,7 +491,7 @@ static uiTooltipData *ui_tooltip_data_from_tool(bContext *C, uiBut *but, bool is const char *tool_attr = BKE_paint_get_tool_prop_id_from_paintmode(paint_mode); if (tool_attr != NULL) { const EnumPropertyItem *items = BKE_paint_get_tool_enum_from_paintmode(paint_mode); - const int i = RNA_enum_from_name(items, tool_name); + const int i = RNA_enum_from_name(items, tool_id); if (i != -1) { wmOperatorType *ot = WM_operatortype_find("paint.brush_select", true); PointerRNA op_props; @@ -504,9 +534,9 @@ static uiTooltipData *ui_tooltip_data_from_tool(bContext *C, uiBut *but, bool is wmKeyMap *keymap = (wmKeyMap *)expr_result; for (wmKeyMapItem *kmi = keymap->items.first; kmi; kmi = kmi->next) { if (STREQ(kmi->idname, but->optype->idname)) { - char tool_name_test[MAX_NAME]; - RNA_string_get(kmi->ptr, "name", tool_name_test); - if (STREQ(tool_name, tool_name_test)) { + char tool_id_test[MAX_NAME]; + RNA_string_get(kmi->ptr, "name", tool_id_test); + if (STREQ(tool_id, tool_id_test)) { char buf[128]; WM_keymap_item_to_string(kmi, false, buf, sizeof(buf)); shortcut = BLI_sprintfN("%s, %s", shortcut_toolbar, buf); @@ -543,12 +573,12 @@ static uiTooltipData *ui_tooltip_data_from_tool(bContext *C, uiBut *but, bool is SNPRINTF( expr, "getattr(" - "bl_ui.space_toolsystem_common.keymap_from_name(" + "bl_ui.space_toolsystem_common.keymap_from_id(" "bpy.context, " "bpy.context.space_data.type, " "'%s'), " "'as_pointer', lambda: 0)()", - tool_name); + tool_id); intptr_t expr_result = 0; if (BPY_execute_string_as_intptr(C, expr_imports, expr, true, &expr_result)) { |