use of org.rstudio.core.client.files.FileSystemItem 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.core.client.files.FileSystemItem in project rstudio by rstudio.
the class TextEditingTargetRMarkdownHelper method createDraftFromTemplate.
private void createDraftFromTemplate(final RmdChosenTemplate template, final String target) {
final ProgressIndicator progress = new GlobalProgressDelayer(globalDisplay_, 250, "Creating R Markdown Document...").getIndicator();
server_.createRmdFromTemplate(target, template.getTemplatePath(), template.createDir(), new ServerRequestCallback<RmdCreatedTemplate>() {
@Override
public void onResponseReceived(RmdCreatedTemplate created) {
// write a pref indicating this is the preferred template--
// we'll default to it the next time we load the template list
prefs_.rmdPreferredTemplatePath().setGlobalValue(template.getTemplatePath());
prefs_.writeUIPrefs();
FileSystemItem file = FileSystemItem.createFile(created.getPath());
eventBus_.fireEvent(new FileEditEvent(file));
progress.onCompleted();
}
@Override
public void onError(ServerError error) {
progress.onError("Couldn't create a template from " + template.getTemplatePath() + " at " + target + ".\n\n" + error.getMessage());
}
});
}
use of org.rstudio.core.client.files.FileSystemItem in project rstudio by rstudio.
the class TextEditingTargetRMarkdownHelper method createDraftFromTemplate.
public void createDraftFromTemplate(final RmdChosenTemplate template) {
final String target = template.getDirectory() + "/" + template.getFileName();
final String targetFile = target + (template.createDir() ? "" : ".Rmd");
fileServer_.stat(targetFile, new ServerRequestCallback<FileSystemItem>() {
@Override
public void onResponseReceived(final FileSystemItem fsi) {
// the file doesn't exist--proceed
if (!fsi.exists()) {
createDraftFromTemplate(template, target);
return;
}
// the file exists--offer to clean it up and continue.
globalDisplay_.showYesNoMessage(GlobalDisplay.MSG_QUESTION, "Overwrite " + (template.createDir() ? "Directory" : "File"), targetFile + " exists. Overwrite it?", false, new Operation() {
@Override
public void execute() {
cleanAndCreateTemplate(template, target, fsi);
}
}, null, null, "Overwrite", "Cancel", false);
}
@Override
public void onError(ServerError error) {
// presumably the file doesn't exist, which is what we want.
createDraftFromTemplate(template, target);
}
});
}
use of org.rstudio.core.client.files.FileSystemItem in project rstudio by rstudio.
the class ViewerPresenter method onViewerSaveAsWebPage.
@Handler
public void onViewerSaveAsWebPage() {
display_.bringToFront();
if (saveAsWebPageDefaultPath_ == null)
saveAsWebPageDefaultPath_ = workbenchContext_.getCurrentWorkingDir();
dependencyManager_.withRMarkdown("Saving standalone web pages", new Command() {
@Override
public void execute() {
fileDialogs_.saveFile("Save As Web Page", fileSystemContext_, saveAsWebPageDefaultPath_, ".html", false, new ProgressOperationWithInput<FileSystemItem>() {
@Override
public void execute(final FileSystemItem targetFile, ProgressIndicator indicator) {
if (targetFile == null) {
indicator.onCompleted();
return;
}
indicator.onProgress("Saving as web page...");
server_.viewerSaveAsWebPage(targetFile.getPath(), new VoidServerRequestCallback(indicator) {
@Override
public void onSuccess() {
saveAsWebPageDefaultPath_ = targetFile.getParentPath();
}
});
}
});
}
});
}
use of org.rstudio.core.client.files.FileSystemItem in project rstudio by rstudio.
the class VCSFileOpener method doOpenFiles.
private void doOpenFiles(JsArray<FileSystemItem> items) {
for (int i = 0; i < items.length(); i++) {
FileSystemItem item = items.get(i);
if (!item.isDirectory()) {
fileTypeRegistry_.openFile(item);
} else {
commands_.activateFiles().execute();
eventBus_.fireEvent(new DirectoryNavigateEvent(item));
}
}
}
Aggregations