以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));
最新评论