Search in sources :

Example 6 with ScheduledCommand

use of com.google.gwt.core.client.Scheduler.ScheduledCommand in project rstudio by rstudio.

the class RSConnectDeploy method populateDeploymentFiles.

private void populateDeploymentFiles(final ProgressIndicator indicator) {
    if (source_ == null)
        return;
    // dependencies; just inject it directly into the list.
    if (source_.isSelfContained() && source_.isStatic() && !source_.isWebsiteRmd()) {
        ArrayList<String> files = new ArrayList<String>();
        FileSystemItem selfContained = FileSystemItem.createFile(source_.getDeployFile());
        files.add(selfContained.getName());
        setFileList(files, null, null);
        setPrimaryFile(selfContained.getName());
        return;
    }
    // ternery operator maps to appropriate files to list for deployment:
    // website code    - website code directory 
    // static website  - website build directory
    // document        - R Markdown document
    // non-document    - Shiny app directory
    final String fileSource = source_.isDocument() ? source_.isWebsiteRmd() ? source_.isStatic() ? source_.getDeployDir() : source_.getWebsiteDir() : source_.getDeployFile() : source_.getDeployDir();
    indicator.onProgress("Collecting files...");
    server_.getDeploymentFiles(fileSource, asMultipleRmd_, new ServerRequestCallback<RSConnectDeploymentFiles>() {

        @Override
        public void onResponseReceived(RSConnectDeploymentFiles files) {
            if (files.getDirSize() > files.getMaxSize()) {
                indicator.onError("The item to be deployed (" + fileSource + ") " + "exceeds the maximum deployment size, which is " + StringUtil.formatFileSize(files.getMaxSize()) + "." + " Consider creating a new directory containing " + "only the content you wish to deploy.");
            } else {
                if (files.getDirList() == null || files.getDirList().length() == 0) {
                    indicator.onError("Could not determine the list of " + "files to deploy.");
                    indicator.onCompleted();
                }
                setFileList(JsArrayUtil.fromJsArrayString(files.getDirList()), fromPrevious_ != null ? fromPrevious_.getAdditionalFiles() : null, fromPrevious_ != null ? fromPrevious_.getIgnoredFiles() : null);
                if (!source_.isWebsiteRmd())
                    setPrimaryFile(FileSystemItem.createFile(source_.getDeployFile()).getName());
            }
            Scheduler.get().scheduleDeferred(new ScheduledCommand() {

                @Override
                public void execute() {
                    indicator.clearProgress();
                }
            });
        }

        @Override
        public void onError(ServerError error) {
            // we need to have a list of files to deploy to proceed
            indicator.onError("Could not find files to deploy: \n\n" + error.getMessage());
            indicator.onCompleted();
        }
    });
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) ServerError(org.rstudio.studio.client.server.ServerError) ArrayList(java.util.ArrayList) RSConnectDeploymentFiles(org.rstudio.studio.client.rsconnect.model.RSConnectDeploymentFiles)

Example 7 with ScheduledCommand

use of com.google.gwt.core.client.Scheduler.ScheduledCommand in project rstudio by rstudio.

the class ConsolePane method setProfilerMode.

@Override
public void setProfilerMode(boolean profilerMode) {
    profilerMode_ = profilerMode;
    loadDebugToolsIntoSecondaryToolbar();
    Scheduler.get().scheduleFinally(new ScheduledCommand() {

        public void execute() {
            ensureCursorVisible();
        }
    });
}
Also used : ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand)

Example 8 with ScheduledCommand

use of com.google.gwt.core.client.Scheduler.ScheduledCommand in project rstudio by rstudio.

the class RCompletionManager method previewKeyPress.

