Page MenuHome

Hide shortcuts from buttons in popups
AbandonedPublic

Authored by Aleksandr Zinovev (raa) on Dec 22 2016, 1:10 AM.

Details

Summary

Before and After:

To reproduce the issue run the script in Blender's text editor:

import bpy

class TEST_OT_test(bpy.types.Operator):
    bl_idname = "test.test"
    bl_label = "Test"

    def draw(self, context):
        layout = self.layout
        layout.operator("ed.undo")
        layout.operator("ed.undo_history")

    def execute(self, context):
        return {'FINISHED'}

    def invoke(self, context, event):
        return context.window_manager.invoke_props_dialog(self, width=100)

bpy.utils.register_class(TEST_OT_test)

bpy.ops.test.test('INVOKE_DEFAULT')

Diff Detail

Repository
rB Blender

Event Timeline

Aleksandr Zinovev (raa) retitled this revision from to Hide shortcuts from buttons in popups.
Aleksandr Zinovev (raa) updated this object.
Aleksandr Zinovev (raa) set the repository for this revision to rB Blender.
Bastien Montagne (mont29) requested changes to this revision.Dec 29 2016, 10:08 AM
Bastien Montagne (mont29) edited edge metadata.

Am afraid this won’t be that simple… Your patch also removes shortcuts from 'popup' menus (like Special W one, try it in Edit mode of a mesh e.g.).

This revision now requires changes to proceed.Dec 29 2016, 10:08 AM
Aleksandr Zinovev (raa) edited edge metadata.

Looks like the easiest way to fix the issue is to add a new UI_BLOCK_MENU flag.

The task related to this Differential is T49919.

Bastien Montagne (mont29) edited edge metadata.

Patch looks OK to me now, @Julian Eisel (Severin) would really not mind a second pair of eyes on that one before we commit it ;)

This revision is now accepted and ready to land.Jan 9 2017, 12:54 PM

Found a way to fix the issue without adding a new flag.

Aleksandr Zinovev (raa) requested review of this revision.May 25 2017, 6:46 PM
Aleksandr Zinovev (raa) edited edge metadata.
Julian Eisel (Severin) requested changes to this revision.Jul 26 2017, 6:31 PM

Hmm, am not so sure about this. Using UI_BLOCK_BOUNDS_POPUP_MOUSE doesn't seem right since the issue may also occur on menus not bound to the mouse. Adding an extra flag... don't really like this either.

I guess the purpose of the keymap strings is for un-embossed menu items, like in the 'Specials' menu in edit mode or most other pulldowns. So I think a better way to fix this issue is checking if buttons draw pulldown-like without embossing before adding the shortcut string. Something like this:

1diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
2index 2bf10c1..8ea5094 100644
3--- a/source/blender/editors/interface/interface.c
4+++ b/source/blender/editors/interface/interface.c
5@@ -1165,6 +1165,8 @@ static void ui_menu_block_set_keymaps(const bContext *C, uiBlock *block)
6 uiBut *but;
7 char buf[128];
8
9+ BLI_assert(block->flag & UI_BLOCK_LOOP);
10+
11 /* only do it before bounding */
12 if (block->rect.xmin != block->rect.xmax)
13 return;
14@@ -1179,6 +1181,9 @@ static void ui_menu_block_set_keymaps(const bContext *C, uiBlock *block)
15 }
16 else {
17 for (but = block->buttons.first; but; but = but->next) {
18+ if (but->dt != UI_EMBOSS_PULLDOWN) {
19+ continue;
20+ }
21
22 if (ui_but_event_operator_string(C, but, buf, sizeof(buf))) {
23 ui_but_add_shortcut(but, buf, false);

This revision now requires changes to proceed.Jul 26 2017, 6:31 PM

Committed rB920bff522483cf. Thanks @Aleksandr Zinovev (raa) for raising awareness and attempting to fix! (Even if we ended up going with a different solution ;) )