tags:

views:

198

answers:

5

Hi,

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.

A: 

AFAIK setAccelerator(.) does nothing else than adding the appropriate text to your MenuItem. You are responsible to register for an KeyUp event and react on it.

You can use Display.addFilter(SWT.KeyUp, myListener) to register your Listener independently of your widgets.

the.duckman
A: 

Thanks for the help- I try this one!

But why would the accelarator key work once I have opened the menu? My guess is it's some kind of lazy initialization. In Eclips RCP applications one should use Commands to register hotkeys. My application doesn't have the infrastructure though.

BTW I asked the same on the Eclipse SWT newsgroup but they couldn't provide an answer yet. So it's either a new weird bug in 3.4.1 or something really stupid on my part :)

Torsten.

Torsten Uhlmann
A: 

I have tried the original code with Eclipse 3.3 libraries and it works out of the box. So I guess it's a SWT bug which I'm gonna submit now...

Torsten Uhlmann
A: 

Turns out that this is a bug in Eclipse 3.4. I have submitted a bug report: https://bugs.eclipse.org/bugs/show_bug.cgi?id=253078

Torsten Uhlmann
A: 

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 the ApplicationWindow and then getMenuBarManager().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.

Torsten Uhlmann