Search in sources :

Example 1 with SourceDocument

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

the class Source method restoreDocuments.

private void restoreDocuments(final Session session) {
    final JsArray<SourceDocument> docs = session.getSessionInfo().getSourceDocuments();
    for (int i = 0; i < docs.length(); i++) {
        // restore the docs assigned to this source window
        SourceDocument doc = docs.get(i);
        String docWindowId = doc.getProperties().getString(SourceWindowManager.SOURCE_WINDOW_ID);
        if (docWindowId == null)
            docWindowId = "";
        String currentSourceWindowId = SourceWindowManager.getSourceWindowId();
        // is the main window, and the window it's assigned to isn't open.
        if (currentSourceWindowId == docWindowId || (SourceWindowManager.isMainSourceWindow() && !windowManager_.isSourceWindowOpen(docWindowId))) {
            // attempt to add a tab for the current doc; try/catch this since
            // we don't want to allow one failure to prevent all docs from
            // opening
            EditingTarget sourceEditor = null;
            try {
                sourceEditor = addTab(doc, true, OPEN_REPLAY);
            } catch (Exception e) {
                Debug.logException(e);
            }
            // next one
            if (sourceEditor == null)
                continue;
            final EditingTarget editor = sourceEditor;
            // pop out a particular doc, and restore that doc's position if so
            if (!SourceWindowManager.isMainSourceWindow()) {
                final SourceWindow sourceWindow = RStudioGinjector.INSTANCE.getSourceWindow();
                if (sourceWindow.getInitialDocId() == doc.getId() && sourceWindow.getInitialSourcePosition() != null) {
                    // restore position deferred; restoring it immediately after
                    // instantiating the editor causes inaccurate scroll position
                    // reads elsewhere
                    Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {

                        @Override
                        public void execute() {
                            editor.restorePosition(sourceWindow.getInitialSourcePosition());
                            editor.ensureCursorVisible();
                        }
                    });
                }
            }
        }
    }
}
Also used : ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) Scheduler(com.google.gwt.core.client.Scheduler) 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) JSONString(com.google.gwt.json.client.JSONString) JsArrayString(com.google.gwt.core.client.JsArrayString)

Example 2 with SourceDocument

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

the class Source method onShowData.

public void onShowData(ShowDataEvent event) {
    // ignore if we're a satellite
    if (!SourceWindowManager.isMainSourceWindow())
        return;
    DataItem data = event.getData();
    for (int i = 0; i < editors_.size(); i++) {
        String path = editors_.get(i).getPath();
        if (path != null && path.equals(data.getURI())) {
            ((DataEditingTarget) editors_.get(i)).updateData(data);
            ensureVisible(false);
            view_.selectTab(i);
            return;
        }
    }
    ensureVisible(true);
    server_.newDocument(FileTypeRegistry.DATAFRAME.getTypeId(), null, (JsObject) data.cast(), new SimpleRequestCallback<SourceDocument>("Show Data Frame") {

        @Override
        public void onResponseReceived(SourceDocument response) {
            addTab(response, OPEN_INTERACTIVE);
        }
    });
}
Also used : DataEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.data.DataEditingTarget) DataItem(org.rstudio.studio.client.workbench.views.source.model.DataItem) 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 3 with SourceDocument

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

the class Source method onShowContent.

public void onShowContent(ShowContentEvent event) {
    // ignore if we're a satellite
    if (!SourceWindowManager.isMainSourceWindow())
        return;
    ensureVisible(true);
    ContentItem content = event.getContent();
    server_.newDocument(FileTypeRegistry.URLCONTENT.getTypeId(), null, (JsObject) content.cast(), new SimpleRequestCallback<SourceDocument>("Show") {

        @Override
        public void onResponseReceived(SourceDocument response) {
            addTab(response, OPEN_INTERACTIVE);
        }
    });
}
Also used : SourceDocument(org.rstudio.studio.client.workbench.views.source.model.SourceDocument) ContentItem(org.rstudio.studio.client.workbench.views.source.model.ContentItem)

Example 4 with SourceDocument

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

the class Source method doOpenSourceFile.

