Search in sources :

Example 16 with EditingTarget

use of org.rstudio.studio.client.workbench.views.source.editors.EditingTarget in project rstudio by rstudio.

the class Source method onNewSweaveDoc.

@Handler
public void onNewSweaveDoc() {
    // set concordance value if we need to
    String concordance = new String();
    if (uiPrefs_.alwaysEnableRnwConcordance().getValue()) {
        RnwWeave activeWeave = rnwWeaveRegistry_.findTypeIgnoreCase(uiPrefs_.defaultSweaveEngine().getValue());
        if (activeWeave.getInjectConcordance())
            concordance = "\\SweaveOpts{concordance=TRUE}\n";
    }
    final String concordanceValue = concordance;
    // show progress
    final ProgressIndicator indicator = new GlobalProgressDelayer(globalDisplay_, 500, "Creating new document...").getIndicator();
    // get the template
    server_.getSourceTemplate("", "sweave.Rnw", new ServerRequestCallback<String>() {

        @Override
        public void onResponseReceived(String templateContents) {
            indicator.onCompleted();
            // add in concordance if necessary
            final boolean hasConcordance = concordanceValue.length() > 0;
            if (hasConcordance) {
                String beginDoc = "\\begin{document}\n";
                templateContents = templateContents.replace(beginDoc, beginDoc + concordanceValue);
            }
            newDoc(FileTypeRegistry.SWEAVE, templateContents, new ResultCallback<EditingTarget, ServerError>() {

                @Override
                public void onSuccess(EditingTarget target) {
                    int startRow = 4 + (hasConcordance ? 1 : 0);
                    target.setCursorPosition(Position.create(startRow, 0));
                }
            });
        }

        @Override
        public void onError(ServerError error) {
            indicator.onError(error.getUserMessage());
        }
    });
}
Also used : RnwWeave(org.rstudio.studio.client.common.rnw.RnwWeave) ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator) ServerError(org.rstudio.studio.client.server.ServerError) GlobalProgressDelayer(org.rstudio.studio.client.common.GlobalProgressDelayer) 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) JSONString(com.google.gwt.json.client.JSONString) JsArrayString(com.google.gwt.core.client.JsArrayString) NativePreviewHandler(com.google.gwt.user.client.Event.NativePreviewHandler) FileTypeChangedHandler(org.rstudio.studio.client.workbench.views.source.editors.text.events.FileTypeChangedHandler) Handler(org.rstudio.core.client.command.Handler) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) SelectionHandler(com.google.gwt.event.logical.shared.SelectionHandler) CloseHandler(com.google.gwt.event.logical.shared.CloseHandler) ViewDataHandler(org.rstudio.studio.client.workbench.views.data.events.ViewDataHandler) SourceOnSaveChangedHandler(org.rstudio.studio.client.workbench.views.source.editors.text.events.SourceOnSaveChangedHandler) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) OpenSourceFileHandler(org.rstudio.studio.client.common.filetypes.events.OpenSourceFileHandler)

Example 17 with EditingTarget

use of org.rstudio.studio.client.workbench.views.source.editors.EditingTarget in project rstudio by rstudio.

the class Source method saveChanges.

private void saveChanges(ArrayList<UnsavedChangesTarget> targets, Command onCompleted) {
    // convert back to editing targets
    ArrayList<EditingTarget> saveTargets = new ArrayList<EditingTarget>();
    for (UnsavedChangesTarget target : targets) {
        EditingTarget saveTarget = getEditingTargetForId(target.getId());
        if (saveTarget != null)
            saveTargets.add(saveTarget);
    }
    // execute the save
    cpsExecuteForEachEditor(// targets the user chose to save
    saveTargets, // save each editor
    new CPSEditingTargetCommand() {

        @Override
        public void execute(EditingTarget saveTarget, Command continuation) {
            saveTarget.save(continuation);
        }
    }, // onCompleted at the end
    onCompleted);
}
Also used : UnsavedChangesTarget(org.rstudio.studio.client.workbench.model.UnsavedChangesTarget) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) Command(com.google.gwt.user.client.Command) AppCommand(org.rstudio.core.client.command.AppCommand) ArrayList(java.util.ArrayList) 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)

Example 18 with EditingTarget

use of org.rstudio.studio.client.workbench.views.source.editors.EditingTarget in project rstudio by rstudio.

the class Source method newSourceDocWithTemplate.

