[Bf-blender-cvs] [89ed6b12936] master: UI: simplify tool-tip logic for operators

Campbell Barton noreply at git.blender.org
Wed Sep 2 05:03:56 CEST 2020


Commit: 89ed6b12936bc2a89b18cf6dbd7b86e0fbc760d3
Author: Campbell Barton
Date:   Wed Sep 2 12:54:06 2020 +1000
Branches: master
https://developer.blender.org/rB89ed6b12936bc2a89b18cf6dbd7b86e0fbc760d3

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.

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

M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface.c
M	source/blender/editors/interface/interface_layout.c
M	source/blender/editors/interface/interface_region_tooltip.c
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/intern/wm_operator_type.c

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

diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 1fa9ed0b2c0..367f7965026 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -1863,6 +1863,8 @@ uiBlock *uiLayoutGetBlock(uiLayout *layout);
 void uiLayoutSetFunc(uiLayout *layout, uiMenuHandleFunc handlefunc, void *argv);
 void uiLayoutSetContextPointer(uiLayout *layout, const char *name, struct PointerRNA *ptr);
 void uiLayoutContextCopy(uiLayout *layout, struct bContextStore *context);
+struct wmOperatorType *UI_but_operatortype_get_from_enum_menu(struct uiBut *but,
+                                                              PropertyRNA **r_prop);
 struct MenuType *UI_but_menutype_get(uiBut *but);
 struct PanelType *UI_but_paneltype_get(uiBut *but);
 void UI_menutype_draw(struct bContext *C, struct MenuType *mt, struct uiLayout *layout);
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 9cede126890..c8526c16dba 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -6758,9 +6758,6 @@ void UI_but_string_info_get(bContext *C, uiBut *but, ...)
       else if (but->tip && but->tip[0]) {
         tmp = BLI_strdup(but->tip);
       }
-      else if (but->optype && but->optype->get_description) {
-        tmp = WM_operatortype_description(C, but->optype, but->opptr);
-      }
       else {
         type = BUT_GET_RNA_TIP; /* Fail-safe solution... */
       }
@@ -6805,13 +6802,10 @@ void UI_but_string_info_get(bContext *C, uiBut *but, ...)
       }
       else if (but->optype) {
         if (type == BUT_GET_RNA_LABEL) {
-          tmp = BLI_strdup(WM_operatortype_name(but->optype, NULL));
+          tmp = BLI_strdup(WM_operatortype_name(but->optype, but->opptr));
         }
         else {
-          const char *t = RNA_struct_ui_description(but->optype->srna);
-          if (t && t[0]) {
-            tmp = BLI_strdup(t);
-          }
+          tmp = WM_operatortype_description(C, but->optype, but->opptr);
         }
       }
       else if (ELEM(but->type, UI_BTYPE_MENU, UI_BTYPE_PULLDOWN, UI_BTYPE_POPOVER)) {
@@ -6833,6 +6827,18 @@ void UI_but_string_info_get(bContext *C, uiBut *but, ...)
           }
         }
 
+        if (tmp == NULL) {
+          wmOperatorType *ot = UI_but_operatortype_get_from_enum_menu(but, NULL);
+          if (ot) {
+            if (type == BUT_GET_RNA_LABEL) {
+              tmp = BLI_strdup(WM_operatortype_name(ot, NULL));
+            }
+            else {
+              tmp = WM_operatortype_description(C, ot, NULL);
+            }
+          }
+        }
+
         if (tmp == NULL) {
           PanelType *pt = UI_but_paneltype_get(but);
           if (pt) {
diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c
index f7955c15dc4..50355d350ac 100644
--- a/source/blender/editors/interface/interface_layout.c
+++ b/source/blender/editors/interface/interface_layout.c
@@ -3404,14 +3404,7 @@ void uiItemMenuEnumO_ptr(uiLayout *layout,
   BLI_strncpy(lvl->propname, propname, sizeof(lvl->propname));
   lvl->opcontext = layout->root->opcontext;
 
-  but = ui_item_menu(layout,
-                     name,
-                     icon,
-                     menu_item_enum_opname_menu,
-                     NULL,
-                     lvl,
-                     RNA_struct_ui_description(ot->srna),
-                     true);
+  but = ui_item_menu(layout, name, icon, menu_item_enum_opname_menu, NULL, lvl, NULL, true);
 
   /* add hotkey here, lower UI code can't detect it */
   if ((layout->root->block->flag & UI_BLOCK_LOOP) && (ot->prop && ot->invoke)) {
@@ -5500,6 +5493,24 @@ void uiLayoutSetContextFromBut(uiLayout *layout, uiBut *but)
   }
 }
 
+/* this is a bit of a hack but best keep it in one place at least */
+wmOperatorType *UI_but_operatortype_get_from_enum_menu(uiBut *but, PropertyRNA **r_prop)
+{
+  if (r_prop != NULL) {
+    *r_prop = NULL;
+  }
+
+  if (but->menu_create_func == menu_item_enum_opname_menu) {
+    MenuItemLevel *lvl = but->func_argN;
+    wmOperatorType *ot = WM_operatortype_find(lvl->opname, false);
+    if ((ot != NULL) && (r_prop != NULL)) {
+      *r_prop = RNA_struct_type_find_property(ot->srna, lvl->propname);
+    }
+    return ot;
+  }
+  return NULL;
+}
+
 /* this is a bit of a hack but best keep it in one place at least */
 MenuType *UI_but_menutype_get(uiBut *but)
 {
diff --git a/source/blender/editors/interface/interface_region_tooltip.c b/source/blender/editors/interface/interface_region_tooltip.c
index b3a65e024f3..f472c56e280 100644
--- a/source/blender/editors/interface/interface_region_tooltip.c
+++ b/source/blender/editors/interface/interface_region_tooltip.c
@@ -1075,7 +1075,7 @@ static uiTooltipData *ui_tooltip_data_from_gizmo(bContext *C, wmGizmo *gz)
                                 NULL;
       if (gzop != NULL) {
         /* Description */
-        char *info = WM_operatortype_description(C, gzop->type, &gzop->ptr);
+        char *info = WM_operatortype_description_or_name(C, gzop->type, &gzop->ptr);
 
         if (info != NULL) {
           char *text = info;
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;
+}
+
 /** \} */



More information about the Bf-blender-cvs mailing list