Fix status bar and keymap editor showing Call Menu instead of menu name
authorBrecht Van Lommel <brechtvanlommel@gmail.com>
Tue, 4 Jun 2019 13:50:15 +0000 (15:50 +0200)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Tue, 4 Jun 2019 16:26:02 +0000 (18:26 +0200)
17 files changed:
source/blender/editors/animation/keyframing.c
source/blender/editors/interface/interface.c
source/blender/editors/interface/interface_layout.c
source/blender/editors/interface/interface_region_hud.c
source/blender/editors/interface/interface_templates.c
source/blender/editors/screen/screen_ops.c
source/blender/editors/space_file/file_panels.c
source/blender/editors/space_file/filesel.c
source/blender/editors/space_outliner/outliner_tools.c
source/blender/editors/undo/ed_undo.c
source/blender/makesrna/intern/rna_wm.c
source/blender/windowmanager/WM_api.h
source/blender/windowmanager/WM_types.h
source/blender/windowmanager/intern/wm_dragdrop.c
source/blender/windowmanager/intern/wm_event_system.c
source/blender/windowmanager/intern/wm_operator_type.c
source/blender/windowmanager/intern/wm_operators.c

index 2dc17c5c39709731bc3a61e26c27d9a6fde32b88..89d853889812e499197136dc8f6fc2104c089b7a 100644 (file)
@@ -1956,7 +1956,7 @@ static int insert_key_menu_invoke(bContext *C, wmOperator *op, const wmEvent *UN
     uiLayout *layout;
 
     /* call the menu, which will call this operator again, hence the canceled */
-    pup = UI_popup_menu_begin(C, RNA_struct_ui_name(op->type->srna), ICON_NONE);
+    pup = UI_popup_menu_begin(C, WM_operatortype_name(op->type, op->ptr), ICON_NONE);
     layout = UI_popup_menu_layout(pup);
     uiItemsEnumO(layout, "ANIM_OT_keyframe_insert_menu", "type");
     UI_popup_menu_end(C, pup);
index 931a4faa1c031fdcffa0b3f8bf60f579d37e1c0a..2154ac4a7f6aa248bc767cd959867be33cf289b3 100644 (file)
@@ -4241,7 +4241,7 @@ static uiBut *ui_def_but_operator_ptr(uiBlock *block,
 
   if (!str) {
     if (ot && ot->srna) {
-      str = RNA_struct_ui_name(ot->srna);
+      str = WM_operatortype_name(ot, NULL);
     }
     else {
       str = "";
@@ -6392,7 +6392,7 @@ void UI_but_string_info_get(bContext *C, uiBut *but, ...)
       }
       else if (but->optype) {
         if (type == BUT_GET_RNA_LABEL) {
-          tmp = BLI_strdup(RNA_struct_ui_name(but->optype->srna));
+          tmp = BLI_strdup(WM_operatortype_name(but->optype, NULL));
         }
         else {
           const char *t = RNA_struct_ui_description(but->optype->srna);
index b89767171ab5921e6c4434b9ea76507a0e97c688..d4d7af3a374e4acdc24293e1e85fafe2a696abf5 100644 (file)
@@ -1143,7 +1143,7 @@ static uiBut *uiItemFullO_ptr_ex(uiLayout *layout,
 
   if (!name) {
     if (ot && ot->srna && (flag & UI_ITEM_R_ICON_ONLY) == 0) {
-      name = RNA_struct_ui_name(ot->srna);
+      name = WM_operatortype_name(ot, NULL);
     }
     else {
       name = "";
@@ -3126,7 +3126,7 @@ void uiItemMenuEnumO_ptr(uiLayout *layout,
   BLI_assert(ot->srna != NULL);
 
   if (name == NULL) {
-    name = RNA_struct_ui_name(ot->srna);
+    name = WM_operatortype_name(ot, NULL);
   }
 
   if (layout->root->type == UI_LAYOUT_MENU && !icon) {
index 362a1c8a22c94155c5e1602999e0f8e09784783a..6d1b2baeff993e494a5ef16eb8d68ac88c84fbbd 100644 (file)
@@ -92,7 +92,7 @@ static bool hud_panel_operator_redo_poll(const bContext *C, PanelType *UNUSED(pt
 static void hud_panel_operator_redo_draw_header(const bContext *C, Panel *pa)
 {
   wmOperator *op = WM_operator_last_redo(C);
-  BLI_strncpy(pa->drawname, RNA_struct_ui_name(op->type->srna), sizeof(pa->drawname));
+  BLI_strncpy(pa->drawname, WM_operatortype_name(op->type, op->ptr), sizeof(pa->drawname));
 }
 
 static void hud_panel_operator_redo_draw(const bContext *C, Panel *pa)
index b1d404e8ab4b0da5dbcc5417007794b0d56382b1..5d25c778de1797cb0b457729b4b708e20231262a 100644 (file)
@@ -2355,7 +2355,7 @@ void uiTemplateOperatorRedoProperties(uiLayout *layout, const bContext *C)
   /* Repeat button with operator name as text. */
   uiItemFullO(layout,
               "SCREEN_OT_repeat_last",
-              RNA_struct_ui_name(op->type->srna),
+              WM_operatortype_name(op->type, op->ptr),
               ICON_NONE,
               NULL,
               WM_OP_INVOKE_DEFAULT,
@@ -5916,7 +5916,7 @@ eAutoPropButsReturn uiTemplateOperatorPropertyButs(const bContext *C,
   }
 
   if (flag & UI_TEMPLATE_OP_PROPS_SHOW_TITLE) {
-    uiItemL(layout, RNA_struct_ui_name(op->type->srna), ICON_NONE);
+    uiItemL(layout, WM_operatortype_name(op->type, op->ptr), ICON_NONE);
   }
 
   /* menu */
index 773f596ec79f01eecfd48c3eeaac534070a058dc..7c03ba889a7fc970153332380d75adb6c7a135f5 100644 (file)
@@ -3457,7 +3457,7 @@ static int screen_area_options_invoke(bContext *C, wmOperator *op, const wmEvent
     return OPERATOR_CANCELLED;
   }
 
-  pup = UI_popup_menu_begin(C, RNA_struct_ui_name(op->type->srna), ICON_NONE);
+  pup = UI_popup_menu_begin(C, WM_operatortype_name(op->type, op->ptr), ICON_NONE);
   layout = UI_popup_menu_layout(pup);
 
   uiItemFullO(
@@ -3596,13 +3596,13 @@ static int repeat_history_invoke(bContext *C, wmOperator *op, const wmEvent *UNU
     return OPERATOR_CANCELLED;
   }
 
-  pup = UI_popup_menu_begin(C, RNA_struct_ui_name(op->type->srna), ICON_NONE);
+  pup = UI_popup_menu_begin(C, WM_operatortype_name(op->type, op->ptr), ICON_NONE);
   layout = UI_popup_menu_layout(pup);
 
   for (i = items - 1, lastop = wm->operators.last; lastop; lastop = lastop->prev, i--) {
     if ((lastop->type->flag & OPTYPE_REGISTER) && WM_operator_repeat_check(C, lastop)) {
       uiItemIntO(
-          layout, RNA_struct_ui_name(lastop->type->srna), ICON_NONE, op->type->idname, "index", i);
+          layout, WM_operatortype_name(lastop->type, lastop->ptr), ICON_NONE, op->type->idname, "index", i);
     }
   }
 
index 023dff704c7d998dbaebbba2590983d1b42b40c2..d9a6e70121ffa3483e0860b1cbef2bde0b4d9b5b 100644 (file)
@@ -62,7 +62,7 @@ static void file_panel_operator_header(const bContext *C, Panel *pa)
   SpaceFile *sfile = CTX_wm_space_file(C);
   wmOperator *op = sfile->op;
 
-  BLI_strncpy(pa->drawname, RNA_struct_ui_name(op->type->srna), sizeof(pa->drawname));
+  BLI_strncpy(pa->drawname, WM_operatortype_name(op->type, op->ptr), sizeof(pa->drawname));
 }
 
 static void file_panel_operator(const bContext *C, Panel *pa)
index e5f19f0164dc87ff02d1e59f57adf8ac5f33ef77..c82e140e1fe5bb608068f8c6931f47d2135a5ba1 100644 (file)
@@ -112,7 +112,7 @@ short ED_fileselect_set_params(SpaceFile *sfile)
     const bool is_directory = (RNA_struct_find_property(op->ptr, "directory") != NULL);
     const bool is_relative_path = (RNA_struct_find_property(op->ptr, "relative_path") != NULL);
 
-    BLI_strncpy_utf8(params->title, RNA_struct_ui_name(op->type->srna), sizeof(params->title));
+    BLI_strncpy_utf8(params->title, WM_operatortype_name(op->type, op->ptr), sizeof(params->title));
 
     if ((prop = RNA_struct_find_property(op->ptr, "filemode"))) {
       params->type = RNA_property_int_get(op->ptr, prop);
index 0f9efb0d2e13256a508ebc427893f456ac7da412..7e5638e48ea377b7af7f21d0d4d0f746e58f0cb7 100644 (file)
@@ -2144,7 +2144,7 @@ void OUTLINER_OT_data_operation(wmOperatorType *ot)
 static int outliner_operator_menu(bContext *C, const char *opname)
 {
   wmOperatorType *ot = WM_operatortype_find(opname, false);
-  uiPopupMenu *pup = UI_popup_menu_begin(C, RNA_struct_ui_name(ot->srna), ICON_NONE);
+  uiPopupMenu *pup = UI_popup_menu_begin(C, WM_operatortype_name(ot, NULL), ICON_NONE);
   uiLayout *layout = UI_popup_menu_layout(pup);
 
   /* set this so the default execution context is the same as submenus */
index ccbe12b4a9326d19d6a5d8219fedf5acc2f94476..734cdc424d9e123f090bd1fc5314cf8c3a4e5d3e 100644 (file)
@@ -591,7 +591,7 @@ static int undo_history_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSE
     const EnumPropertyItem *item = rna_undo_itemf(C, &totitem);
 
     if (totitem > 0) {
-      uiPopupMenu *pup = UI_popup_menu_begin(C, RNA_struct_ui_name(op->type->srna), ICON_NONE);
+      uiPopupMenu *pup = UI_popup_menu_begin(C, WM_operatortype_name(op->type, op->ptr), ICON_NONE);
       uiLayout *layout = UI_popup_menu_layout(pup);
       uiLayout *split = uiLayoutSplit(layout, 0.0f, false);
       uiLayout *column = NULL;
index 3c707142951b0c6348415b22478f9778f2754a1a..72c23f29b31297dcace41bb2586d96fbfa729a93 100644 (file)
@@ -1203,14 +1203,14 @@ static void rna_wmKeyMapItem_name_get(PointerRNA *ptr, char *value)
 {
   wmKeyMapItem *kmi = ptr->data;
   wmOperatorType *ot = WM_operatortype_find(kmi->idname, 1);
-  strcpy(value, ot ? RNA_struct_ui_name(ot->srna) : kmi->idname);
+  strcpy(value, ot ? WM_operatortype_name(ot, kmi->ptr) : kmi->idname);
 }
 
 static int rna_wmKeyMapItem_name_length(PointerRNA *ptr)
 {
   wmKeyMapItem *kmi = ptr->data;
   wmOperatorType *ot = WM_operatortype_find(kmi->idname, 1);
-  return strlen(ot ? RNA_struct_ui_name(ot->srna) : kmi->idname);
+  return strlen(ot ? WM_operatortype_name(ot, kmi->ptr) : kmi->idname);
 }
 
 static bool rna_KeyMapItem_userdefined_get(PointerRNA *ptr)
index 558eb97c54baabd31aeb6f4bb382eb74c00d354c..dfea0cf25faa7cdfd1c04b1709ce6234c5983193 100644 (file)
@@ -537,6 +537,8 @@ struct wmOperatorType *WM_operatortype_append_macro(const char *idname,
 struct wmOperatorTypeMacro *WM_operatortype_macro_define(struct wmOperatorType *ot,
                                                          const char *idname);
 
+const char *WM_operatortype_name(struct wmOperatorType *ot, struct PointerRNA *properties);
+
 /* wm_uilist_type.c */
 void WM_uilisttype_init(void);
 struct uiListType *WM_uilisttype_find(const char *idname, bool quiet);
index 20bb5935c8e3367bd7aec097d08534ac980c1e40..c725b9f51c9adc0ae8f4c6c843c53e733b194802 100644 (file)
@@ -648,6 +648,10 @@ typedef struct wmOperatorType {
   /* optional panel for redo and repeat, autogenerated if not set */
   void (*ui)(struct bContext *, struct wmOperator *);
 
+  /* Return a different name to use in the user interface, based on property values.
+   * The returned string does not need to be freed. */
+  const char *(*get_name)(struct wmOperatorType *, struct PointerRNA *);
+
   /* rna for properties */
   struct StructRNA *srna;
 
index e4ecf7e6e94c438ba8356aedf1cc152dbf867a17..6b3bd1ea24ea8bce62ef4b496a09f0ee9be85c8d 100644 (file)
@@ -208,7 +208,7 @@ static const char *dropbox_active(bContext *C,
           if (drop->poll(C, drag, event, &tooltip)) {
             /* XXX Doing translation here might not be ideal, but later we have no more
              *     access to ot (and hence op context)... */
-            return (tooltip) ? tooltip : RNA_struct_ui_name(drop->ot->srna);
+            return (tooltip) ? tooltip : WM_operatortype_name(drop->ot, drop->ptr);
           }
         }
       }
index 987c71398eed8551880f827c340b7c7f047fc888..f688f5205729891fde436e9a23af82347757fe39 100644 (file)
@@ -5099,7 +5099,8 @@ void WM_window_cursor_keymap_status_refresh(bContext *C, wmWindow *win)
     }
     if (kmi) {
       wmOperatorType *ot = WM_operatortype_find(kmi->idname, 0);
-      STRNCPY(cd->text[button_index][type_index], ot ? ot->name : kmi->idname);
+      const char *name = (ot) ? WM_operatortype_name(ot, kmi->ptr) : kmi->idname;
+      STRNCPY(cd->text[button_index][type_index], name);
     }
   }
 
index 69f09162c749f3a1dbf20847f37f8b5801328a2e..1cec984810464f7906fa1f9e7b356be54ae2f0b6 100644 (file)
@@ -584,4 +584,14 @@ static void wm_operatortype_free_macro(wmOperatorType *ot)
   BLI_freelistN(&ot->macro);
 }
 
+const char *WM_operatortype_name(struct wmOperatorType *ot, struct PointerRNA *properties)
+{
+  if (ot->get_name && properties) {
+    return ot->get_name(ot, properties);
+  }
+  else {
+    return RNA_struct_ui_name(ot->srna);
+  }
+}
+
 /** \} */
index 4a99c2de6e776528b9848692d25ea7506c99e504..31205ab11f4e7ca56f3f71f5fdc4f5f5ec6580ce 100644 (file)
@@ -753,7 +753,7 @@ int WM_menu_invoke_ex(bContext *C, wmOperator *op, int opcontext)
     return retval;
   }
   else {
-    pup = UI_popup_menu_begin(C, RNA_struct_ui_name(op->type->srna), ICON_NONE);
+    pup = UI_popup_menu_begin(C, WM_operatortype_name(op->type, op->ptr), ICON_NONE);
     layout = UI_popup_menu_layout(pup);
     /* set this so the default execution context is the same as submenus */
     uiLayoutSetOperatorContext(layout, opcontext);
@@ -805,7 +805,7 @@ static uiBlock *wm_enum_search_menu(bContext *C, ARegion *ar, void *arg)
   uiDefBut(block,
            UI_BTYPE_LABEL,
            0,
-           RNA_struct_ui_name(op->type->srna),
+           WM_operatortype_name(op->type, op->ptr),
            10,
            10,
            UI_searchbox_size_x(),
@@ -1843,6 +1843,14 @@ static int wm_call_menu_exec(bContext *C, wmOperator *op)
   return UI_popup_menu_invoke(C, idname, op->reports);
 }
 
+static const char *wm_call_menu_get_name(wmOperatorType *ot, PointerRNA *ptr)
+{
+  char idname[BKE_ST_MAXNAME];
+  RNA_string_get(ptr, "name", idname);
+  MenuType *mt = WM_menutype_find(idname, true);
+  return (mt) ? mt->label : ot->name;
+}
+
 static void WM_OT_call_menu(wmOperatorType *ot)
 {
   ot->name = "Call Menu";
@@ -1851,6 +1859,7 @@ static void WM_OT_call_menu(wmOperatorType *ot)
 
   ot->exec = wm_call_menu_exec;
   ot->poll = WM_operator_winactive;
+  ot->get_name = wm_call_menu_get_name;
 
   ot->flag = OPTYPE_INTERNAL;
 
@@ -1882,6 +1891,7 @@ static void WM_OT_call_menu_pie(wmOperatorType *ot)
   ot->invoke = wm_call_pie_menu_invoke;
   ot->exec = wm_call_pie_menu_exec;
   ot->poll = WM_operator_winactive;
+  ot->get_name = wm_call_menu_get_name;
 
   ot->flag = OPTYPE_INTERNAL;
 
@@ -1897,6 +1907,14 @@ static int wm_call_panel_exec(bContext *C, wmOperator *op)
   return UI_popover_panel_invoke(C, idname, keep_open, op->reports);
 }
 
+static const char *wm_call_panel_get_name(wmOperatorType *ot, PointerRNA *ptr)
+{
+  char idname[BKE_ST_MAXNAME];
+  RNA_string_get(ptr, "name", idname);
+  PanelType *pt = WM_paneltype_find(idname, true);
+  return (pt) ? pt->label : ot->name;
+}
+
 static void WM_OT_call_panel(wmOperatorType *ot)
 {
   ot->name = "Call Panel";
@@ -1905,6 +1923,7 @@ static void WM_OT_call_panel(wmOperatorType *ot)
 
   ot->exec = wm_call_panel_exec;
   ot->poll = WM_operator_winactive;
+  ot->get_name = wm_call_panel_get_name;
 
   ot->flag = OPTYPE_INTERNAL;