Search in sources :

Example 1 with FileType

use of org.rstudio.studio.client.common.filetypes.FileType in project rstudio by rstudio.

the class AceEditorBackgroundLinkHighlighter method navigateToUrl.

private void navigateToUrl(String url) {
    // allow web links starting with 'www'
    if (url.startsWith("www."))
        url = "http://" + url;
    // attempt to open web links in a new window
    Pattern reWebLink = Pattern.create("^https?://");
    if (reWebLink.test(url)) {
        globalDisplay_.openWindow(url);
        return;
    }
    // handle testthat links
    Pattern reSrcRef = Pattern.create("@[^#]+#\\d+");
    if (reSrcRef.test(url))
        return;
    // treat other URLs as paths to files on the server
    final String finalUrl = url;
    server_.stat(finalUrl, new ServerRequestCallback<FileSystemItem>() {

        @Override
        public void onResponseReceived(FileSystemItem file) {
            // inform user when no file found
            if (file == null || !file.exists()) {
                String message = "No file at path '" + finalUrl + "'.";
                String caption = "Error navigating to file";
                globalDisplay_.showErrorMessage(caption, message);
                return;
            }
            // if we have a registered filetype for this file, try
            // to open it in the IDE; otherwise open in browser
            FileType fileType = fileTypeRegistry_.getTypeForFile(file);
            if (fileType != null && fileType instanceof EditableFileType) {
                fileType.openFile(file, null, NavigationMethods.DEFAULT, events_);
            } else {
                events_.fireEvent(new OpenFileInBrowserEvent(file));
            }
        }

        @Override
        public void onError(ServerError error) {
            Debug.logError(error);
        }
    });
}
Also used : Pattern(org.rstudio.core.client.regex.Pattern) FileSystemItem(org.rstudio.core.client.files.FileSystemItem) OpenFileInBrowserEvent(org.rstudio.studio.client.common.filetypes.events.OpenFileInBrowserEvent) EditableFileType(org.rstudio.studio.client.common.filetypes.EditableFileType) FileType(org.rstudio.studio.client.common.filetypes.FileType) TextFileType(org.rstudio.studio.client.common.filetypes.TextFileType) ServerError(org.rstudio.studio.client.server.ServerError) EditableFileType(org.rstudio.studio.client.common.filetypes.EditableFileType)

Aggregations

FileSystemItem (org.rstudio.core.client.files.FileSystemItem)1 Pattern (org.rstudio.core.client.regex.Pattern)1 EditableFileType (org.rstudio.studio.client.common.filetypes.EditableFileType)1 FileType (org.rstudio.studio.client.common.filetypes.FileType)1 TextFileType (org.rstudio.studio.client.common.filetypes.TextFileType)1 OpenFileInBrowserEvent (org.rstudio.studio.client.common.filetypes.events.OpenFileInBrowserEvent)1 ServerError (org.rstudio.studio.client.server.ServerError)1