动态菜单贡献与键绑定(Dynamic menu contribution with key bindings)

167 IT屋

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.

解决方案

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.

我有一个问题。我有一个动态菜单贡献(类扩展 ContributionItem )。但是我找不到如何连接密钥绑定这些项目。



主要的问题是插件实际上很容易。它从XML文件加载菜单。实际上这是一个恐怖,因为只有很少的关于动态菜单的教程。几乎每个教程都使用 plugin.xml 。但我不能这样做。根据选择的工作空间,我需要从XML文件中加载项目。该文件包含菜单结构,包括键盘。这是我的问题我从来没有发现如何动态地使用命令绑定密钥。


解决方案

幸运的是,菜单项有一个方法,可以使用要完成此任务:



  MenuItem menuItem = new MenuItem(菜单,SWT.CHECK,索引); 
menuItem.setAccelerator(SWT.SHIFT | SWT.ALT |'G');


目前来看,目前Eclipse实例中已经使用的键绑定列表并不简单。很可能他们必须通过浏览插件列表和他们的菜单贡献来调整。


本文地址:IT屋 » 动态菜单贡献与键绑定