I’m developing a SWT/JFace application using the libraries from Eclipse 3.4.1. I encounter the following problem on Windows (Vista 32bit) and Ubuntu 8.10 32bit:
I create a menu bar in the createMenuManager method of the JFace ApplicationWindow. I add MenuManagers for file, edit and help.
I then add an ExitAction to the file MenuManager like so:
filemenu.add(new ExitAction(this));
The ExitAction is defined this way:
public class ExitAction extends Action { final ApplicationWindow window; public ExitAction(ApplicationWindow w) { this.window = w; setText('E&xit'); setToolTipText('Exit the application'); setAccelerator(SWT.MOD1 + 'Q'); } }
Now when my application starts I want be able to press ‘CTRL+Q’ to quit the application. This does however not work. Only AFTER I click on ‘File’ in the menu bar and THEN clicking ‘CTRL+Q’ the application will quit.
I’ve tried this with different accelerators- same behavior.
It does work however if I create a ‘MenuItem’ instead of an ‘Action’ to contribute to the menu bar.
Is this a SWT bug or do I miss something?
Torsten.
Update: There is a duplicate bug of mine which also contains a workaround. The bug url is: https://bugs.eclipse.org/bugs/show_bug.cgi?id=243758
Basically the workaround is to call
create()on theApplicationWindowand thengetMenuBarManager().updateAll(true);which will force all menu items to get initialized.Of course you have to call the above methods after you created the menu items.