org.eclipse.ui.editorActions

我們剛剛見到,當編輯器變為作用中時,它們如何將自己的動作提供給工作台功能表和工具列。 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="%Editors.Action.label" 
	      toolbarPath="ReadmeEditor" 
              icon="icons/obj16/editor.gif" 
              tooltip="%Editors.Action.tooltip" 
            class="org.eclipse.ui.examples.readmetool.EditorActionDelegate" 
              /> 
      </editorContribution>
</extension>

和檢視畫面動作類似,延伸項目必須指定要接受它提供的動作之編輯器的 targetID。  除了指定的類別必須實作 IEditorActionDelegate 之外,動作本身非常類似檢視畫面動作(idlabelicontoolbarPath ...)。  

請注意,這個標記中沒有指定功能表列路徑。因此當編輯器在作用時,動作會出現在工作台工具列中,但不會出現在工作台功能表列中。 (請參閱功能表和工具列路徑,以取得功能表和工具列路徑的討論。)

當然,當編輯器在作用中,我們會在編輯器本身提供的動作旁的工具列中看到我們的編輯器動作。

編輯器動作出現在工作台工具列原始編輯器構成要素的旁邊

Readme 工具提供 EditorActionDelegate 來實作這個動作。此類別非常類似於我們先前見到的檢視畫面動作委派。

public void run(IAction action) {      MessageDialog.openInformation(editor.getSite().getShell(),
		MessageUtil.getString("Readme_Editor"),  
		MessageUtil.getString("Editor_Action_executed")); 
}

Copyright IBM Corporation and others 2000, 2003.