use of org.rstudio.studio.client.common.filetypes.EditableFileType 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);
}
});
}
use of org.rstudio.studio.client.common.filetypes.EditableFileType in project rstudio by rstudio.
the class Source method onNewDocumentWithCode.
public void onNewDocumentWithCode(final NewDocumentWithCodeEvent event) {
// determine the type
final EditableFileType docType;
if (event.getType().equals(NewDocumentWithCodeEvent.R_SCRIPT))
docType = FileTypeRegistry.R;
else
docType = FileTypeRegistry.RMARKDOWN;
// command to create and run the new doc
Command newDocCommand = new Command() {
@Override
public void execute() {
newDoc(docType, new ResultCallback<EditingTarget, ServerError>() {
public void onSuccess(EditingTarget arg) {
TextEditingTarget editingTarget = (TextEditingTarget) arg;
editingTarget.insertCode(event.getCode(), false);
if (event.getCursorPosition() != null) {
editingTarget.navigateToPosition(event.getCursorPosition(), false);
}
if (event.getExecute()) {
if (docType.equals(FileTypeRegistry.R)) {
commands_.executeToCurrentLine().execute();
commands_.activateSource().execute();
} else {
commands_.executePreviousChunks().execute();
}
}
}
});
}
};
// do it
if (docType.equals(FileTypeRegistry.R)) {
newDocCommand.execute();
} else {
dependencyManager_.withRMarkdown("R Notebook", "Create R Notebook", newDocCommand);
}
}
Aggregations