Search in sources :

Example 6 with SourceDocument

use of org.rstudio.studio.client.workbench.views.source.model.SourceDocument in project rstudio by rstudio.

the class ProfilerEditingTarget method onActivate.

public void onActivate() {
    activeProfilerEditingTarger_ = this;
    Scheduler.get().scheduleDeferred(new ScheduledCommand() {

        public void execute() {
            commands_.gotoProfileSource().setEnabled(hasValidPath_);
        }
    });
    final Operation activateOperation = new Operation() {

        @Override
        public void execute() {
            if (!htmlPathInitialized_) {
                htmlPathInitialized_ = true;
                htmlPath_ = getContents().getHtmlPath();
                htmlLocalPath_ = getContents().getHtmlLocalPath();
                isUserSaved_ = getContents().isUserSaved();
                if (htmlPath_ == null) {
                    presenter_.buildHtmlPath(new OperationWithInput<ProfileOperationResponse>() {

                        @Override
                        public void execute(ProfileOperationResponse response) {
                            htmlPath_ = response.getHtmlPath();
                            htmlLocalPath_ = response.getHtmlLocalPath();
                            persistDocumentProperty("htmlPath", htmlPath_);
                            persistDocumentProperty("htmlLocalPath", htmlLocalPath_);
                            view_.showProfilePage(htmlPath_);
                            pSourceWindowManager_.get().maximizeSourcePaneIfNecessary();
                        }
                    }, new Operation() {

                        @Override
                        public void execute() {
                            server_.clearProfile(getPath(), new ServerRequestCallback<JavaScriptObject>() {

                                @Override
                                public void onResponseReceived(JavaScriptObject response) {
                                    commands_.closeSourceDoc().execute();
                                }

                                @Override
                                public void onError(ServerError error) {
                                    Debug.logError(error);
                                    commands_.closeSourceDoc().execute();
                                }
                            });
                        }
                    }, getPath());
                } else {
                    view_.showProfilePage(htmlPath_);
                    Scheduler.get().scheduleDeferred(new ScheduledCommand() {

                        public void execute() {
                            pSourceWindowManager_.get().maximizeSourcePaneIfNecessary();
                        }
                    });
                }
            }
        }
    };
    if (getId() != null && !SourceWindowManager.isMainSourceWindow()) {
        sourceServer_.getSourceDocument(getId(), new ServerRequestCallback<SourceDocument>() {

            @Override
            public void onResponseReceived(SourceDocument document) {
                doc_ = document;
                activateOperation.execute();
            }

            @Override
            public void onError(ServerError error) {
                Debug.logError(error);
            }
        });
    } else {
        activateOperation.execute();
    }
    // This shouldn't happen though.
    if (commandHandlerReg_ != null) {
        Debug.log("Warning: onActivate called twice without intervening onDeactivate");
        commandHandlerReg_.removeHandler();
        commandHandlerReg_ = null;
    }
    commandHandlerReg_ = commandBinder.bind(commands_, this);
}
Also used : ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) ServerError(org.rstudio.studio.client.server.ServerError) SourceDocument(org.rstudio.studio.client.workbench.views.source.model.SourceDocument) ServerRequestCallback(org.rstudio.studio.client.server.ServerRequestCallback) ProfileOperationResponse(org.rstudio.studio.client.workbench.views.source.editors.profiler.model.ProfileOperationResponse) Operation(org.rstudio.core.client.widget.Operation)

Example 7 with SourceDocument

use of org.rstudio.studio.client.workbench.views.source.model.SourceDocument 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 8 with SourceDocument

use of org.rstudio.studio.client.workbench.views.source.model.SourceDocument in project rstudio by rstudio.

the class Source method onShowProfiler.

