Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » External browser with relative paths(Open external browser with a relative path from intro.xml)
External browser with relative paths [message #1851791] Fri, 15 April 2022 16:35 Go to next message
Santiago Gil is currently offline Santiago GilFriend
Messages: 3
Registered: October 2019
Junior Member
Could anyone give me some hint on how can I open a url on external browser using a relative path from a customized Welcome page plugin?

The following code is an example of what I have so far in "intro.xml", which is working and displaying the html file OK for Linux but it doesn't work for 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>
Re: External browser with relative paths [message #1851916 is a reply to message #1851791] Thu, 21 April 2022 15:54 Go to previous message
Santiago Gil is currently offline Santiago GilFriend
Messages: 3
Registered: October 2019
Junior Member
I found a workaround, by using "http://org.eclipse.ui.intro/runAction" and create a class that implements "IIntroAction"

First step: Add a class that implements 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) {
            }   
        }   
    }
}



Second step: Update the url in the link tag as follows:
 url="http://org.eclipse.ui.intro/runAction?pluginId=x.y.z&amp;class=x.y.z.OpenFileInBrowser&amp;filePath=../documentation/index.html"

Previous Topic:arduino / sloeber: how to use #define via configuration?
Next Topic:Sources are not shown during remote target debugging
Goto Forum:
  


Current Time: Fri Apr 19 16:19:07 GMT 2024

Powered by FUDForum. Page generated in 0.01777 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top