Search in sources :

Example 1 with EditableFileType

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);
        }
    });
}
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 2 with EditableFileType

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);
    }
}
Also used : ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) Command(com.google.gwt.user.client.Command) AppCommand(org.rstudio.core.client.command.AppCommand) ServerError(org.rstudio.studio.client.server.ServerError) TextEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget) EditingTarget(org.rstudio.studio.client.workbench.views.source.editors.EditingTarget) DataEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.data.DataEditingTarget) CodeBrowserEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.codebrowser.CodeBrowserEditingTarget) TextEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget) EditableFileType(org.rstudio.studio.client.common.filetypes.EditableFileType)

Aggregations

EditableFileType (org.rstudio.studio.client.common.filetypes.EditableFileType)2 ServerError (org.rstudio.studio.client.server.ServerError)2 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)1 Command (com.google.gwt.user.client.Command)1 AppCommand (org.rstudio.core.client.command.AppCommand)1 FileSystemItem (org.rstudio.core.client.files.FileSystemItem)1 Pattern (org.rstudio.core.client.regex.Pattern)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 EditingTarget (org.rstudio.studio.client.workbench.views.source.editors.EditingTarget)1 CodeBrowserEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.codebrowser.CodeBrowserEditingTarget)1 DataEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.data.DataEditingTarget)1 TextEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget)1