如何使用自定義 Eclipse 歡迎頁面插件中的相對路徑在外部瀏覽器上打開 url?
以下代碼是我迄今為止從 intro.xml 獲得的示例,它在 Linux 上運行良好,但在 Windows 上不起作用。
<link
label="Documentation"
url="http://org.eclipse.ui.intro/openBrowser?url=file:../documentation/index.html"
id="link-img-documentation"
style-id="content-link">
<text>Read documentation.</text>
</link>
uj5u.com熱心網友回復:
一種替代方法是使用http://org.eclipse.ui.intro/runAction并創建一個實作的類。IIntroAction
總體而言,您需要做兩件事。
- 添加一個實作的類
IIntroAction
public class OpenFileInBrowser implements IIntroAction {
@Override
public void run(IIntroSite site, Properties params) {
if (params.containsKey("filePath") ){
String filePath = params.getProperty("filePath");
String workingDir = System.getProperty("user.dir");
String urlString = "file://" workingDir File.separator filePath;
try {
IWorkbenchBrowserSupport browserSupport = PlatformUI.getWorkbench().getBrowserSupport();
IWebBrowser browser = browserSupport.getExternalBrowser();
URL url = new URL(urlString);
browser.openURL(url);
} catch (Exception e) {
}
}
}
}
- 更新鏈接標簽中的url如下:
url="http://org.eclipse.ui.intro/runAction?pluginId=x.y.z&class=x.y.z.OpenFileInBrowser&filePath=../documentation/index.html"
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/463591.html
上一篇:如何從R中的URL批量下載資料
