Search in sources :

Example 1 with EditingTarget

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

the class Source method onGetEditorContext.

@Override
public void onGetEditorContext(GetEditorContextEvent event) {
    GetEditorContextEvent.Data data = event.getData();
    int type = data.getType();
    if (type == GetEditorContextEvent.TYPE_ACTIVE_EDITOR) {
        if (consoleEditorHadFocusLast() || activeEditor_ == null)
            type = GetEditorContextEvent.TYPE_CONSOLE_EDITOR;
        else
            type = GetEditorContextEvent.TYPE_SOURCE_EDITOR;
    }
    if (type == GetEditorContextEvent.TYPE_CONSOLE_EDITOR) {
        InputEditorDisplay editor = consoleEditorProvider_.getConsoleEditor();
        if (editor != null && editor instanceof DocDisplay) {
            getEditorContext("#console", "", (DocDisplay) editor);
            return;
        }
    } else if (type == GetEditorContextEvent.TYPE_SOURCE_EDITOR) {
        EditingTarget target = activeEditor_;
        if (target != null && target instanceof TextEditingTarget) {
            getEditorContext(target.getId(), target.getPath(), ((TextEditingTarget) target).getDocDisplay());
            return;
        }
    }
    // We need to ensure a 'getEditorContext' event is always
    // returned as we have a 'wait-for' event on the server side
    server_.getEditorContextCompleted(GetEditorContextEvent.SelectionData.create(), new VoidServerRequestCallback());
}
Also used : InputEditorDisplay(org.rstudio.studio.client.workbench.views.console.shell.editor.InputEditorDisplay) GetEditorContextEvent(org.rstudio.studio.client.events.GetEditorContextEvent) 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) DocDisplay(org.rstudio.studio.client.workbench.views.source.editors.text.DocDisplay)

Example 2 with EditingTarget

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

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

the class Source method attemptSourceNavigation.

private void attemptSourceNavigation(final SourceNavigation navigation, final AppCommand retryCommand) {
    // see if we can navigate by id
    String docId = navigation.getDocumentId();
    final EditingTarget target = getEditingTargetForId(docId);
    if (target != null) {
        // case execute the retry command
        if ((target == activeEditor_) && target.isAtSourceRow(navigation.getPosition())) {
            if (retryCommand.isEnabled())
                retryCommand.execute();
        } else {
            suspendSourceNavigationAdding_ = true;
            try {
                view_.selectTab(target.asWidget());
                target.restorePosition(navigation.getPosition());
            } finally {
                suspendSourceNavigationAdding_ = false;
            }
        }
    } else // check for code browser navigation
    if ((navigation.getPath() != null) && navigation.getPath().startsWith(CodeBrowserEditingTarget.PATH)) {
        activateCodeBrowser(navigation.getPath(), false, new SourceNavigationResultCallback<CodeBrowserEditingTarget>(navigation.getPosition(), retryCommand));
    } else // check for file path navigation
    if ((navigation.getPath() != null) && !navigation.getPath().startsWith(DataItem.URI_PREFIX)) {
        FileSystemItem file = FileSystemItem.createFile(navigation.getPath());
        TextFileType fileType = fileTypeRegistry_.getTextTypeForFile(file);
        // open the file and restore the position
        openFile(file, fileType, new SourceNavigationResultCallback<EditingTarget>(navigation.getPosition(), retryCommand));
    } else {
        // couldn't navigate to this item, retry
        if (retryCommand.isEnabled())
            retryCommand.execute();
    }
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) TextFileType(org.rstudio.studio.client.common.filetypes.TextFileType) 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 4 with EditingTarget

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

the class Source method onNewRPresentationDoc.

@Handler
public void onNewRPresentationDoc() {
    dependencyManager_.withRMarkdown("Authoring R Presentations", new Command() {

        @Override
        public void execute() {
            fileDialogs_.saveFile("New R Presentation", fileContext_, workbenchContext_.getDefaultFileDialogDir(), ".Rpres", true, new ProgressOperationWithInput<FileSystemItem>() {

                @Override
                public void execute(final FileSystemItem input, final ProgressIndicator indicator) {
                    if (input == null) {
                        indicator.onCompleted();
                        return;
                    }
                    indicator.onProgress("Creating Presentation...");
                    server_.createNewPresentation(input.getPath(), new VoidServerRequestCallback(indicator) {

                        @Override
                        public void onSuccess() {
                            openFile(input, FileTypeRegistry.RPRESENTATION, new CommandWithArg<EditingTarget>() {

                                @Override
                                public void execute(EditingTarget arg) {
                                    server_.showPresentationPane(input.getPath(), new VoidServerRequestCallback());
                                }
                            });
                        }
                    });
                }
            });
        }
    });
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) Command(com.google.gwt.user.client.Command) AppCommand(org.rstudio.core.client.command.AppCommand) ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator) 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) VoidServerRequestCallback(org.rstudio.studio.client.server.VoidServerRequestCallback) ProgressOperationWithInput(org.rstudio.core.client.widget.ProgressOperationWithInput) 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 5 with EditingTarget

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

the class Source method closeAllLocalSourceDocs.

private void closeAllLocalSourceDocs(String caption, Command onCompleted, final boolean excludeActive) {
    // save active editor for exclusion (it changes as we close tabs)
    final EditingTarget activeEditor = activeEditor_;
    // collect up a list of dirty documents
    ArrayList<EditingTarget> dirtyTargets = new ArrayList<EditingTarget>();
    for (EditingTarget target : editors_) {
        if (excludeActive && target == activeEditor)
            continue;
        if (target.dirtyState().getValue())
            dirtyTargets.add(target);
    }
    // create a command used to close all tabs 
    final Command closeAllTabsCommand = new Command() {

        @Override
        public void execute() {
            cpsExecuteForEachEditor(editors_, new CPSEditingTargetCommand() {

                @Override
                public void execute(EditingTarget target, Command continuation) {
                    if (excludeActive && target == activeEditor) {
                        continuation.execute();
                        return;
                    } else {
                        view_.closeTab(target.asWidget(), false, continuation);
                    }
                }
            });
        }
    };
    // save targets
    saveEditingTargetsWithPrompt(caption, dirtyTargets, CommandUtil.join(closeAllTabsCommand, onCompleted), null);
}
Also used : ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) Command(com.google.gwt.user.client.Command) AppCommand(org.rstudio.core.client.command.AppCommand) 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) ArrayList(java.util.ArrayList)

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