Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[platform-swt-dev] Done with cocoa Menus


Ok, I'm done with Menu.java and MenuItem.java for cocoa and I never want to see them again (but I doubt I will be that lucky).

I have implemented a horrible hack to get accelerators to draw, but not fire.  To summarize, Eclipse looks for keystrokes and doesn't use real accelerators.  Cocoa doesn't provide any sort of custom draw for menus so the only way to get accelerators to draw is to match what Eclipse is giving us, then set the real accelerator, however, the real accelerator cannot fire.  If it did, then Eclipse would run two actions instead of one.  There is a horrible hack (that probably will not hold) where menu items are hidden and shown when a menu is hidden and shown to avoid accelerators matching. The good thing about using real accelerators is that, like carbon, accessibility will work way better.

Lots of time was wasted on menuHasKeyEquivalent:forEvent:target:action:, which seems to be what you want but provides no way to stop an accelerator from running and let the keystroke go to the widget.  All combinations of returning true and false, hacks involving temporarily disabling the items so they wouldn't match then reenabing them etc. failed.

I expect that the hide/show hack will not hold and we will have to match the key ourselves in NSApplication to find out if it matches but there is no SWT accelerator associated with it, then fool around to get the key to go to the widget.  Right now, I don't have the strength for this ... but somone else might.

Along with fixing the accelerator bug, I fixed everything I could see and made sure there were //TODO's for things left.  Here are some of the fixes I did:
        - deleted unused fields
        - deleted unused (and unwanted) methods
        - deleted useless casts (ie. ((NSMenuItem)nsItem))
        - fixed SWT.Show to be sent every time the menu is shown
        - sorted the methods alphabetically

The following Eclipse UI bugs/featuresare stopping accelerators from being 100% right.  Eclipse needs to change to feed us the right accelerator string.

https://bugs.eclipse.org/bugs/show_bug.cgi?id=217810
[KeyBindings] org.eclipse.ui.bindings -> key becomes awkward with carbon and cocoa

https://bugs.eclipse.org/bugs/show_bug.cgi?id=239485
[Workbench] Better handling of ws/os specific code

Back to the top