Add Eclipse help system

By | 1月 17, 2016

1. 创建单独的 help plugin

  • New plugin-in project,非RCP,选择模板“Plugin-in with sample help content”。
  • Add dependencies:
    org.eclipse.help
    org.eclipse.help.ui
    org.eclipse.help.webapp
    org.eclipse.equinox.http.jetty
  • Add extensions: “org.eclipse.help.toc”
    将一个topick添加到帮助系统,也就加入到帮助目录中。选中扩展点,可以添加很多toc,最后加入的会覆盖前面的,所以只要加入一个便可。两个变量,file关联一个toc文件;primary表明是否显示在help系统的目录中,一般要为true。
  • 创建Context Help
    里面定义了很多的Context Help ID,该ID用于绑定给UI上的Action或者某个Control。New –> User Assistance –> Context Help。
  • Add extensions: “org.eclipse.help.contexts”
    关联刚创建的Context Help,选中扩展点,new contexts,file指定HelpContext文件,plugin指定ContextHelp所在的plugin。

2. 使用Help Plugin

我们已经创建好了Help Plugin,只要在我们的Plugin中dependenies加入就可以使用了。

添加Help menu (ApplicationActionBarAdvisor.java)

01
02
03
04
05
06
07
08
09
10
11
12
13
14
@Override
protected void makeActions(IWorkbenchWindow window) {
  super.makeActions(window);
  helpAction = ActionFactory.HELP_CONTENTS.create(window);
  this.register(helpAction);
}
 
@Override
protected void fillMenuBar(IMenuManager menuBar) {
  super.fillMenuBar(menuBar);
  MenuManager helpMenu = new MenuManager("&Help", "Help");
  helpMenu.add(helpAction);
  menuBar.add(helpMenu);
}

给Control绑定Context Help

1
PlatformUI.getWorkbench().getHelpSystem().setHelp(control, "rcp.usage.help.ContextHelpId");

第二个变量是:${PluginName}.ContextHelpId. ContextHelpId是在Context Help文件中定义的。