[置顶] 欢迎您。今天是2023年06月10日。
https://file.foreworld.net/foreworld/20140207/134411.jpg

以net.foreworld.rss2为例,添加一个Ctrl+N打开新窗口功能。

1. 在plugin.xml中添加org.eclipse.ui.commands扩展点。
<extension point="org.eclipse.ui.commands">  
  <category description="Foreworld" id="net.foreworld.rss2.commands" name="Foreworld" />  
  <command categoryId="net.foreworld.rss2.commands" description="打开新窗口" id="net.foreworld.rss2.bindings.command.open_new_window" name="打开新窗口" />
</extension>
2. 在plugin.xml中添加org.eclipse.ui.bindings扩展点。
    <extension point="org.eclipse.ui.bindings">  
  <scheme id="net.foreworld.rss2.bindings" name="Foreworld" />
  <key commandId="net.foreworld.rss2.bindings.command.open_new_window" schemeId="net.foreworld.rss2.bindings" sequence="Ctrl+N" />
</extension>
3. 在Action中设置全局快捷键。
public static final ActionFactory OPEN_NEW_WINDOW = new ActionFactory(ActionFactory.OPEN_NEW_WINDOW.getId()){
  public IWorkbenchAction create(IWorkbenchWindow window) {
    IWorkbenchAction action = ActionFactory.OPEN_NEW_WINDOW.create(window);
    String id = "net.foreworld.rss2.bindings.command.open_new_window";
    if(action != null){
      action.setText("打开新窗口(&N)");
      action.setActionDefinitionId(id);
    }
    return action;
  }
};
4. 在ApplicationActionBarAdvisor的makeActions()中注册该方法。
this.register(RSS2ActionFactory.OPEN_NEW_WINDOW.create(this.window));
您可能也喜欢

今天给RCP打包测试,遇到了以前的遗留问题,就是打包后配置文件丢失,导致一些功能实现不了,从而用了硬编码实现,今天闲来无事,偶然间把问题解决了。以前用的配置文件格式是ini的,在查看了几个配置文件都是properties格式能打包进去后,我也把ini改成了properties,竟然成功。呵呵~爽啊~

二维码
摄像头