private void doOpenSourceFile(final FileSystemItem file, final TextFileType fileType, final FilePosition position, final String pattern, final int navMethod, final boolean forceHighlightMode) {
    // if the navigation should happen in another window, do that instead
    NavigationResult navResult = windowManager_.navigateToFile(file, position, navMethod);
    // we navigated externally, just skip this
    if (navResult.getType() == NavigationResult.RESULT_NAVIGATED)
        return;
    // we're about to open in this window--if it's the main window, focus it
    if (SourceWindowManager.isMainSourceWindow() && Desktop.isDesktop())
        Desktop.getFrame().bringMainFrameToFront();
    final boolean isDebugNavigation = navMethod == NavigationMethods.DEBUG_STEP || navMethod == NavigationMethods.DEBUG_END;
    final CommandWithArg<EditingTarget> editingTargetAction = new CommandWithArg<EditingTarget>() {

        @Override
        public void execute(EditingTarget target) {
            if (position != null) {
                SourcePosition endPosition = null;
                if (isDebugNavigation) {
                    DebugFilePosition filePos = (DebugFilePosition) position.cast();
                    endPosition = SourcePosition.create(filePos.getEndLine() - 1, filePos.getEndColumn() + 1);
                    if (Desktop.isDesktop() && navMethod != NavigationMethods.DEBUG_END)
                        Desktop.getFrame().bringMainFrameToFront();
                }
                navigate(target, SourcePosition.create(position.getLine() - 1, position.getColumn() - 1), endPosition);
            } else if (pattern != null) {
                Position pos = target.search(pattern);
                if (pos != null) {
                    navigate(target, SourcePosition.create(pos.getRow(), 0), null);
                }
            }
        }

        private void navigate(final EditingTarget target, final SourcePosition srcPosition, final SourcePosition srcEndPosition) {
            Scheduler.get().scheduleDeferred(new ScheduledCommand() {

                @Override
                public void execute() {
                    if (navMethod == NavigationMethods.DEBUG_STEP) {
                        target.highlightDebugLocation(srcPosition, srcEndPosition, true);
                    } else if (navMethod == NavigationMethods.DEBUG_END) {
                        target.endDebugHighlighting();
                    } else {
                        // force highlight mode if requested
                        if (forceHighlightMode)
                            target.forceLineHighlighting();
                        // now navigate to the new position
                        boolean highlight = navMethod == NavigationMethods.HIGHLIGHT_LINE && !uiPrefs_.highlightSelectedLine().getValue();
                        target.navigateToPosition(srcPosition, false, highlight);
                    }
                }
            });
        }
    };
    if (navResult.getType() == NavigationResult.RESULT_RELOCATE) {
        server_.getSourceDocument(navResult.getDocId(), new ServerRequestCallback<SourceDocument>() {

            @Override
            public void onResponseReceived(final SourceDocument doc) {
                editingTargetAction.execute(addTab(doc, OPEN_REPLAY));
            }

            @Override
            public void onError(ServerError error) {
                globalDisplay_.showErrorMessage("Document Tab Move Failed", "Couldn't move the tab to this window: \n" + error.getMessage());
            }
        });
        return;
    }
    final CommandWithArg<FileSystemItem> action = new CommandWithArg<FileSystemItem>() {

        @Override
        public void execute(FileSystemItem file) {
            openFile(file, fileType, editingTargetAction);
        }
    };
    // highlight in place.
    if (isDebugNavigation) {
        setPendingDebugSelection();
        for (int i = 0; i < editors_.size(); i++) {
            EditingTarget target = editors_.get(i);
            String path = target.getPath();
            if (path != null && path.equalsIgnoreCase(file.getPath())) {
                // the file's open; just update its highlighting 
                if (navMethod == NavigationMethods.DEBUG_END) {
                    target.endDebugHighlighting();
                } else {
                    view_.selectTab(i);
                    editingTargetAction.execute(target);
                }
                return;
            }
        }
        // open a file just to turn off debug highlighting in the file!
        if (navMethod == NavigationMethods.DEBUG_END)
            return;
    }
    // Warning: event.getFile() can be null (e.g. new Sweave document)
    if (file != null && file.getLength() < 0) {
        // If the file has no size info, stat the file from the server. This
        // is to prevent us from opening large files accidentally.
        server_.stat(file.getPath(), new ServerRequestCallback<FileSystemItem>() {

            @Override
            public void onResponseReceived(FileSystemItem response) {
                action.execute(response);
            }

            @Override
            public void onError(ServerError error) {
                // Couldn't stat the file? Proceed anyway. If the file doesn't
                // exist, we'll let the downstream code be the one to show the
                // error.
                action.execute(file);
            }
        });
    } else {
        action.execute(file);
    }
}
Also used : SourcePosition(org.rstudio.studio.client.workbench.views.source.model.SourcePosition) Position(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position) 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) SourceDocument(org.rstudio.studio.client.workbench.views.source.model.SourceDocument) JSONString(com.google.gwt.json.client.JSONString) JsArrayString(com.google.gwt.core.client.JsArrayString) FileSystemItem(org.rstudio.core.client.files.FileSystemItem) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) SourcePosition(org.rstudio.studio.client.workbench.views.source.model.SourcePosition) NavigationResult(org.rstudio.studio.client.workbench.views.source.SourceWindowManager.NavigationResult)

Example 5 with SourceDocument

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

the class ProfilerPresenter method onStartProfiler.

@Handler
public void onStartProfiler() {
    dependencyManager_.withProfvis(profilerDependecyUserAction_, new Command() {

        @Override
        public void execute() {
            ProfileOperationRequest request = ProfileOperationRequest.create("");
            server_.startProfiling(request, new ServerRequestCallback<ProfileOperationResponse>() {

                @Override
                public void onResponseReceived(ProfileOperationResponse response) {
                    if (response.getErrorMessage() != null) {
                        globalDisplay_.showErrorMessage("Profiler Error", response.getErrorMessage());
                        return;
                    }
                    pSourceWindowManager_.get().ensureVisibleSourcePaneIfNecessary();
                    response_ = response;
                    sourceServer_.newDocument(FileTypeRegistry.PROFILER.getTypeId(), null, (JsObject) ProfilerContents.create(response.getFileName(), null, null, true).cast(), new SimpleRequestCallback<SourceDocument>("Show Profiler") {

                        @Override
                        public void onResponseReceived(SourceDocument response) {
                            currentDocId_ = response.getId();
                        }

                        @Override
                        public void onError(ServerError error) {
                            Debug.logError(error);
                        }
                    });
                }

                @Override
                public void onError(ServerError error) {
                    Debug.logError(error);
                    globalDisplay_.showErrorMessage("Failed to Stop Profiler", error.getMessage());
                }
            });
        }
    });
}
Also used : Command(com.google.gwt.user.client.Command) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) 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) ProfileOperationRequest(org.rstudio.studio.client.workbench.views.source.editors.profiler.model.ProfileOperationRequest) Handler(org.rstudio.core.client.command.Handler)

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