Fix #35262: assiging shortcuts from e.g. delete or selection mode menus did not
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Fri, 10 May 2013 23:41:41 +0000 (23:41 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Fri, 10 May 2013 23:41:41 +0000 (23:41 +0000)
work anymore. This was due to a bugfix to show missing shortcut keys for e.g. the
mesh > vertices > separate menu. Both should work now.

source/blender/editors/include/UI_interface.h
source/blender/editors/interface/interface.c
source/blender/editors/interface/interface_layout.c
source/blender/editors/interface/interface_templates.c
source/blender/editors/space_logic/logic_window.c
source/blender/makesrna/intern/rna_ui_api.c
source/blender/windowmanager/WM_keymap.h
source/blender/windowmanager/intern/wm_keymap.c

index 77bdd85d9fbd7a59e99a9889cbba12fc546ac288..a97f1689db960a99c24b198378ada2eafc341825 100644 (file)
@@ -892,7 +892,7 @@ void uiItemV(uiLayout *layout, const char *name, int icon, int argval); /* value
 void uiItemS(uiLayout *layout); /* separator */
 
 void uiItemMenuF(uiLayout *layout, const char *name, int icon, uiMenuCreateFunc func, void *arg);
-void uiItemMenuEnumO(uiLayout *layout, const char *opname, const char *propname, const char *name, int icon);
+void uiItemMenuEnumO(uiLayout *layout, struct bContext *C, const char *opname, const char *propname, const char *name, int icon);
 void uiItemMenuEnumR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, const char *name, int icon);
 
 /* UI Operators */