public void onShowProfiler(OpenProfileEvent event) {
    String profilePath = event.getFilePath();
    String htmlPath = event.getHtmlPath();
    String htmlLocalPath = event.getHtmlLocalPath();
    // first try to activate existing
    for (int idx = 0; idx < editors_.size(); idx++) {
        String path = editors_.get(idx).getPath();
        if (path != null && profilePath.equals(path)) {
            ensureVisible(false);
            view_.selectTab(idx);
            return;
        }
    }
    // create new profiler 
    ensureVisible(true);
    if (event.getDocId() != null) {
        server_.getSourceDocument(event.getDocId(), new ServerRequestCallback<SourceDocument>() {

            @Override
            public void onResponseReceived(SourceDocument response) {
                addTab(response, OPEN_INTERACTIVE);
            }

            @Override
            public void onError(ServerError error) {
                Debug.logError(error);
                globalDisplay_.showErrorMessage("Source Document Error", error.getUserMessage());
            }
        });
    } else {
        server_.newDocument(FileTypeRegistry.PROFILER.getTypeId(), null, (JsObject) ProfilerContents.create(profilePath, htmlPath, htmlLocalPath, event.getCreateProfile()).cast(), new SimpleRequestCallback<SourceDocument>("Show Profiler") {

            @Override
            public void onResponseReceived(SourceDocument response) {
                addTab(response, OPEN_INTERACTIVE);
            }

            @Override
            public void onError(ServerError error) {
                Debug.logError(error);
                globalDisplay_.showErrorMessage("Source Document Error", error.getUserMessage());
            }
        });
    }
}
Also used : ServerError(org.rstudio.studio.client.server.ServerError) SourceDocument(org.rstudio.studio.client.workbench.views.source.model.SourceDocument) JSONString(com.google.gwt.json.client.JSONString) JsArrayString(com.google.gwt.core.client.JsArrayString)

Example 9 with SourceDocument

use of org.rstudio.studio.client.workbench.views.source.model.SourceDocument in project rstudio by rstudio.

the class SourceWindowManager method navigateToPath.

// this function implements the core of routing navigation requests among
// source windows; it does the following:
// 1. attempts to find a window open with the given path 
//    (which can be a physical file or e.g. a code browser) 
// 2. if such a window is found, fires the given event to the window, or
//    closes the window's instance of the tab (server mode w/tab stealing)
// 3. if such a window is not found, indicates as much
private NavigationResult navigateToPath(String path, CrossWindowEvent<?> event, boolean focus) {
    // if this is the main window, check to see if we should route an event
    // there instead
    String sourceWindowId = getWindowIdOfDocPath(path);
    if (isMainSourceWindow()) {
        // if this is the main window but the doc is open in a satellite...
        if (!StringUtil.isNullOrEmpty(sourceWindowId) && isSourceWindowOpen(sourceWindowId)) {
            if (canActivateSourceWindows()) {
                // in desktop mode (and IE) we can bring the appropriate window
                // forward 
                fireEventToSourceWindow(sourceWindowId, event, focus);
                return new NavigationResult(NavigationResult.RESULT_NAVIGATED);
            } else {
                // otherwise, move the tab over to this window by closing it in
                // in its origin window
                JsArray<SourceDocument> sourceDocs = getSourceDocs();
                for (int i = 0; i < sourceDocs.length(); i++) {
                    if (sourceDocs.get(i).getPath() == path) {
                        assignSourceDocWindowId(sourceDocs.get(i).getId(), getSourceWindowId(), null);
                        fireEventToSourceWindow(sourceWindowId, new DocWindowChangedEvent(sourceDocs.get(i).getId(), sourceWindowId, null, sourceDocs.get(i).getCollabParams(), 0), true);
                        return new NavigationResult(NavigationResult.RESULT_RELOCATE, sourceDocs.get(i).getId());
                    }
                }
            }
        }
    } else if (sourceWindowId != null && sourceWindowId != getSourceWindowId()) {
        if (canActivateSourceWindows()) {
            // in desktop mode (and IE) we can just route to the main window
            events_.fireEventToMainWindow(event);
            // if the destination is the main window, raise it
            if (sourceWindowId.isEmpty()) {
                pSatellite_.get().focusMainWindow();
            }
            return new NavigationResult(NavigationResult.RESULT_NAVIGATED);
        } else {
            // otherwise, move the tab over to this window by closing it in
            // in its origin window
            JsArray<SourceDocument> sourceDocs = getSourceDocs();
            for (int i = 0; i < sourceDocs.length(); i++) {
                if (sourceDocs.get(i).getPath() == path) {
                    // take ownership of the doc immediately 
                    assignSourceDocWindowId(sourceDocs.get(i).getId(), getSourceWindowId(), null);
                    events_.fireEventToMainWindow(new DocWindowChangedEvent(sourceDocs.get(i).getId(), sourceWindowId, null, sourceDocs.get(i).getCollabParams(), 0));
                    return new NavigationResult(NavigationResult.RESULT_RELOCATE, sourceDocs.get(i).getId());
                }
            }
        }
    }
    return new NavigationResult(NavigationResult.RESULT_NONE);
}
Also used : JsArray(com.google.gwt.core.client.JsArray) SourceDocument(org.rstudio.studio.client.workbench.views.source.model.SourceDocument) JsArrayString(com.google.gwt.core.client.JsArrayString)

