[Bf-blender-cvs] [594790d8a56] master: UI: add function to access the buttons text without it's shortcut

Campbell Barton noreply at git.blender.org
Thu Aug 19 05:07:42 CEST 2021


Commit: 594790d8a56777c4436b4da2165113d59d57283a
Author: Campbell Barton
Date:   Thu Aug 19 12:49:10 2021 +1000
Branches: master
https://developer.blender.org/rB594790d8a56777c4436b4da2165113d59d57283a

UI: add function to access the buttons text without it's shortcut

===================================================================

M	source/blender/editors/interface/interface_context_menu.c
M	source/blender/editors/interface/interface_intern.h
M	source/blender/editors/interface/interface_query.c

===================================================================

diff --git a/source/blender/editors/interface/interface_context_menu.c b/source/blender/editors/interface/interface_context_menu.c
index 8ace057891d..b953d88c896 100644
--- a/source/blender/editors/interface/interface_context_menu.c
+++ b/source/blender/editors/interface/interface_context_menu.c
@@ -373,13 +373,7 @@ static void ui_but_user_menu_add(bContext *C, uiBut *but, bUserMenu *um)
   BLI_assert(ui_but_is_user_menu_compatible(C, but));
 
   char drawstr[sizeof(but->drawstr)];
-  STRNCPY(drawstr, but->drawstr);
-  if (but->flag & UI_BUT_HAS_SEP_CHAR) {
-    char *sep = strrchr(drawstr, UI_SEP_CHAR);
-    if (sep) {
-      *sep = '\0';
-    }
-  }
+  ui_but_drawstr_without_sep_char(but, drawstr, sizeof(drawstr));
 
   MenuType *mt = NULL;
   if (but->optype) {
diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h
index 6b0b8e8df8f..d61104f094e 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -1177,6 +1177,8 @@ uiBut *ui_list_find_mouse_over_ex(const struct ARegion *region,
 
 bool ui_but_contains_password(const uiBut *but) ATTR_WARN_UNUSED_RESULT;
 
+size_t ui_but_drawstr_without_sep_char(const uiBut *but, char *str, size_t str_maxlen)
+    ATTR_NONNULL(1, 2);
 size_t ui_but_drawstr_len_without_sep_char(const uiBut *but);
 size_t ui_but_tip_len_only_first_line(const uiBut *but);
 
diff --git a/source/blender/editors/interface/interface_query.c b/source/blender/editors/interface/interface_query.c
index 8534c95b6fd..09429bb6df5 100644
--- a/source/blender/editors/interface/interface_query.c
+++ b/source/blender/editors/interface/interface_query.c
@@ -23,6 +23,7 @@
 #include "BLI_listbase.h"
 #include "BLI_math.h"
 #include "BLI_rect.h"
+#include "BLI_string.h"
 #include "BLI_utildefines.h"
 
 #include "DNA_screen_types.h"
@@ -553,6 +554,12 @@ size_t ui_but_drawstr_len_without_sep_char(const uiBut *but)
   return strlen(but->drawstr);
 }
 
+size_t ui_but_drawstr_without_sep_char(const uiBut *but, char *str, size_t str_maxlen)
+{
+  size_t str_len_clip = ui_but_drawstr_len_without_sep_char(but);
+  return BLI_strncpy_rlen(str, but->drawstr, min_zz(str_len_clip + 1, str_maxlen));
+}
+
 size_t ui_but_tip_len_only_first_line(const uiBut *but)
 {
   if (but->tip == NULL) {



More information about the Bf-blender-cvs mailing list