編寫指令鏈結

如果要將指令鏈結併入文件中,您必須先宣告使用支援的 JavaScript 程式碼。 即時說明 JavaScript 位於 org.eclipse.help 外掛程式。 您利用說明系統的跨外掛程式參照技術來參照它。 這項 Script 參照應該放在 HTML 的 HEAD 區段中:

<script language="JavaScript" src="PLUGINS_ROOT/org.eclipse.help/livehelp.js> </script>

現在,在文件主體中,您可以呼叫 executeCommand 函數。 其範例如下:

<a href='javascript:executeCommand("org.eclipse.ui.help.aboutAction")'>
Open the About dialog</a>

executeCommand 函數的參數是序列化的 ParameterizedCommand。 如需此格式的完整資料,請參閱 ParameterizedCommand.serialize() 方法。

上述範例顯示將指令內嵌在 HTML 鏈結中的最基本需求。 Eclipse 文件提供了兩段額外的資訊來加以補充。 首先是指定 class 屬性,以便透過 CSS 來調整鏈結的外觀。 其次是在鏈結文字之前併入影像標示。 影像用來區分指令鏈結和通往其他 HTML 頁面的一般鏈結。 我們最初的範例補充這兩項額外的特性,看起來會如下:

<a class="command-link" href='javascript:executeCommand("org.eclipse.ui.help.aboutAction")'>
<img src="PLUGINS_ROOT/org.eclipse.help/command_link.png">
Open the About dialog</a>

在上述範例中,「關於」對話框指令不需要任何參數,序列化只是指令 id:org.eclipse.ui.help.aboutAction。 以下是另一個範例,顯示帶有參數的指令。請注意,指令 id 後面以括弧括住參數 id 和值:

<a href='javascript:executeCommand(
	"org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.ui.preferencePages.Views)")'>
	Show a preference page</a>

另一個範例是可能有多個參數的示範。 參數以逗點分隔,次序不重要。

<a href='javascript:executeCommand(
	"org.eclipse.ui.dialogs.openMessageDialog(imageType=3,buttonLabel2=Maybe,title=Opinion Poll,message=Do you like command links?,buttonLabel0=Yes,defaultIndex=0,buttonLabel1=No)")'>
	Open a message dialog</a>