setAccelerator(SWT.CTRL | ‘O’); //not working!

Veröffentlicht von

In my current RCP application I had a problem that the menu key shortcuts did not work correctly:

image

When I started the application and pressed the shortcut, nothing happened. After I opened the menu once, suddenly everything worked! Nachdenkliches Smiley

I created the menu item in the “ApplicationActionBarAdvisor”:

actionOpen.setAccelerator(SWT.CTRL | ‘O’);

So what is the problem? It came up, that in an RCP application the menu and the items are loaded, when the user opens it for the first time. There is not really a solution for that, just a workaround: I had to call “updateAll(true)” on the menu manager:

IWorkbenchWindow window = Workbench.getInstance().getActiveWorkbenchWindow();

if(window instanceof WorkbenchWindow) {
    MenuManager menuManager = ((WorkbenchWindow)window).getMenuManager();
    menuManager.updateAll(true);
}

I called this from my main application window. After that the key bindings worked correctly.

Kommentar hinterlassen

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.