diff options
author | Walid Shouman <eng.walidshouman@gmail.com> | 2013-12-09 07:20:53 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-12-09 07:25:03 +0400 |
commit | c6620905a7c812aefac128f95960a38123b5af38 (patch) | |
tree | b4a038cf5314dea08e9fe919b38b15fb5a27bb5b /source/blender | |
parent | bac86a08259e23e6e1a8ff6c1ba4efdfe53a48fd (diff) |
Tooltips: abbreviate long python operator tooltips
Some tooltips would end up containing long string/array args spanning the screen.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/editors/interface/interface_regions.c | 3 | ||||
-rw-r--r-- | source/blender/windowmanager/WM_api.h | 1 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_operators.c | 41 |
3 files changed, 45 insertions, 0 deletions
diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c index 4566746b805..bb8da2810c8 100644 --- a/source/blender/editors/interface/interface_regions.c +++ b/source/blender/editors/interface/interface_regions.c @@ -541,6 +541,9 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but) str = WM_operator_pystring_ex(C, NULL, false, false, but->optype, opptr); + /* avoid overly verbose tips (eg, arrays of 20 layers), exact limit is arbitrary */ + WM_operator_pystring_abbreviate(str, 32); + /* operator info */ if ((U.flag & USER_TOOLTIPS_PYTHON) == 0) { BLI_snprintf(data->lines[data->totline], sizeof(data->lines[0]), TIP_("Python: %s"), str); diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index 26294dd5876..d8f558bf2c9 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -278,6 +278,7 @@ char *WM_operator_pystring_ex(struct bContext *C, struct wmOperator *op, struct wmOperatorType *ot, struct PointerRNA *opptr); char *WM_operator_pystring(struct bContext *C, struct wmOperator *op, const bool all_args, const bool macro_args); +bool WM_operator_pystring_abbreviate(char *str, int str_len_max); char *WM_prop_pystring_assign(struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA *prop, int index); void WM_operator_bl_idname(char *to, const char *from); void WM_operator_py_idname(char *to, const char *from); diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 91790f7d8d5..ac32d16a23b 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -611,6 +611,47 @@ char *WM_operator_pystring(bContext *C, wmOperator *op, return WM_operator_pystring_ex(C, op, all_args, macro_args, op->type, op->ptr); } + +/** + * \return true if the string was shortened + */ +bool WM_operator_pystring_abbreviate(char *str, int str_len_max) +{ + const int str_len = strlen(str); + const char *parens_start = strchr(str, '('); + + if (parens_start) { + const int parens_start_pos = parens_start - str; + const char *parens_end = strrchr(parens_start + 1, ')'); + + if (parens_end) { + const int parens_len = parens_end - parens_start; + + if (parens_len > str_len_max) { + const char *comma_first = strchr(parens_start, ','); + + /* truncate after the first comma */ + if (comma_first) { + const char end_str[] = " ... )"; + const int end_str_len = sizeof(end_str) - 1; + + /* leave a place for the first argument*/ + const int new_str_len = (comma_first - parens_start) + 1; + + if (str_len >= new_str_len + parens_start_pos + end_str_len + 1) { + /* append " ... )" to the string after the comma */ + memcpy(str + new_str_len + parens_start_pos, end_str, end_str_len + 1); + + return true; + } + } + } + } + } + + return false; +} + /* return NULL if no match is found */ #if 0 static char *wm_prop_pystring_from_context(bContext *C, PointerRNA *ptr, PropertyRNA *prop, int index) |