Search in sources :

Example 56 with JsArrayString

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

the class DomUtils method extractCssValue.

public static final String extractCssValue(String className, String propertyName) {
    JsArrayString classes = JsArrayString.createArray().cast();
    classes.push(className);
    return extractCssValue(classes, propertyName);
}
Also used : JsArrayString(com.google.gwt.core.client.JsArrayString)

Example 57 with JsArrayString

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

the class VirtualConsole method toString.

@Override
public String toString() {
    String output = output_.toString();
    int maxLength = prefs_.truncateLongLinesInConsoleHistory().getGlobalValue();
    if (maxLength == 0)
        return output;
    JsArrayString splat = StringUtil.split(output, "\n");
    for (int i = 0; i < splat.length(); i++) {
        String string = splat.get(i);
        String trimmed = StringUtil.trimRight(string);
        if (trimmed.length() > maxLength)
            splat.set(i, trimmed.substring(0, maxLength) + "... <truncated>");
        else if (string.length() > maxLength)
            splat.set(i, string.substring(0, maxLength));
    }
    String joined = splat.join("\n");
    return joined;
}
Also used : JsArrayString(com.google.gwt.core.client.JsArrayString) JsArrayString(com.google.gwt.core.client.JsArrayString)

Example 58 with JsArrayString

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

the class ModifyKeyboardShortcutsWidget method collectShortcuts.

private void collectShortcuts() {
    final List<KeyboardShortcutEntry> bindings = new ArrayList<KeyboardShortcutEntry>();
    SerializedCommandQueue queue = new SerializedCommandQueue();
    // Load addins discovered as part of package exports. This registers
    // the addin, with the actual keybinding to be registered later,
    // if discovered.
    queue.addCommand(new SerializedCommand() {

        @Override
        public void onExecute(final Command continuation) {
            RAddins rAddins = addins_.getRAddins();
            for (String key : JsUtil.asIterable(rAddins.keys())) {
                RAddin addin = rAddins.get(key);
                bindings.add(new KeyboardShortcutEntry(addin.getPackage() + "::" + addin.getBinding(), addin.getName(), new KeySequence(), KeyboardShortcutEntry.TYPE_ADDIN, false, AppCommand.Context.Addin));
            }
            continuation.execute();
        }
    });
    // Load saved addin bindings
    queue.addCommand(new SerializedCommand() {

        @Override
        public void onExecute(final Command continuation) {
            addins_.loadBindings(new CommandWithArg<EditorKeyBindings>() {

                @Override
                public void execute(EditorKeyBindings addinBindings) {
                    for (String commandId : addinBindings.iterableKeys()) {
                        EditorKeyBinding addinBinding = addinBindings.get(commandId);
                        for (KeyboardShortcutEntry binding : bindings) {
                            if (binding.getId() == commandId) {
                                List<KeySequence> keys = addinBinding.getKeyBindings();
                                if (keys.size() >= 1)
                                    binding.setDefaultKeySequence(keys.get(0));
                                if (keys.size() >= 2) {
                                    for (int i = 1; i < keys.size(); i++) {
                                        bindings.add(new KeyboardShortcutEntry(binding.getId(), binding.getName(), keys.get(i), KeyboardShortcutEntry.TYPE_ADDIN, false, AppCommand.Context.Addin));
                                    }
                                }
                            }
                        }
                    }
                    continuation.execute();
                }
            });
        }
    });
    // Ace loading command
    queue.addCommand(new SerializedCommand() {

        @Override
        public void onExecute(final Command continuation) {
            // Ace Commands
            JsArray<AceCommand> aceCommands = editorCommands_.getCommands();
            for (int i = 0; i < aceCommands.length(); i++) {
                AceCommand command = aceCommands.get(i);
                JsArrayString shortcuts = command.getBindingsForCurrentPlatform();
                if (shortcuts != null) {
                    String id = command.getInternalName();
                    String name = command.getDisplayName();
                    boolean custom = command.isCustomBinding();
                    for (int j = 0; j < shortcuts.length(); j++) {
                        String shortcut = shortcuts.get(j);
                        KeySequence keys = KeySequence.fromShortcutString(shortcut);
                        int type = KeyboardShortcutEntry.TYPE_EDITOR_COMMAND;
                        bindings.add(new KeyboardShortcutEntry(id, name, keys, type, custom, AppCommand.Context.Editor));
                    }
                }
            }
            continuation.execute();
        }
    });
    // RStudio commands
    queue.addCommand(new SerializedCommand() {

        @Override
        public void onExecute(final Command continuation) {
            // RStudio Commands
            appCommands_.loadBindings(new CommandWithArg<EditorKeyBindings>() {

                @Override
                public void execute(final EditorKeyBindings customBindings) {
                    Map<String, AppCommand> commands = commands_.getCommands();
                    for (Map.Entry<String, AppCommand> entry : commands.entrySet()) {
                        AppCommand command = entry.getValue();
                        if (isExcludedCommand(command))
                            continue;
                        String id = command.getId();
                        String name = getAppCommandName(command);
                        int type = KeyboardShortcutEntry.TYPE_RSTUDIO_COMMAND;
                        boolean isCustom = customBindings.hasKey(id);
                        List<KeySequence> keySequences = new ArrayList<KeySequence>();
                        if (isCustom)
                            keySequences = customBindings.get(id).getKeyBindings();
                        else
                            keySequences.add(command.getKeySequence());
                        for (KeySequence keys : keySequences) {
                            KeyboardShortcutEntry binding = new KeyboardShortcutEntry(id, name, keys, type, isCustom, command.getContext());
                            bindings.add(binding);
                        }
                    }
                    continuation.execute();
                }
            });
        }
    });
    // Sort and finish up
    queue.addCommand(new SerializedCommand() {

        @Override
        public void onExecute(final Command continuation) {
            Collections.sort(bindings, new Comparator<KeyboardShortcutEntry>() {

                @Override
                public int compare(KeyboardShortcutEntry o1, KeyboardShortcutEntry o2) {
                    if (o1.getContext() != o2.getContext())
                        return o1.getContext().compareTo(o2.getContext());
                    return o1.getName().compareTo(o2.getName());
                }
            });
            originalBindings_ = bindings;
            updateData(bindings);
            continuation.execute();
        }
    });
    queue.addCommand(new SerializedCommand() {

        @Override
        public void onExecute(Command continuation) {
            if (initialFilterText_ != null) {
                filterWidget_.setText(initialFilterText_);
                filter();
            }
            continuation.execute();
        }
    });
    // Exhaust the queue
    queue.run();
}
Also used : SerializedCommand(org.rstudio.core.client.SerializedCommand) RAddins(org.rstudio.studio.client.workbench.addins.Addins.RAddins) SerializedCommandQueue(org.rstudio.core.client.SerializedCommandQueue) ArrayList(java.util.ArrayList) JsArrayString(com.google.gwt.core.client.JsArrayString) CommandWithArg(org.rstudio.core.client.CommandWithArg) Comparator(java.util.Comparator) EditorKeyBinding(org.rstudio.core.client.command.EditorCommandManager.EditorKeyBinding) EditorKeyBindings(org.rstudio.core.client.command.EditorCommandManager.EditorKeyBindings) JsArray(com.google.gwt.core.client.JsArray) RAddin(org.rstudio.studio.client.workbench.addins.Addins.RAddin) JsArrayString(com.google.gwt.core.client.JsArrayString) Command(com.google.gwt.user.client.Command) SerializedCommand(org.rstudio.core.client.SerializedCommand) AceCommand(org.rstudio.studio.client.workbench.views.source.editors.text.ace.AceCommand) AceCommand(org.rstudio.studio.client.workbench.views.source.editors.text.ace.AceCommand) KeySequence(org.rstudio.core.client.command.KeyboardShortcut.KeySequence) Map(java.util.Map) HashMap(java.util.HashMap)

