问题
I've a question. I have a dynamic menu contribution (class extending the ContributionItem). But I cannot find how to connect these items with key bindings.
The main problem is, that the plugin is actually quite easy. It loads menu from XML file. Practically it is a horror, because there is just few tutorials about dynamic menus. Almost every tutorial uses plugin.xml. But I cannot do it this way. I need to load items from a XML file depending on the workspace choosen. The file contains menu structure including key bindigs. That's my problem. I've never found how to bind keys with commands dynamically.
回答1:
Fortunately the menu item has a method, wich can be used to get this task done:
MenuItem menuItem = new MenuItem(menu, SWT.CHECK, index);
menuItem.setAccelerator(SWT.SHIFT | SWT.ALT | 'G');
Nevetheless to get list of the key bindings already used in current Eclipse instance is not so trivial. Most likely they must be instpected by going through list of plugins and their menu contributions.
来源:https://stackoverflow.com/questions/10028967/dynamic-menu-contribution-with-key-bindings