Bug 219305 - Open context menu via keyboard shortcut on the Mac
Summary: Open context menu via keyboard shortcut on the Mac
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.4   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P3 enhancement (vote)
Target Milestone: 4.2 M4   Edit
Assignee: Carolyn MacLeod CLA
QA Contact:
URL:
Whiteboard:
Keywords: accessibility
Depends on:
Blocks: 357532
  Show dependency tree
 
Reported: 2008-02-18 06:31 EST by Markus Keller CLA
Modified: 2012-02-17 06:19 EST (History)
5 users (show)

See Also:


Attachments
old patch (10.33 KB, patch)
2011-11-28 10:27 EST, Carolyn MacLeod CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2008-02-18 06:31:28 EST
N20080217-0010

Add a shortcut to the open the context menu on the current selection.

In Eclipse, some views have actions that are only available as context menu items on certain selections (e.g. Synchronize view's "Mark as Merged", or Package Explorer's "Assign Working Sets...").

These actions are currently very hard to use on the Mac without a mouse. The only way I found is to
- enable MouseKeys,
- move the cursor to a selected item, and then
- press Ctrl+Numpad_5

Other platforms have a dedicated 'Menu' key on the keyboard and also open the menu on Shift+F10. Note that Mac OS X by default binds Shift+F10 to a slow version of Expose > Application Windows, so unless you can override this, we have to find another shortcut for the Mac.

If you decide that SWT is not the right place to fill in this missing platform functionality, please move to Platform/UI to consider adding a command for opening the context menu (with a default key binding on the Mac).
Comment 1 Steve Northover CLA 2008-02-19 15:38:06 EST
CAR, is there a standard key that pops up a menu on the Mac?  Scott, do you know of one?
Comment 2 Scott Kovatch CLA 2008-02-19 17:21:24 EST
No, there is no way to show a contextual menu from the keyboard.  There is a Mac OS X bug tracking this, but it hasn't been touched in over 7 years. :-\
Comment 3 Steve Northover CLA 2008-02-19 18:09:05 EST
Wow!  The Mac is so advanced in so many ways ... to be missing this?  Ok, so the "right" platform behavior is not to have a key sequence for this and to make sure the voice over command to get it works.  CAR, do you agree?
Comment 4 Scott Kovatch CLA 2008-02-19 18:39:17 EST
Assuming you already know what element has focus you could always fake a control-click event on the control.
Comment 5 Scott Kovatch CLA 2008-02-20 00:48:46 EST
How about this event?  See CarbonEvents.h:

