Search in sources :

Example 81 with FileSystemItem

use of org.rstudio.core.client.files.FileSystemItem in project rstudio by rstudio.

the class TextEditingTarget method postSaveCommand.

private Command postSaveCommand() {
    return new Command() {

        public void execute() {
            // fire source document saved event
            FileSystemItem file = FileSystemItem.createFile(docUpdateSentinel_.getPath());
            events_.fireEvent(new SourceFileSaveCompletedEvent(file, docUpdateSentinel_.getContents(), docDisplay_.getCursorPosition()));
            // check for source on save
            if (fileType_.canSourceOnSave() && docUpdateSentinel_.sourceOnSave()) {
                if (fileType_.isRd()) {
                    previewRd();
                } else if (fileType_.canPreviewFromR()) {
                    previewFromR();
                } else {
                    if (docDisplay_.hasBreakpoints()) {
                        hideBreakpointWarningBar();
                    }
                    consoleDispatcher_.executeSourceCommand(docUpdateSentinel_.getPath(), fileType_, docUpdateSentinel_.getEncoding(), activeCodeIsAscii(), false, false, docDisplay_.hasBreakpoints());
                }
            }
        }
    };
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) RepeatingCommand(com.google.gwt.core.client.Scheduler.RepeatingCommand) Command(com.google.gwt.user.client.Command) AppCommand(org.rstudio.core.client.command.AppCommand) SourceFileSaveCompletedEvent(org.rstudio.studio.client.workbench.views.presentation.events.SourceFileSaveCompletedEvent)

Example 82 with FileSystemItem

use of org.rstudio.core.client.files.FileSystemItem in project rstudio by rstudio.

the class TextEditingTargetCompilePdfHelper method getTargetFile.

public FileSystemItem getTargetFile(FileSystemItem editorFile) {
    ArrayList<TexMagicComment> magicComments = TexMagicComment.parseComments(docDisplay_.getCode());
    String root = StringUtil.notNull(detectRootDirective(magicComments));
    if (root.length() > 0) {
        return FileSystemItem.createFile(editorFile.getParentPath().completePath(root));
    } else {
        String rootPref = prefs_.rootDocument().getValue();
        if (rootPref.length() > 0) {
            FileSystemItem projDir = session_.getSessionInfo().getActiveProjectDir();
            if (projDir != null)
                return FileSystemItem.createFile(projDir.completePath(rootPref));
            else
                return editorFile;
        } else {
            return editorFile;
        }
    }
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) TexMagicComment(org.rstudio.core.client.tex.TexMagicComment)

Example 83 with FileSystemItem

use of org.rstudio.core.client.files.FileSystemItem in project rstudio by rstudio.

the class TextEditingTargetRMarkdownHelper method getKnitWorkingDir.

public String getKnitWorkingDir(DocUpdateSentinel sourceDoc) {
    // shortcut if we don't support manually specified working directories
    if (!session_.getSessionInfo().getKnitWorkingDirAvailable())
        return null;
    // compute desired working directory type
    String workingDirType = sourceDoc.getProperty(RenderRmdEvent.WORKING_DIR_PROP, prefs_.knitWorkingDir().getValue());
    String workingDir = null;
    if (workingDirType == UIPrefsAccessor.KNIT_DIR_PROJECT) {
        // get the project directory, but if we don't have one (e.g. no
        // project) use the default working directory for the session
        FileSystemItem projectDir = session_.getSessionInfo().getActiveProjectDir();
        if (projectDir != null)
            workingDir = projectDir.getPath();
        if (StringUtil.isNullOrEmpty(workingDir))
            workingDir = session_.getSessionInfo().getDefaultWorkingDir();
    } else if (workingDirType == UIPrefsAccessor.KNIT_DIR_CURRENT) {
        workingDir = workbenchContext_.getCurrentWorkingDir().getPath();
    }
    return workingDir;
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) JsArrayString(com.google.gwt.core.client.JsArrayString)

Example 84 with FileSystemItem

use of org.rstudio.core.client.files.FileSystemItem in project rstudio by rstudio.

the class TextEditingTargetRMarkdownHelper method getRMarkdownParamsFile.

public void getRMarkdownParamsFile(final String file, final String encoding, final boolean contentKnownToBeAscii, final CommandWithArg<String> onReady) {
    // can't do this if the server is already busy
    if (workbenchContext_.isServerBusy()) {
        globalDisplay_.showMessage(MessageDisplay.MSG_WARNING, "R Session Busy", "Unable to edit parameters (the R session is currently busy).");
        return;
    }
    // meet all dependencies then ask for params
    final String action = "Specifying Knit parameters";
    dependencyManager_.withRMarkdown(action, new Command() {

        @Override
        public void execute() {
            dependencyManager_.withShiny(action, new Command() {

                @Override
                public void execute() {
                    // subscribe to notification of params ready
                    // (ensure only one handler at a time is sucscribed)
                    rmdParamsReadyUnsubscribe();
                    rmdParamsReadyRegistration_ = eventBus_.addHandler(RmdParamsReadyEvent.TYPE, new RmdParamsReadyEvent.Handler() {

                        @Override
                        public void onRmdParamsReady(RmdParamsReadyEvent e) {
                            rmdParamsReadyUnsubscribe();
                            onReady.execute(e.getParamsFile());
                        }
                    });
                    // execute knit_with_parameters in the console
                    FileSystemItem targetFile = FileSystemItem.createFile(file);
                    consoleDispatcher_.executeCommandWithFileEncoding("knit_with_parameters", targetFile.getPath(), encoding, contentKnownToBeAscii);
                }
            });
        }
    });
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) Command(com.google.gwt.user.client.Command) RmdParamsReadyEvent(org.rstudio.studio.client.rmarkdown.events.RmdParamsReadyEvent) JsArrayString(com.google.gwt.core.client.JsArrayString)

Example 85 with FileSystemItem

use of org.rstudio.core.client.files.FileSystemItem in project rstudio by rstudio.

the class TextEditingTarget method doSynctexSearch.

private void doSynctexSearch(boolean fromClick) {
    SourceLocation sourceLocation = getSelectionAsSourceLocation(fromClick);
    if (sourceLocation == null)
        return;
    // compute the target pdf
    FileSystemItem editorFile = FileSystemItem.createFile(docUpdateSentinel_.getPath());
    FileSystemItem targetFile = compilePdfHelper_.getTargetFile(editorFile);
    String pdfFile = targetFile.getParentPath().completePath(targetFile.getStem() + ".pdf");
    synctex_.forwardSearch(pdfFile, sourceLocation);
}
Also used : SourceLocation(org.rstudio.studio.client.common.synctex.model.SourceLocation) FileSystemItem(org.rstudio.core.client.files.FileSystemItem) JsArrayString(com.google.gwt.core.client.JsArrayString)

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