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);
}
});
}
Aggregations