Search in sources :

Example 11 with FileSystemItem

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

Example 12 with FileSystemItem

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());
        }
    });
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) FileEditEvent(org.rstudio.studio.client.workbench.views.source.events.FileEditEvent) ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator) ServerError(org.rstudio.studio.client.server.ServerError) GlobalProgressDelayer(org.rstudio.studio.client.common.GlobalProgressDelayer) RmdCreatedTemplate(org.rstudio.studio.client.rmarkdown.model.RmdCreatedTemplate)

Example 13 with FileSystemItem

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);
        }
    });
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) ServerError(org.rstudio.studio.client.server.ServerError) JsArrayString(com.google.gwt.core.client.JsArrayString) Operation(org.rstudio.core.client.widget.Operation)

Example 14 with FileSystemItem

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();
                        }
                    });
                }
            });
        }
    });
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) AppCommand(org.rstudio.core.client.command.AppCommand) Command(com.google.gwt.user.client.Command) ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator) VoidServerRequestCallback(org.rstudio.studio.client.server.VoidServerRequestCallback) ProgressOperationWithInput(org.rstudio.core.client.widget.ProgressOperationWithInput) EnabledChangedHandler(org.rstudio.core.client.command.EnabledChangedHandler) Handler(org.rstudio.core.client.command.Handler)

Example 15 with FileSystemItem

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));
        }
    }
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) DirectoryNavigateEvent(org.rstudio.studio.client.workbench.views.files.events.DirectoryNavigateEvent)

Aggregations

FileSystemItem (org.rstudio.core.client.files.FileSystemItem)89 ServerError (org.rstudio.studio.client.server.ServerError)18 ProgressIndicator (org.rstudio.core.client.widget.ProgressIndicator)16 JsArrayString (com.google.gwt.core.client.JsArrayString)14 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)10 Handler (org.rstudio.core.client.command.Handler)10 Command (com.google.gwt.user.client.Command)9 ArrayList (java.util.ArrayList)7 AppCommand (org.rstudio.core.client.command.AppCommand)7 VoidServerRequestCallback (org.rstudio.studio.client.server.VoidServerRequestCallback)6 TextFileType (org.rstudio.studio.client.common.filetypes.TextFileType)5 JsArray (com.google.gwt.core.client.JsArray)4 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)4 JSONString (com.google.gwt.json.client.JSONString)4 FilePosition (org.rstudio.core.client.FilePosition)4 ServerRequestCallback (org.rstudio.studio.client.server.ServerRequestCallback)4 EditingTarget (org.rstudio.studio.client.workbench.views.source.editors.EditingTarget)4 CodeBrowserEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.codebrowser.CodeBrowserEditingTarget)4 DataEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.data.DataEditingTarget)4 TextEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget)4