private void newSourceDocWithTemplate(final TextFileType fileType, String name, String template, final Position cursorPosition, final CommandWithArg<EditingTarget> onSuccess, final TransformerCommand<String> contentTransformer) {
    final ProgressIndicator indicator = new GlobalProgressDelayer(globalDisplay_, 500, "Creating new document...").getIndicator();
    server_.getSourceTemplate(name, template, new ServerRequestCallback<String>() {

        @Override
        public void onResponseReceived(String templateContents) {
            indicator.onCompleted();
            if (contentTransformer != null)
                templateContents = contentTransformer.transform(templateContents);
            newDoc(fileType, templateContents, new ResultCallback<EditingTarget, ServerError>() {

                @Override
                public void onSuccess(EditingTarget target) {
                    if (cursorPosition != null)
                        target.setCursorPosition(cursorPosition);
                    if (onSuccess != null)
                        onSuccess.execute(target);
                }
            });
        }

        @Override
        public void onError(ServerError error) {
            indicator.onError(error.getUserMessage());
        }
    });
}
Also used : ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator) ServerError(org.rstudio.studio.client.server.ServerError) GlobalProgressDelayer(org.rstudio.studio.client.common.GlobalProgressDelayer) 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) JSONString(com.google.gwt.json.client.JSONString) JsArrayString(com.google.gwt.core.client.JsArrayString)

Example 19 with EditingTarget

use of org.rstudio.studio.client.workbench.views.source.editors.EditingTarget 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)

Example 20 with EditingTarget

use of org.rstudio.studio.client.workbench.views.source.editors.EditingTarget in project rstudio by rstudio.

the class Source method openFile.

// top-level wrapper for opening files. takes care of:
//  - making sure the view is visible
//  - checking whether it is already open and re-selecting its tab
//  - prohibit opening very large files (>500KB)
//  - confirmation of opening large files (>100KB)
//  - finally, actually opening the file from the server
//    via the call to the lower level openFile method
private void openFile(final FileSystemItem file, final TextFileType fileType, final ResultCallback<EditingTarget, ServerError> resultCallback) {
    ensureVisible(true);
    if (fileType.isRNotebook()) {
        openNotebook(file, fileType, resultCallback);
        return;
    }
    if (file == null) {
        newDoc(fileType, resultCallback);
        return;
    }
    if (openFileAlreadyOpen(file, resultCallback))
        return;
    EditingTarget target = editingTargetSource_.getEditingTarget(fileType);
    if (file.getLength() > target.getFileSizeLimit()) {
        if (resultCallback != null)
            resultCallback.onCancelled();
        showFileTooLargeWarning(file, target.getFileSizeLimit());
    } else if (file.getLength() > target.getLargeFileSize()) {
        confirmOpenLargeFile(file, new Operation() {

            public void execute() {
                openFileFromServer(file, fileType, resultCallback);
            }
        }, new Operation() {

            public void execute() {
                // user (wisely) cancelled
                if (resultCallback != null)
                    resultCallback.onCancelled();
            }
        });
    } else {
        openFileFromServer(file, fileType, resultCallback);
    }
}
Also used : 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) Operation(org.rstudio.core.client.widget.Operation)

Aggregations

EditingTarget (org.rstudio.studio.client.workbench.views.source.editors.EditingTarget)22 CodeBrowserEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.codebrowser.CodeBrowserEditingTarget)22 DataEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.data.DataEditingTarget)22 TextEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget)22 JsArrayString (com.google.gwt.core.client.JsArrayString)10 JSONString (com.google.gwt.json.client.JSONString)10 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)9 Command (com.google.gwt.user.client.Command)7 AppCommand (org.rstudio.core.client.command.AppCommand)7 ServerError (org.rstudio.studio.client.server.ServerError)7 FileSystemItem (org.rstudio.core.client.files.FileSystemItem)4 VoidServerRequestCallback (org.rstudio.studio.client.server.VoidServerRequestCallback)4 SourceDocument (org.rstudio.studio.client.workbench.views.source.model.SourceDocument)4 ArrayList (java.util.ArrayList)3 ProgressIndicator (org.rstudio.core.client.widget.ProgressIndicator)3 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)2 CloseHandler (com.google.gwt.event.logical.shared.CloseHandler)2 SelectionHandler (com.google.gwt.event.logical.shared.SelectionHandler)2 ValueChangeHandler (com.google.gwt.event.logical.shared.ValueChangeHandler)2 NativePreviewHandler (com.google.gwt.user.client.Event.NativePreviewHandler)2