Search in sources :

Example 71 with JsArrayString

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

the class AceCommandManager method rebindCommand.

public final void rebindCommand(String id, List<KeySequence> keys) {
    JsArrayString shortcuts = JavaScriptObject.createArray().cast();
    for (KeySequence ks : keys) shortcuts.push(toAceStyleShortcutString(ks));
    rebindCommand(id, shortcuts);
}
Also used : JsArrayString(com.google.gwt.core.client.JsArrayString) KeySequence(org.rstudio.core.client.command.KeyboardShortcut.KeySequence)

Example 72 with JsArrayString

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

the class SetupChunkOptionsPopupPanel method getChunkText.

private String getChunkText() {
    int chunkStart = position_.getRow();
    int chunkEnd = findEndOfChunk();
    JsArrayString chunkText = display_.getLines(chunkStart + 1, chunkEnd - 1);
    return chunkText.join("\n");
}
Also used : JsArrayString(com.google.gwt.core.client.JsArrayString)

Example 73 with JsArrayString

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

the class CheckSpelling method handleMisspelledWord.

private void handleMisspelledWord(Range range) {
    try {
        docDisplay_.setSelectionRange(range);
        docDisplay_.moveCursorNearTop();
        view_.clearSuggestions();
        view_.getReplacement().setText("");
        final String word = docDisplay_.getTextForRange(range);
        if (changeAll_.containsKey(word)) {
            doReplacement(changeAll_.get(word));
            findNextMisspelling();
            return;
        }
        view_.getMisspelledWord().setText(word);
        // This fixed delay is regrettable but necessary as it can take some
        // time for Ace's scrolling logic to actually execute (i.e. the next
        // time the renderloop runs). If we don't wait, then misspelled words
        // at the end of the document will result in misreported cursor bounds,
        // meaning we'll be avoiding a completely incorrect region.
        Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {

            @Override
            public boolean execute() {
                showDialog(docDisplay_.getCursorBounds());
                view_.focusReplacement();
                spellChecker_.suggestionList(word, new ServerRequestCallback<JsArrayString>() {

                    @Override
                    public void onResponseReceived(JsArrayString response) {
                        String[] suggestions = JsUtil.toStringArray(response);
                        view_.setSuggestions(suggestions);
                        if (suggestions.length > 0) {
                            view_.getReplacement().setText(suggestions[0]);
                            view_.focusReplacement();
                        }
                    }

                    @Override
                    public void onError(ServerError error) {
                        Debug.logError(error);
                    }
                });
                return false;
            }
        }, 100);
    } catch (Exception e) {
        Debug.log(e.toString());
        close();
        RStudioGinjector.INSTANCE.getGlobalDisplay().showErrorMessage("Check Spelling", "An error has occurred:\n\n" + e.getMessage());
        callback_.onFailure(e);
    }
}
Also used : ServerError(org.rstudio.studio.client.server.ServerError) RepeatingCommand(com.google.gwt.core.client.Scheduler.RepeatingCommand) ServerRequestCallback(org.rstudio.studio.client.server.ServerRequestCallback) JsArrayString(com.google.gwt.core.client.JsArrayString) JsArrayString(com.google.gwt.core.client.JsArrayString)

Example 74 with JsArrayString

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

the class ChooseEncodingDialog method setEncodings.

private void setEncodings(JsArrayString encodings, String encoding) {
    listBox_.clear();
    for (int i = 0; i < encodings.length(); i++) {
        listBox_.addItem(encodings.get(i));
    }
    int sysIndex = findSystemEncodingIndex();
    if (!StringUtil.isNullOrEmpty(systemEncoding_)) {
        // Remove the system encoding (if it is present) so we can move it
        // to the top of the list. If it's already present, use the same
        // label (un-normalized encoding name) so it's consistent with
        // related encodings that are also present in the list.
        String sysEncName = sysIndex < 0 ? systemEncoding_ : listBox_.getValue(sysIndex);
        if (sysIndex >= 0)
            listBox_.removeItem(sysIndex);
        listBox_.insertItem(sysEncName + " (System default)", systemEncoding_, 0);
    }
    if (includePromptForEncoding_) {
        listBox_.insertItem(ASK_LABEL, "", 0);
    }
    if (isSystemEncoding(encoding))
        setCurrentValue(listBox_.getValue(includePromptForEncoding_ ? 1 : 0));
    else
        setCurrentValue(encoding);
}
Also used : JsArrayString(com.google.gwt.core.client.JsArrayString)

Example 75 with JsArrayString

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

the class RnwChunkOptions method completeValue.

private void completeValue(RnwWeave rnwWeave, String name, String value, JsArrayString completions) {
    String optionType = StringUtil.notNull(this.getOptionType(name));
    if (optionType.equals("logical")) {
        CompletionOptions options = new CompletionOptions();
        options.addOption("TRUE", 0);
        options.addOption("FALSE", 0);
        if (!rnwWeave.usesCodeForOptions()) {
            // Legacy Sweave is case insensitive
            options.addOption("true", 1);
            options.addOption("false", 1);
            options.addOption("True", 2);
            options.addOption("False", 2);
        }
        for (String logical : options.getCompletions(value)) completions.push(logical);
    } else if (optionType.equals("list")) {
        CompletionOptions options = new CompletionOptions();
        ArrayList<String> optionValues = this.getOptionValues(name);
        if (!rnwWeave.usesCodeForOptions()) {
            // Legacy Sweave
            for (String optionVal : optionValues) options.addOption(optionVal, 0);
        } else {
            for (String optionVal : optionValues) options.addOption("'" + optionVal + "'", 0);
            for (String optionVal : optionValues) options.addOption('"' + optionVal + '"', 1);
        }
        for (String option : options.getCompletions(value)) completions.push(option);
    }
}
Also used : ArrayList(java.util.ArrayList) JsArrayString(com.google.gwt.core.client.JsArrayString) JSONString(com.google.gwt.json.client.JSONString)

Aggregations

JsArrayString (com.google.gwt.core.client.JsArrayString)86 ArrayList (java.util.ArrayList)15 JSONString (com.google.gwt.json.client.JSONString)5 Position (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position)5 ServerError (org.rstudio.studio.client.server.ServerError)4 JsArrayInteger (com.google.gwt.core.client.JsArrayInteger)3 Command (com.google.gwt.user.client.Command)3 List (java.util.List)3 KeySequence (org.rstudio.core.client.command.KeyboardShortcut.KeySequence)3 JsObject (org.rstudio.core.client.js.JsObject)3 RmdTemplateFormatOption (org.rstudio.studio.client.rmarkdown.model.RmdTemplateFormatOption)3 JsArrayBoolean (com.google.gwt.core.client.JsArrayBoolean)2 FlowPanel (com.google.gwt.user.client.ui.FlowPanel)2 Label (com.google.gwt.user.client.ui.Label)2 OperationException (org.eclipse.che.api.promises.client.OperationException)2 Handler (org.rstudio.core.client.command.Handler)2 EnsureHeightHandler (org.rstudio.core.client.events.EnsureHeightHandler)2 EnsureVisibleHandler (org.rstudio.core.client.events.EnsureVisibleHandler)2 ChangeFontSizeHandler (org.rstudio.studio.client.application.events.ChangeFontSizeHandler)2 RmdFrontMatterOutputOptions (org.rstudio.studio.client.rmarkdown.model.RmdFrontMatterOutputOptions)2