/*
 *  kEventClassWindow / kEventWindowContextualMenuSelect
 *  
 *  Summary:
 *    A request to display a contextual menu.
 *  
 *  Discussion:
 *    This event is generated by the standard window handler in
 *    response to a contextual menu click in the content area of a
 *    window. In response to such an event, the standard window handler
 *    first checks if the click is on a control, and if so, calls
 *    HandleControlContextualMenuClick. If the click was not on a
 *    control, or if HandleControlContextualMenuClick returned that it
 *    did not handle the click, then the standard window handler sends
 *    kEventWindowContextualMenuSelect to allow the application to
 *    provide its own customized contextual menu. The standard window
 *    handler does not respond to this event itself.
 *  
Comment 6 Markus Keller CLA 2008-02-20 05:37:23 EST
(In reply to comment #2)
> No, there is no way to show a contextual menu from the keyboard.  There is a
> Mac OS X bug tracking this, but it hasn't been touched in over 7 years. :-\

So ... how about touching the bug now?-)

I quickly googled for this before I opened this bug, and I found a number of forum posts from people looking for such a shortcut on the OS level.
Comment 7 Carolyn MacLeod CLA 2008-02-20 12:32:46 EST
Re comment 3, the VoiceOver key sequence is supposed to be: VO-Shift-M
(In other words, Command-F5 to turn on VoiceOver, then Control-Option-Shift-M to get a context menu).

Unfortunately, this doesn't work in Eclipse, on either Tiger or Leopard.
(It does work in Finder and Safari).

So our accessibility implementation is missing something... I believe that if I add the "AxShowMenu" action to a control when a pop-up menu is added, i.e. in setMenu(Menu), then VoiceOver (or any other assistive tool) will be able to pop up the context menu when the user types VO-Shift-M. I'll let you know.

Re comment 6, that'd be great! Scott, you could win the award for "oldest bug fixed" if you tackled this one.  ;)   Is there anything in the radar to give a hint as to why the bug was never fixed?

Re comment 4 and 5, thanks - looks promising. I'll try faking the event after I try fixing the VO-Shift-M not working problem. (That may seem to be the wrong order to fix the problems in, but I am looking at VO problems at the moment... Besides, maybe that will give you time to fix the 7 year old bug before I have to fake the event <grin>).
Comment 8 Steve Northover CLA 2008-02-20 13:15:22 EST
If you put in code to test when to fake the event, you may as well just open the menu in that place rather than faking the event, right?
Comment 9 Carolyn MacLeod CLA 2008-02-20 23:09:35 EST
The AXShowMenu stuff is about 80% working - still needs some cleanup, and some thinking about which x, y to use to pop up the menu <g> before I release it.

Re comment 8 - good point  :)

I had to write a little "showMenu(x, y)" helper method for the AXShowMenu stuff anyhow, so now I only need to look for... what? Shift+F10? 
Or I guess we could copy VoiceOver and use Control-Option-Shift-M ?
Steve? Scott?
Comment 10 Markus Keller CLA 2009-04-09 03:56:50 EDT
The VoiceOver shortcut Control-Option-Shift-M also does not work on Cocoa.
Comment 11 Carolyn MacLeod CLA 2011-11-22 14:36:30 EST
For what it's worth, I found this (marginally useful) information on Wikipedia:

"A keyboard alternative for Mac OS is to enable Mouse keys in Universal Access. Then, depending on whether a laptop or compact or extended keyboard type is used, the shortcut is Function+Ctrl+5 or Ctrl+5 (numeric keypad) or Function+Ctrl+i (laptop)."

I wasn't able to try this on a laptop, and it didn't work with a compact keyboard (no numpad) that I tried, but it did work with an extended keyboard (with numpad).
The down side is that you have to turn on mousekeys, which renders your numpad useless for typing numbers. Also, there are many VoiceOver commands that use the numpad, so I doubt VoiceOver users want MouseKeys on.

Also, it seemed to make my mouse behave strangely (popping up menus everywhere I clicked) until I typed ESC.
Comment 12 Markus Keller CLA 2011-11-26 15:58:51 EST
Yes, MouseKeys is not great, see comment 0. This shortcut should work on the current selection and not at the location of the mouse.

I recently filed bug 357532 for Platform UI support for this, but I haven't verified the final implementation yet. Replacing that implementation with a native SWT version would still be nice.
Comment 13 Carolyn MacLeod CLA 2011-11-27 14:52:29 EST
Re comment 12:
Rats - I thought it was working on the focused item, but I didn't notice that I just happened to have the mouse in the right place when I tried it. Duh.

OK, so the following keyboard insanity does work, for what it's worth.
However it is "suboptimal" (and that's an understatement).

- Beforehand, go to System Preferences, Universal Access, Mouse, and check the box for "Press the Option key 5 times to turn MouseKeys on or off".
1) move focus, using the keyboard, to the item you want a context menu for.
2) turn on VoiceOver (command+F5)
   Notice that the VO cursor (black box) is on drawn around your focus item.
3) secret ingredient: "move mouse to VO cursor" is control+option+command+F5
4) now turn on MouseKeys (option 5 times)
5) control+numpad 5 to bring up the context menu (same as control+mouse click)
6) use the menu
7) at some point you will want to turn off MouseKeys (option 5 times)
8) if you are not a VoiceOver user, turn off VoiceOver (command+F5)

Looking at bug 357532: can the context menu shortcut (ctrl+shift+F10) be reassigned by the user? This might end up being desirable, because some folks might prefer something else. For example, some Mac apps have chosen ctrl+space for context menu (yes, I know we use that for autocomplete), and others have chosen shift+F10 (to be the same as Windows and Linux). Sure wish Mac had assigned a system shortcut for it... apparently their philosophy is that all commands should be accessible by other menus or shortcuts. Oh well.
Comment 14 Carolyn MacLeod CLA 2011-11-28 10:27:57 EST
Created attachment 207605 [details]
old patch

Since I mentioned in comment 9 that I had something mostly working (almost 4 years ago - yikes), I thought it might be helpful if I searched for that patch on my old Mac hard disk and saved it in this bug report so that it isn't lost. Unfortunately, it was for carbon, however the cocoa code should be similar.
Comment 15 Carolyn MacLeod CLA 2011-12-02 12:15:15 EST
Fixed in 3.8 and 4.2: http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=40e15e68f5fa0b6fe1e8ba9d3ffd820b3dca362f

Note that the context menu pops up at the mouse coordinates, instead of over the focused item. However, the user is still able to arrow through the items, and VoiceOver speaks them.

The strange location of the context menu when it is activated from the keyboard is a very old bug that I do not have time to fix at the moment:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=110005
Comment 16 Carolyn MacLeod CLA 2011-12-02 13:46:31 EST
FYI, the fix I just committed makes Control-Option-Shift-M work under VoiceOver. Bug 357532 covers providing a key binding for use without VoiceOver.
Comment 18 Daniel Bevenius CLA 2012-02-17 02:02:45 EST
Thanks so much for adding this feature, I've really missed it on Mac.
Comment 19 Markus Keller CLA 2012-02-17 06:05:06 EST
(In reply to comment #18)
Thanks for the confirmation. I'm just curious: Do you really use the VoiceOver shortcut Control+Option+Shift+M, or do you use Shift+F10 from bug 357532?
Comment 20 Daniel Bevenius CLA 2012-02-17 06:19:29 EST
Ah sorry, I'm actually using SHIFT+F10.