我们刚刚了解了当编辑器活动,它们可以如何将它们自己的操作添加至工作台菜单和工具栏。当另一个插件的编辑器活动时,org.eclipse.ui.editorActions 扩展点允许向工作台菜单和工具栏作添加插件。
在自述文件示例中,插件使用 editorActions 扩展点来为自述文件编辑器添加的菜单添加附加操作。现在,plugin.xml 中的定义应该看起来相当熟悉。
<extension point = "org.eclipse.ui.editorActions"> <editorContribution id="org.eclipse.ui.examples.readmetool.ec1" targetID="org.eclipse.ui.examples.readmetool.ReadmeEditor"> <action id="org.eclipse.ui.examples.readmetool.ea1" label="%Editors.Action.label" toolbarPath="ReadmeEditor" icon="icons/obj16/editor.png" tooltip="%Editors.Action.tooltip" class="org.eclipse.ui.examples.readmetool.EditorActionDelegate" /> </editorContribution> </extension>
与视图操作类似,扩展必须指定它正对其添加操作的编辑器的 targetID。该操作本身与视图操作(标识、标签、图标和 toolbarPath...)非常相似,但指定类必须实现 IEditorActionDelegate。
注意,此标记中未指定菜单栏路径。因此,当编辑器活动时,该操作将出现在工作台工具栏中,而不是出现在工作台菜单栏中。(有关工具栏和菜单路径的讨论,请参阅菜单和工具栏路径。)
的确,当编辑器活动时,我们会看到编辑器操作出现在由编辑器本身添加的操作旁边的工具栏上。
自述文件工具提供 EditorActionDelegate 来实现该操作。此类很象我们先前看到的视图操作代表。
public void run(IAction action) { MessageDialog.openInformation(editor.getSite().getShell(), MessageUtil.getString("Readme_Editor"), MessageUtil.getString("Editor_Action_executed")); }