我們剛剛見到,當編輯器在作用中時,它們如何將它們自己的動作提供給工作台功能表和工具列。 org.eclipse.ui.editorActions 延伸點則可讓外掛程式在另一外掛程式的編輯器進入作用狀態時新增至工作台功能表和工具列。
在 Readme 範例中,外掛程式會利用 editorActions 延伸點來將其它動作提供到 Readme 編輯器所提供的功能表中。 現在,我們的 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="&Readme Editor Extension"
toolbarPath="ReadmeEditor"
icon="icons/basic/obj16/editor.gif"
tooltip="Run Readme Editor Extension"
class="org.eclipse.ui.examples.readmetool.EditorActionDelegate"
/>
</editorContribution>
</extension>
和檢視畫面動作類似,延伸項目必須指定要接受它提供的動作之編輯器的 targetID。 除了指定的類別必須實作 IEditorActionDelegate 之外,動作本身非常類似檢視畫面動作(id、label 和 toolbarPath)。
請注意,這個標記中沒有指定功能表列路徑。這表示當編輯器在作用中,動作會出現在工作台工具列中,但不會出現在工作台功能表列中。 (請參閱功能表和工具列路徑,以取得功能表和工具列路徑的討論。)
當然,當編輯器在作用中,我們會在編輯器本身提供的動作旁的工具列中看到我們的編輯器動作。
Readme 工具提供 EditorActionDelegate 來實作這個動作。這非常類似於我們先前見到的檢視畫面動作委派。
public void run(IAction action) {
MessageDialog.openInformation(editor.getSite().getShell(),
"Readme Editor",
"Editor Action executed");
}