public boolean previewKeyPress(char c) {
    suggestTimer_.cancel();
    if (isDisabled())
        return false;
    if (popup_.isShowing()) {
        // If insertion of this character completes an available suggestion,
        // and is not a prefix match of any other suggestion, then implicitly
        // apply that.
        QualifiedName selectedItem = popup_.getSelectedValue();
        // can also dismiss the popup on a perfect match of <foo>.
        if (selectedItem != null && selectedItem.name.replaceAll(":", "").equals(token_ + c)) {
            String fullToken = token_ + c;
            // Find prefix matches -- there should only be one if we really
            // want this behaviour (ie the current selection)
            int prefixMatchCount = 0;
            QualifiedName[] items = popup_.getItems();
            for (int i = 0; i < items.length; i++) {
                if (items[i].name.startsWith(fullToken)) {
                    ++prefixMatchCount;
                    if (prefixMatchCount > 1)
                        break;
                }
            }
            if (prefixMatchCount == 1) {
                // We place the completion list offscreen to ensure that
                // backspace events are handled later. 
                popup_.placeOffscreen();
                return false;
            }
        }
        if (c == ':') {
            suggestTimer_.schedule(false, true, false);
            return false;
        }
        if (c == ' ')
            return false;
        // Always update the current set of completions following
        // a key insertion. Defer execution so the key insertion can
        // enter the document.
        Scheduler.get().scheduleDeferred(new ScheduledCommand() {

            @Override
            public void execute() {
                beginSuggest(false, true, false);
            }
        });
        return false;
    } else {
        // Bail if we're not in R mode
        if (!DocumentMode.isCursorInRMode(docDisplay_))
            return false;
        // Bail if we're in a single-line string
        if (docDisplay_.isCursorInSingleLineString())
            return false;
        // if there's a selection, bail
        if (input_.hasSelection())
            return false;
        // following the cursor
        if (isValidForRIdentifier(docDisplay_.getCharacterAtCursor()))
            return false;
        // Perform an auto-popup if a set number of R identifier characters
        // have been inserted (but only if the user has allowed it in prefs)
        boolean autoPopupEnabled = uiPrefs_.codeComplete().getValue().equals(UIPrefsAccessor.COMPLETION_ALWAYS);
        if (!autoPopupEnabled)
            return false;
        // Immediately display completions after '$', '::', etc.
        char prevChar = docDisplay_.getCurrentLine().charAt(input_.getCursorPosition().getColumn() - 1);
        if ((c == ':' && prevChar == ':') || (c == '$') || (c == '@')) {
            // Bail if we're in Vim but not in insert mode
            if (docDisplay_.isVimModeOn() && !docDisplay_.isVimInInsertMode()) {
                return false;
            }
            Scheduler.get().scheduleDeferred(new ScheduledCommand() {

                @Override
                public void execute() {
                    beginSuggest(true, true, false);
                }
            });
            return false;
        }
        // Check for a valid number of R identifier characters for autopopup
        boolean canAutoPopup = checkCanAutoPopup(c, uiPrefs_.alwaysCompleteCharacters().getValue() - 1);
        // Attempt to pop up completions immediately after a function call.
        if (c == '(' && !isLineInComment(docDisplay_.getCurrentLine())) {
            String token = StringUtil.getToken(docDisplay_.getCurrentLine(), input_.getCursorPosition().getColumn(), "[" + RegexUtil.wordCharacter() + "._]", false, true);
            if (token.matches("^(library|require|requireNamespace|data)\\s*$"))
                canAutoPopup = true;
            sigTipManager_.resolveActiveFunctionAndDisplayToolTip();
        }
        if ((canAutoPopup) || isSweaveCompletion(c)) {
            // Delay suggestion to avoid auto-popup while the user is typing
            suggestTimer_.schedule(true, true, false);
        }
    }
    return false;
}
Also used : ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) QualifiedName(org.rstudio.studio.client.workbench.views.console.shell.assist.CompletionRequester.QualifiedName)

Example 9 with ScheduledCommand

use of com.google.gwt.core.client.Scheduler.ScheduledCommand in project rstudio by rstudio.

the class RequestLogVisualization method onLoad.

@Override
protected void onLoad() {
    super.onLoad();
    Scheduler.get().scheduleDeferred(new ScheduledCommand() {

        public void execute() {
            scrollPanel_.scrollToTop();
            scrollPanel_.scrollToRight();
        }
    });
}
Also used : ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand)

Example 10 with ScheduledCommand

use of com.google.gwt.core.client.Scheduler.ScheduledCommand in project rstudio by rstudio.

the class MathJax method renderLatexLineWidget.

private void renderLatexLineWidget(LineWidget widget, final Range range, final String text, final MathJaxTypesetCallback callback) {
    final Element el = DomUtils.getFirstElementWithClassName(widget.getElement(), MATHJAX_ROOT_CLASSNAME);
    // call 'onLineWidgetChanged' to ensure the widget is attached
    docDisplay_.onLineWidgetChanged(widget);
    // defer typesetting just to ensure that the widget has actually been
    // attached to the DOM
    final LineWidget lineWidget = widget;
    Scheduler.get().scheduleDeferred(new ScheduledCommand() {

        @Override
        public void execute() {
            mathjaxTypeset(el, text, new MathJaxTypesetCallback() {

                @Override
                public void onMathJaxTypesetComplete(final boolean error) {
                    // force expansion
                    withExpandedLineWidget(lineWidget, new CommandWithArg<Boolean>() {

                        @Override
                        public void execute(Boolean stateChanged) {
                            // re-position the element
                            int height = el.getOffsetHeight() + 30;
                            Element ppElement = el.getParentElement().getParentElement();
                            ppElement.getStyle().setHeight(height, Unit.PX);
                            docDisplay_.onLineWidgetChanged(lineWidget);
                            // invoke supplied callback
                            if (callback != null)
                                callback.onMathJaxTypesetComplete(error);
                        }
                    });
                }
            });
        }
    });
}
Also used : ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) Element(com.google.gwt.dom.client.Element) PinnedLineWidget(org.rstudio.studio.client.workbench.views.source.editors.text.PinnedLineWidget) LineWidget(org.rstudio.studio.client.workbench.views.source.editors.text.ace.LineWidget)

Aggregations

ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)104 Position (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position)7 Element (com.google.gwt.dom.client.Element)6 Range (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Range)6 JsArray (com.google.gwt.core.client.JsArray)5 Command (com.google.gwt.user.client.Command)5 ServerError (org.rstudio.studio.client.server.ServerError)5 JsArrayString (com.google.gwt.core.client.JsArrayString)4 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 FileSystemItem (org.rstudio.core.client.files.FileSystemItem)4 RepeatingCommand (com.google.gwt.core.client.Scheduler.RepeatingCommand)3 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)3 Event (com.google.gwt.user.client.Event)3 NativePreviewHandler (com.google.gwt.user.client.Event.NativePreviewHandler)3 Timer (com.google.gwt.user.client.Timer)3 WindowEx (org.rstudio.core.client.dom.WindowEx)3 SourcePosition (org.rstudio.studio.client.workbench.views.source.model.SourcePosition)3 ErrorDialog (com.google.gerrit.client.ErrorDialog)2 OnEditEnabler (com.google.gerrit.client.ui.OnEditEnabler)2