Example 59 with JsArrayString

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

the class RoxygenHelper method amendExistingRoxygenBlock.

private void amendExistingRoxygenBlock(int row, String objectName, JsArrayString argNames, JsArrayString argTypes, String tagName, Pattern pattern) {
    // Get the range encompassing this Roxygen block.
    Range range = getRoxygenBlockRange(row);
    // Extract that block (as an array of strings)
    JsArrayString block = extractRoxygenBlock(editor_.getWidget().getEditor(), range);
    // bail.
    for (int i = 0; i < block.length(); i++) {
        if (RE_ROXYGEN_NONLOCAL.test(block.get(i))) {
            view_.showWarningBar("Cannot automatically update roxygen blocks " + "that are not self-contained.");
            return;
        }
    }
    String roxygenDelim = RE_ROXYGEN.match(block.get(0), 0).getGroup(1);
    // The replacement block (we build by munging parts of
    // the old block
    JsArrayString replacement = JsArray.createArray().cast();
    // Scan through the block to get the names of
    // pre-existing parameters.
    JsArrayString params = listParametersInRoxygenBlock(block, pattern);
    // Figure out what parameters need to be removed, and remove them.
    // Any parameter not mentioned in the current function's argument list
    // should be stripped out.
    JsArrayString paramsToRemove = setdiff(params, argNames);
    int blockLength = block.length();
    for (int i = 0; i < blockLength; i++) {
        // If we encounter a param we don't want to extract, then
        // move over it.
        Match match = pattern.match(block.get(i), 0);
        if (match != null && contains(paramsToRemove, match.getGroup(1))) {
            i++;
            while (i < blockLength && !RE_ROXYGEN_WITH_TAG.test(block.get(i))) i++;
            i--;
            continue;
        }
        replacement.push(block.get(i));
    }
    // Now, add example roxygen for any parameters that are
    // present in the function prototype, but not present
    // within the roxygen block.
    int insertionPosition = findParamsInsertionPosition(replacement, pattern);
    JsArrayInteger indices = setdiffIndices(argNames, params);
    // NOTE: modifies replacement
    insertNewTags(replacement, argNames, argTypes, indices, roxygenDelim, tagName, insertionPosition);
    // Ensure space between final param and next tag
    ensureSpaceBetweenFirstParamAndPreviousEntry(replacement, roxygenDelim, pattern);
    ensureSpaceBetweenFinalParamAndNextTag(replacement, roxygenDelim, pattern);
    // Apply the replacement.
    editor_.getSession().replace(range, replacement.join("\n") + "\n");
}
Also used : JsArrayInteger(com.google.gwt.core.client.JsArrayInteger) JsArrayString(com.google.gwt.core.client.JsArrayString) JsArrayString(com.google.gwt.core.client.JsArrayString) Range(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Range) Match(org.rstudio.core.client.regex.Match)

Example 60 with JsArrayString

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

the class LatexProgramRegistry method getTypes.

public ArrayList<String> getTypes() {
    if (latexProgramTypes_ == null) {
        JsArrayString types = pSession_.get().getSessionInfo().getLatexProgramTypes();
        latexProgramTypes_ = new ArrayList<String>();
        for (int i = 0; i < types.length(); i++) latexProgramTypes_.add(types.get(i));
    }
    return latexProgramTypes_;
}
Also used : JsArrayString(com.google.gwt.core.client.JsArrayString) JsArrayString(com.google.gwt.core.client.JsArrayString)

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