Search in sources :

Example 11 with EditingTarget

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

the class Source method openNotebook.

private void openNotebook(final FileSystemItem rmdFile, final SourceDocumentResult doc, final ResultCallback<EditingTarget, ServerError> resultCallback) {
    if (!StringUtil.isNullOrEmpty(doc.getDocPath())) {
        // this happens if we created the R Markdown file, or if the R Markdown
        // file on disk matched the one inside the notebook
        openFileFromServer(rmdFile, FileTypeRegistry.RMARKDOWN, resultCallback);
    } else if (!StringUtil.isNullOrEmpty(doc.getDocId())) {
        // this happens when we have to open an untitled buffer for the the
        // notebook (usually because the of a conflict between the Rmd on disk
        // and the one in the .nb.html file)
        server_.getSourceDocument(doc.getDocId(), new ServerRequestCallback<SourceDocument>() {

            @Override
            public void onResponseReceived(SourceDocument doc) {
                // create the editor
                EditingTarget target = addTab(doc, OPEN_INTERACTIVE);
                // show a warning bar 
                if (target instanceof TextEditingTarget) {
                    ((TextEditingTarget) target).showWarningMessage("This notebook has the same name as an R Markdown " + "file, but doesn't match it.");
                }
                resultCallback.onSuccess(target);
            }

            @Override
            public void onError(ServerError error) {
                globalDisplay_.showErrorMessage("Notebook Open Failed", "This notebook could not be opened. " + "If the error persists, try removing the " + "accompanying R Markdown file. \n\n" + error.getMessage());
                resultCallback.onFailure(error);
            }
        });
    }
}
Also used : ServerError(org.rstudio.studio.client.server.ServerError) SourceDocument(org.rstudio.studio.client.workbench.views.source.model.SourceDocument) 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) VoidServerRequestCallback(org.rstudio.studio.client.server.VoidServerRequestCallback) ServerRequestCallback(org.rstudio.studio.client.server.ServerRequestCallback)

Example 12 with EditingTarget

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

the class Source method openFileAlreadyOpen.

private boolean openFileAlreadyOpen(final FileSystemItem file, final ResultCallback<EditingTarget, ServerError> resultCallback) {
    // check to see if any local editors have the file open
    for (int i = 0; i < editors_.size(); i++) {
        EditingTarget target = editors_.get(i);
        String thisPath = target.getPath();
        if (thisPath != null && thisPath.equalsIgnoreCase(file.getPath())) {
            view_.selectTab(i);
            pMruList_.get().add(thisPath);
            if (resultCallback != null)
                resultCallback.onSuccess(target);
            return true;
        }
    }
    return false;
}
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) JSONString(com.google.gwt.json.client.JSONString) JsArrayString(com.google.gwt.core.client.JsArrayString)

Example 13 with EditingTarget

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

the class Source method onInsertSource.

public void onInsertSource(final InsertSourceEvent event) {
    if (activeEditor_ != null && activeEditor_ instanceof TextEditingTarget && commands_.executeCode().isEnabled()) {
        TextEditingTarget textEditor = (TextEditingTarget) activeEditor_;
        textEditor.insertCode(event.getCode(), event.isBlock());
    } else {
        newDoc(FileTypeRegistry.R, new ResultCallback<EditingTarget, ServerError>() {

            public void onSuccess(EditingTarget arg) {
                ((TextEditingTarget) arg).insertCode(event.getCode(), event.isBlock());
            }
        });
    }
}
Also used : ServerError(org.rstudio.studio.client.server.ServerError) TextEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget) 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 14 with EditingTarget

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

the class Source method fireDocTabsChanged.

private void fireDocTabsChanged() {
    if (!initialized_)
        return;
    // ensure we have a tab order (we want the popup list to match the order
    // of the tabs)
    syncTabOrder();
    String[] ids = new String[editors_.size()];
    ImageResource[] icons = new ImageResource[editors_.size()];
    String[] names = new String[editors_.size()];
    String[] paths = new String[editors_.size()];
    for (int i = 0; i < ids.length; i++) {
        EditingTarget target = editors_.get(tabOrder_.get(i));
        ids[i] = target.getId();
        icons[i] = target.getIcon();
        names[i] = target.getName().getValue();
        paths[i] = target.getPath();
    }
    events_.fireEvent(new DocTabsChangedEvent(ids, icons, names, paths));
    view_.manageChevronVisibility();
}
Also used : ImageResource(com.google.gwt.resources.client.ImageResource) 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 15 with EditingTarget

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

the class Source method openFileFromServer.

private void openFileFromServer(final FileSystemItem file, final TextFileType fileType, final ResultCallback<EditingTarget, ServerError> resultCallback) {
    final Command dismissProgress = globalDisplay_.showProgress("Opening file...");
    server_.openDocument(file.getPath(), fileType.getTypeId(), uiPrefs_.defaultEncoding().getValue(), new ServerRequestCallback<SourceDocument>() {

        @Override
        public void onError(ServerError error) {
            dismissProgress.execute();
            pMruList_.get().remove(file.getPath());
            Debug.logError(error);
            if (resultCallback != null)
                resultCallback.onFailure(error);
        }

        @Override
        public void onResponseReceived(SourceDocument document) {
            dismissProgress.execute();
            pMruList_.get().add(document.getPath());
            EditingTarget target = addTab(document, OPEN_INTERACTIVE);
            if (resultCallback != null)
                resultCallback.onSuccess(target);
        }
    });
}
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) SourceDocument(org.rstudio.studio.client.workbench.views.source.model.SourceDocument) 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)

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