Example 10 with SourceDocument

use of org.rstudio.studio.client.workbench.views.source.model.SourceDocument in project rstudio by rstudio.

the class SourceWindowManager method assignSourceDocWindowId.

private void assignSourceDocWindowId(String docId, String windowId, final Command onComplete) {
    // assign locally
    JsArray<SourceDocument> docs = getSourceDocs();
    for (int i = 0; i < docs.length(); i++) {
        SourceDocument doc = docs.get(i);
        if (doc.getId() == docId) {
            // it 
            if (doc.getSourceWindowId() == windowId)
                return;
            doc.assignSourceWindowId(windowId);
            break;
        }
    }
    // create the new property map
    HashMap<String, String> props = new HashMap<String, String>();
    props.put(SOURCE_WINDOW_ID, windowId);
    // update the doc window ID on the server
    server_.modifyDocumentProperties(docId, props, new ServerRequestCallback<Void>() {

        @Override
        public void onResponseReceived(Void v) {
            if (onComplete != null)
                onComplete.execute();
        }

        @Override
        public void onError(ServerError error) {
            display_.showErrorMessage("Can't Move Doc", "The document could not be " + "moved to a different window: \n" + error.getMessage());
        }
    });
}
Also used : HashMap(java.util.HashMap) ServerError(org.rstudio.studio.client.server.ServerError) SourceDocument(org.rstudio.studio.client.workbench.views.source.model.SourceDocument) JsArrayString(com.google.gwt.core.client.JsArrayString) Void(org.rstudio.studio.client.server.Void)

Aggregations

SourceDocument (org.rstudio.studio.client.workbench.views.source.model.SourceDocument)11 ServerError (org.rstudio.studio.client.server.ServerError)7 JsArrayString (com.google.gwt.core.client.JsArrayString)6 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)5 DataEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.data.DataEditingTarget)5 JSONString (com.google.gwt.json.client.JSONString)4 EditingTarget (org.rstudio.studio.client.workbench.views.source.editors.EditingTarget)4 CodeBrowserEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.codebrowser.CodeBrowserEditingTarget)4 TextEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget)4 ServerRequestCallback (org.rstudio.studio.client.server.ServerRequestCallback)3 Command (com.google.gwt.user.client.Command)2 ProfileOperationResponse (org.rstudio.studio.client.workbench.views.source.editors.profiler.model.ProfileOperationResponse)2 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)1 JsArray (com.google.gwt.core.client.JsArray)1 Scheduler (com.google.gwt.core.client.Scheduler)1 HashMap (java.util.HashMap)1 AppCommand (org.rstudio.core.client.command.AppCommand)1 Handler (org.rstudio.core.client.command.Handler)1 FileSystemItem (org.rstudio.core.client.files.FileSystemItem)1 Operation (org.rstudio.core.client.widget.Operation)1