index d5c359d022ea8b3543d109f16f65de9e347038d2..87281ab78193ca11d3f6b16f116d430ad1e4ec32 100644 (file)
@@ -878,7 +878,7 @@ static void ui_menu_block_set_keymaps(const bContext *C, uiBlock *block)
                if (but->optype) {
                        IDProperty *prop = (but->opptr) ? but->opptr->data : NULL;
 
-                       if (WM_key_event_operator_string(C, but->optype->idname, but->opcontext, prop, TRUE,
+                       if (WM_key_event_operator_string(C, but->optype->idname, but->opcontext, prop, true,
                                                         buf, sizeof(buf)))
                        {
                                ui_but_add_shortcut(but, buf, FALSE);
@@ -895,7 +895,7 @@ static void ui_menu_block_set_keymaps(const bContext *C, uiBlock *block)
 
                        IDP_AssignString(prop_menu_name, mt->idname, sizeof(mt->idname));
 
-                       if (WM_key_event_operator_string(C, "WM_OT_call_menu", WM_OP_INVOKE_REGION_WIN, prop_menu, FALSE,
+                       if (WM_key_event_operator_string(C, "WM_OT_call_menu", WM_OP_INVOKE_REGION_WIN, prop_menu, true,
                                                         buf, sizeof(buf)))
                        {
                                ui_but_add_shortcut(but, buf, FALSE);
@@ -4093,7 +4093,7 @@ void uiButGetStrInfo(bContext *C, uiBut *but, ...)
                                IDProperty *prop = (but->opptr) ? but->opptr->data : NULL;
                                char buf[512];
 
-                               if (WM_key_event_operator_string(C, but->optype->idname, but->opcontext, prop, TRUE,
+                               if (WM_key_event_operator_string(C, but->optype->idname, but->opcontext, prop, true,
                                                                 buf, sizeof(buf)))
                                {
                                        tmp = BLI_strdup(buf);
index 2bde6aa607f7c23d9c47dcd60c9b654f4b2ab0a4..0813e4cba074d907692298ab421d8a57c711718d 100644 (file)
@@ -1681,10 +1681,11 @@ static void menu_item_enum_opname_menu(bContext *UNUSED(C), uiLayout *layout, vo
        uiItemsEnumO(layout, lvl->opname, lvl->propname);
 }
 
-void uiItemMenuEnumO(uiLayout *layout, const char *opname, const char *propname, const char *name, int icon)
+void uiItemMenuEnumO(uiLayout *layout, bContext *C, const char *opname, const char *propname, const char *name, int icon)
 {
        wmOperatorType *ot = WM_operatortype_find(opname, 0); /* print error next */
        MenuItemLevel *lvl;
+       char namestr[UI_MAX_NAME_STR], keybuf[128];
 
        UI_OPERATOR_ERROR_RET(ot, opname, return );
 
@@ -1694,8 +1695,11 @@ void uiItemMenuEnumO(uiLayout *layout, const char *opname, const char *propname,
                return;
        }
 
-       if (!name)
-               name = RNA_struct_ui_name(ot->srna);
+       if (name)
+               BLI_strncpy(namestr, name, sizeof(namestr));
+       else
+               BLI_strncpy(namestr, RNA_struct_ui_name(ot->srna), sizeof(namestr));
+
        if (layout->root->type == UI_LAYOUT_MENU && !icon)
                icon = ICON_BLANK1;
 
@@ -1704,7 +1708,16 @@ void uiItemMenuEnumO(uiLayout *layout, const char *opname, const char *propname,
        BLI_strncpy(lvl->propname, propname, sizeof(lvl->propname));
        lvl->opcontext = layout->root->opcontext;
 
-       ui_item_menu(layout, name, icon, menu_item_enum_opname_menu, NULL, lvl, RNA_struct_ui_description(ot->srna));
+       /* add hotkey here, lower UI code can't detect it */
+       if(layout->root->block->flag & UI_BLOCK_LOOP) {
+               if (ot->prop && WM_key_event_operator_string(C, ot->idname,
+                       layout->root->opcontext, NULL, false, keybuf, sizeof(keybuf))) {
+                       strncat(namestr, "|", sizeof(namestr)-1);
+                       strncat(namestr, keybuf, sizeof(namestr)-1);
+               }
+       }
+
+       ui_item_menu(layout, namestr, icon, menu_item_enum_opname_menu, NULL, lvl, RNA_struct_ui_description(ot->srna));
 }
 
 static void menu_item_enum_rna_menu(bContext *UNUSED(C), uiLayout *layout, void *arg)
index 38b8cd9312c00b8ce6e5bcb05644906ae39d805e..b87c067a1abefb0f307e34642e57373589b8922a 100644 (file)
@@ -2768,7 +2768,7 @@ static void operator_search_cb(const bContext *C, void *UNUSED(arg), const char
                                
                                /* check for hotkey */
                                if (len < sizeof(name) - 6) {
-                                       if (WM_key_event_operator_string(C, ot->idname, WM_OP_EXEC_DEFAULT, NULL, TRUE,
+                                       if (WM_key_event_operator_string(C, ot->idname, WM_OP_EXEC_DEFAULT, NULL, true,
                                                                         &name[len + 1], sizeof(name) - len - 1))
                                        {
                                                name[len] = '|';
index 578006115a5c5192bc159d06d8e24af520069f4b..ce8ee25eef0be6bc00b425b3a401e7ff8fa51192 100644 (file)
@@ -2329,7 +2329,7 @@ void logic_buttons(bContext *C, ARegion *ar)
 
                RNA_pointer_create((ID *)ob, &RNA_Object, ob, &object_ptr);
                uiLayoutSetContextPointer(row, "object", &object_ptr);
-               uiItemMenuEnumO(row, "LOGIC_OT_controller_add", "type", IFACE_("Add Controller"), ICON_NONE);
+               uiItemMenuEnumO(row, C, "LOGIC_OT_controller_add", "type", IFACE_("Add Controller"), ICON_NONE);
 
                if (RNA_boolean_get(&settings_ptr, "show_state_panel")) {
 
@@ -2426,7 +2426,7 @@ void logic_buttons(bContext *C, ARegion *ar)
 
                RNA_pointer_create((ID *)ob, &RNA_Object, ob, &object_ptr);
                uiLayoutSetContextPointer(row, "object", &object_ptr);
-               uiItemMenuEnumO(row, "LOGIC_OT_sensor_add", "type", IFACE_("Add Sensor"), ICON_NONE);
+               uiItemMenuEnumO(row, C, "LOGIC_OT_sensor_add", "type", IFACE_("Add Sensor"), ICON_NONE);
                
                if ((ob->scaflag & OB_SHOWSENS) == 0) continue;
                
@@ -2497,7 +2497,7 @@ void logic_buttons(bContext *C, ARegion *ar)
 
                RNA_pointer_create((ID *)ob, &RNA_Object, ob, &object_ptr);
                uiLayoutSetContextPointer(row, "object", &object_ptr);
-               uiItemMenuEnumO(row, "LOGIC_OT_actuator_add", "type", IFACE_("Add Actuator"), ICON_NONE);
+               uiItemMenuEnumO(row, C, "LOGIC_OT_actuator_add", "type", IFACE_("Add Actuator"), ICON_NONE);
 
                if ((ob->scaflag & OB_SHOWACT) == 0) continue;
                
index c5c8789001a0f0e6534e87892546eb992d582b34..2d89317b4aec08a65bd9aa909283fab2dcb0efd2 100644 (file)
@@ -194,7 +194,7 @@ static PointerRNA rna_uiItemO(uiLayout *layout, const char *opname, const char *
        return uiItemFullO_ptr(layout, ot, name, icon, NULL, uiLayoutGetOperatorContext(layout), flag);
 }
 
-static void rna_uiItemMenuEnumO(uiLayout *layout, const char *opname, const char *propname, const char *name,
+static void rna_uiItemMenuEnumO(uiLayout *layout, bContext *C, const char *opname, const char *propname, const char *name,
                                 const char *text_ctxt, int translate, int icon)
 {
        wmOperatorType *ot = WM_operatortype_find(opname, 0); /* print error next */
@@ -208,7 +208,7 @@ static void rna_uiItemMenuEnumO(uiLayout *layout, const char *opname, const char
        name = rna_translate_ui_text(name, text_ctxt, ot->srna, NULL, translate);
 
        /* XXX This will search operator again :( */
-       uiItemMenuEnumO(layout, opname, propname, name, icon);
+       uiItemMenuEnumO(layout, C, opname, propname, name, icon);
 }
 
 static void rna_uiItemL(uiLayout *layout, const char *name, const char *text_ctxt, int translate,
@@ -549,6 +549,7 @@ void RNA_api_ui_layout(StructRNA *srna)
        RNA_def_property_flag(parm, PROP_REQUIRED);
 
        func = RNA_def_function(srna, "operator_menu_enum", "rna_uiItemMenuEnumO");
+       RNA_def_function_flag(func, FUNC_USE_CONTEXT);
        api_ui_item_op(func); /* cant use api_ui_item_op_common because property must come right after */
        parm = RNA_def_string(func, "property", "", 0, "", "Identifier of property in operator");
        RNA_def_property_flag(parm, PROP_REQUIRED);
index 8d37db000c0841883d69b930ca8c27bbd9088b0c..cebafcea12df35f81b3aa2e6ca51afdf42397543 100644 (file)
@@ -95,7 +95,7 @@ void          WM_keymap_restore_item_to_default(struct bContext *C, struct wmKeyMap *key
 
 const char     *WM_key_event_string(short type);
 int                    WM_key_event_operator_id(const struct bContext *C, const char *opname, int opcontext, struct IDProperty *properties, int hotkey, struct wmKeyMap **keymap_r);
-char           *WM_key_event_operator_string(const struct bContext *C, const char *opname, int opcontext, struct IDProperty *properties, const bool sloppy, char *str, int len);
+char           *WM_key_event_operator_string(const struct bContext *C, const char *opname, int opcontext, struct IDProperty *properties, const bool strict, char *str, int len);
 
 #ifdef __cplusplus
 }
index d5b6d2cd0c8f7cb0c303613448627f97bb97ffa7..4a0e8270bc97db77d566429f91d9e53ac17729ed 100644 (file)
@@ -863,14 +863,9 @@ static wmKeyMapItem *wm_keymap_item_find_handlers(
                                                }
 #endif
 
-                                               if (kmi->ptr) {
-                                                       PointerRNA properties_ptr;
-                                                       RNA_pointer_create(NULL, kmi->ptr->type, properties, &properties_ptr);
-
-                                                       if (RNA_struct_equals(&properties_ptr, kmi->ptr, is_strict)) {
-                                                               if (keymap_r) *keymap_r = keymap;
-                                                               return kmi;
-                                                       }
+                                               if (kmi->ptr && IDP_EqualsProperties_ex(properties, kmi->ptr->data, is_strict)) {
+                                                       if (keymap_r) *keymap_r = keymap;
+                                                       return kmi;
                                                }
                                        }
                                        else {
@@ -938,9 +933,9 @@ static wmKeyMapItem *wm_keymap_item_find_props(
 
 static wmKeyMapItem *wm_keymap_item_find(
         const bContext *C, const char *opname, int opcontext,
-        IDProperty *properties, const short hotkey, const short UNUSED(sloppy), wmKeyMap **keymap_r)
+        IDProperty *properties, const short hotkey, const bool strict, wmKeyMap **keymap_r)
 {
-       wmKeyMapItem *found = wm_keymap_item_find_props(C, opname, opcontext, properties, 1, hotkey, keymap_r);
+       wmKeyMapItem *found = wm_keymap_item_find_props(C, opname, opcontext, properties, strict, hotkey, keymap_r);
 
        if (!found && properties) {
                wmOperatorType *ot = WM_operatortype_find(opname, TRUE);
@@ -953,14 +948,14 @@ static wmKeyMapItem *wm_keymap_item_find(
                        RNA_pointer_create(NULL, ot->srna, properties_default, &opptr);
 
                        if (WM_operator_properties_default(&opptr, true) ||
-                           (ot->prop && RNA_property_is_set(&opptr, ot->prop)))
+                           (!strict && ot->prop && RNA_property_is_set(&opptr, ot->prop)))
                        {
                                /* for operator that has enum menu, unset it so it always matches */
-                               if (ot->prop) {
+                               if (!strict && ot->prop) {
                                        RNA_property_unset(&opptr, ot->prop);
                                }
 
-                               found = wm_keymap_item_find_props(C, opname, opcontext, properties_default, 0, hotkey, keymap_r);
+                               found = wm_keymap_item_find_props(C, opname, opcontext, properties_default, false, hotkey, keymap_r);
                        }
 
                        IDP_FreeProperty(properties_default);
@@ -973,9 +968,9 @@ static wmKeyMapItem *wm_keymap_item_find(
 
 char *WM_key_event_operator_string(
         const bContext *C, const char *opname, int opcontext,
-        IDProperty *properties, const bool sloppy, char *str, int len)
+        IDProperty *properties, const bool strict, char *str, int len)
 {
-       wmKeyMapItem *kmi = wm_keymap_item_find(C, opname, opcontext, properties, 0, sloppy, NULL);
+       wmKeyMapItem *kmi = wm_keymap_item_find(C, opname, opcontext, properties, 0, strict, NULL);
        
        if (kmi) {
                WM_keymap_item_to_string(kmi, str, len);
@@ -989,7 +984,7 @@ int WM_key_event_operator_id(
         const bContext *C, const char *opname, int opcontext,
         IDProperty *properties, int hotkey, wmKeyMap **keymap_r)
 {
-       wmKeyMapItem *kmi = wm_keymap_item_find(C, opname, opcontext, properties, hotkey, TRUE, keymap_r);
+       wmKeyMapItem *kmi = wm_keymap_item_find(C, opname, opcontext, properties, hotkey, true, keymap_r);
        
        if (kmi)
                return kmi->id;