Search in sources :

Example 1 with TexCapabilities

use of org.rstudio.studio.client.workbench.model.TexCapabilities in project rstudio by rstudio.

the class TextEditingTargetCompilePdfHelper method checkCompilers.

public void checkCompilers(final WarningBarDisplay display, TextFileType fileType) {
    // for all tex files we need to parse magic comments and validate
    // any explict latex proram directive
    ArrayList<TexMagicComment> magicComments = null;
    if (fileType.canCompilePDF()) {
        magicComments = TexMagicComment.parseComments(docDisplay_.getCode());
        String latexProgramDirective = detectLatexProgramDirective(magicComments);
        if (latexProgramDirective != null) {
            if (latexProgramRegistry_.findTypeIgnoreCase(latexProgramDirective) == null) {
                // show warning and bail 
                display.showWarningBar("Unknown LaTeX program type '" + latexProgramDirective + "' specified (valid types are " + latexProgramRegistry_.getPrintableTypeNames() + ")");
                return;
            }
        }
    }
    // for Rnw we first determine the RnwWeave type
    RnwWeave rnwWeave = null;
    RnwWeaveDirective rnwWeaveDirective = null;
    if (fileType.isRnw()) {
        rnwWeaveDirective = detectRnwWeaveDirective(magicComments);
        if (rnwWeaveDirective != null) {
            rnwWeave = rnwWeaveDirective.getRnwWeave();
            if (rnwWeave == null) {
                // show warning and bail 
                display.showWarningBar("Unknown Rnw weave method '" + rnwWeaveDirective.getName() + "' specified (valid types are " + rnwWeaveRegistry_.getPrintableTypeNames() + ")");
                return;
            }
        } else {
            rnwWeave = rnwWeaveRegistry_.findTypeIgnoreCase(prefs_.defaultSweaveEngine().getValue());
        }
    }
    final SessionInfo sessionInfo = session_.getSessionInfo();
    TexCapabilities texCap = sessionInfo.getTexCapabilities();
    final boolean checkForTeX = fileType.canCompilePDF() && !texCap.isTexInstalled();
    final boolean checkForRnwWeave = (rnwWeave != null) && !texCap.isRnwWeaveAvailable(rnwWeave);
    if (checkForTeX || checkForRnwWeave) {
        // alias variables to finals
        final boolean hasRnwWeaveDirective = rnwWeaveDirective != null;
        final RnwWeave fRnwWeave = rnwWeave;
        server_.getTexCapabilities(new ServerRequestCallback<TexCapabilities>() {

            @Override
            public void onResponseReceived(TexCapabilities response) {
                if (checkForTeX && !response.isTexInstalled()) {
                    String warning;
                    if (Desktop.isDesktop())
                        warning = "No TeX installation detected. Please install " + "TeX before compiling.";
                    else
                        warning = "This server does not have TeX installed. You " + "may not be able to compile.";
                    display.showWarningBar(warning);
                } else if (checkForRnwWeave && !response.isRnwWeaveAvailable(fRnwWeave)) {
                    String forContext = "";
                    if (hasRnwWeaveDirective)
                        forContext = "this file";
                    else if (sessionInfo.getActiveProjectFile() != null)
                        forContext = "Rnw files for this project";
                    else
                        forContext = "Rnw files";
                    display.showWarningBar(fRnwWeave.getName() + " is configured to weave " + forContext + " " + "however the " + fRnwWeave.getPackageName() + " package is not installed.");
                } else {
                    display.hideWarningBar();
                }
            }

            @Override
            public void onError(ServerError error) {
                Debug.logError(error);
            }
        });
    } else {
        display.hideWarningBar();
    }
}
Also used : RnwWeave(org.rstudio.studio.client.common.rnw.RnwWeave) RnwWeaveDirective(org.rstudio.studio.client.common.rnw.RnwWeaveDirective) ServerError(org.rstudio.studio.client.server.ServerError) TexCapabilities(org.rstudio.studio.client.workbench.model.TexCapabilities) TexMagicComment(org.rstudio.core.client.tex.TexMagicComment) SessionInfo(org.rstudio.studio.client.workbench.model.SessionInfo)

Example 2 with TexCapabilities

use of org.rstudio.studio.client.workbench.model.TexCapabilities in project rstudio by rstudio.

the class RnwWeaveSelectWidget method verifyAvailable.

protected void verifyAvailable(final RnwWeave weave) {
    // first check if it was already available at startup
    TexCapabilities texCap = session_.getSessionInfo().getTexCapabilities();
    if (texCap.isRnwWeaveAvailable(weave))
        return;
    server_.getTexCapabilities(new ServerRequestCallback<TexCapabilities>() {

        @Override
        public void onResponseReceived(TexCapabilities capabilities) {
            if (!capabilities.isRnwWeaveAvailable(weave)) {
                globalDisplay_.showYesNoMessage(MessageDialog.QUESTION, "Confirm Change", "The " + weave.getPackageName() + " package is required " + "for " + weave.getName() + " weaving, " + "however it is not currently installed. You should " + "ensure that " + weave.getPackageName() + " is installed " + "prior to compiling a PDF." + "\n\nAre you sure you want to change this option?", false, new Operation() {

                    @Override
                    public void execute() {
                    }
                }, new Operation() {

                    @Override
                    public void execute() {
                        setValue(rnwWeaveRegistry_.getTypes().get(0).getName());
                    }
                }, false);
            }
        }

        @Override
        public void onError(ServerError error) {
            Debug.logError(error);
        }
    });
}
Also used : ServerError(org.rstudio.studio.client.server.ServerError) TexCapabilities(org.rstudio.studio.client.workbench.model.TexCapabilities) Operation(org.rstudio.core.client.widget.Operation)

Aggregations

ServerError (org.rstudio.studio.client.server.ServerError)2 TexCapabilities (org.rstudio.studio.client.workbench.model.TexCapabilities)2 TexMagicComment (org.rstudio.core.client.tex.TexMagicComment)1 Operation (org.rstudio.core.client.widget.Operation)1 RnwWeave (org.rstudio.studio.client.common.rnw.RnwWeave)1 RnwWeaveDirective (org.rstudio.studio.client.common.rnw.RnwWeaveDirective)1 SessionInfo (org.rstudio.studio.client.workbench.model.SessionInfo)1