Search in sources :

Example 36 with JsArrayString

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

the class ManipulatorPopupPanel method update.

public void update(Manipulator manipulator) {
    mainPanel_.clear();
    if (manipulator != null && manipulator.getVariables() != null) {
        // iterate over the variables
        JsArrayString variables = manipulator.getVariables();
        for (int i = 0; i < variables.length(); i++) {
            String variable = variables.get(i);
            try {
                ManipulatorControl addedControl = null;
                Manipulator.Control control = manipulator.getControl(variable);
                switch(control.getType()) {
                    case Manipulator.Control.SLIDER:
                        Manipulator.Slider slider = control.cast();
                        addedControl = addSliderControl(variable, manipulator.getDoubleValue(variable), slider);
                        break;
                    case Manipulator.Control.PICKER:
                        Manipulator.Picker picker = control.cast();
                        addedControl = addPickerControl(variable, manipulator.getStringValue(variable), picker);
                        break;
                    case Manipulator.Control.CHECKBOX:
                        Manipulator.CheckBox checkBox = control.cast();
                        addedControl = addCheckBoxControl(variable, manipulator.getBooleanValue(variable), checkBox);
                        break;
                    case Manipulator.Control.BUTTON:
                        Manipulator.Button button = control.cast();
                        addedControl = addButtonControl(variable, button);
                        break;
                }
                // save reference to first control (for setting focus)
                if (i == 0)
                    firstControl_ = addedControl;
            } catch (Throwable e) {
                Debug.log("WARNING: exception occurred during addition of " + "variable " + variable + ", " + e.getMessage());
            }
        }
    }
}
Also used : JsArrayString(com.google.gwt.core.client.JsArrayString) JsArrayString(com.google.gwt.core.client.JsArrayString) Manipulator(org.rstudio.studio.client.workbench.views.plots.model.Manipulator)

Example 37 with JsArrayString

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

the class Source method openProjectDocs.

private void openProjectDocs(final Session session) {
    JsArrayString openDocs = session.getSessionInfo().getProjectOpenDocs();
    if (openDocs.length() > 0) {
        // set new tab pending for the duration of the continuation
        newTabPending_++;
        // create a continuation for opening the source docs
        SerializedCommandQueue openCommands = new SerializedCommandQueue();
        for (int i = 0; i < openDocs.length(); i++) {
            String doc = openDocs.get(i);
            final FileSystemItem fsi = FileSystemItem.createFile(doc);
            openCommands.addCommand(new SerializedCommand() {

                @Override
                public void onExecute(final Command continuation) {
                    openFile(fsi, fileTypeRegistry_.getTextTypeForFile(fsi), new CommandWithArg<EditingTarget>() {

                        @Override
                        public void execute(EditingTarget arg) {
                            continuation.execute();
                        }
                    });
                }
            });
        }
        // decrement newTabPending and select first tab when done
        openCommands.addCommand(new SerializedCommand() {

            @Override
            public void onExecute(Command continuation) {
                newTabPending_--;
                onFirstTab();
                continuation.execute();
            }
        });
        // execute the continuation
        openCommands.run();
    }
}
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) 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) JsArrayString(com.google.gwt.core.client.JsArrayString) JSONString(com.google.gwt.json.client.JSONString) JsArrayString(com.google.gwt.core.client.JsArrayString)

Example 38 with JsArrayString

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

the class IgnoredUpdates method addIgnoredUpdate.

public final void addIgnoredUpdate(String update) {
    JsArrayString newUpdateList = create().getIgnoredUpdates();
    JsArrayString existingUpdateList = getIgnoredUpdates();
    for (int i = 0; i < existingUpdateList.length(); i++) {
        // we're about to add.
        if (ApplicationUtils.compareVersions(update, existingUpdateList.get(i)) < 0) {
            newUpdateList.push(existingUpdateList.get(i));
        }
    }
    newUpdateList.push(update);
    setIgnoredUpdates(newUpdateList);
}
Also used : JsArrayString(com.google.gwt.core.client.JsArrayString)

Example 39 with JsArrayString

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

the class TextEditingTarget method onExtractLocalVariable.

@Handler
void onExtractLocalVariable() {
    if (!isCursorInRMode()) {
        showRModeWarning("Extract Variable");
        return;
    }
    docDisplay_.focus();
    String initialSelection = docDisplay_.getSelectionValue();
    final String refactoringName = "Extract local variable";
    final String pleaseSelectCodeMessage = "Please select the code to " + "extract into a variable.";
    if (checkSelectionAndAlert(refactoringName, pleaseSelectCodeMessage, initialSelection))
        return;
    docDisplay_.fitSelectionToLines(false);
    final String code = docDisplay_.getSelectionValue();
    if (checkSelectionAndAlert(refactoringName, pleaseSelectCodeMessage, code))
        return;
    // get the first line of the selection and calculate it's indentation
    String firstLine = docDisplay_.getLine(docDisplay_.getSelectionStart().getRow());
    final String indentation = extractIndentation(firstLine);
    // used to parse the code
    server_.detectFreeVars(code, new RefactorServerRequestCallback(refactoringName) {

        @Override
        void doExtract(JsArrayString response) {
            globalDisplay_.promptForText(refactoringName, "Variable Name", "", new OperationWithInput<String>() {

                public void execute(String input) {
                    final String extractedCode = indentation + input.trim() + " <- " + code + "\n";
                    InputEditorPosition insertPosition = docDisplay_.getSelection().extendToLineStart().getStart();
                    docDisplay_.replaceSelection(input.trim());
                    docDisplay_.insertCode(insertPosition, extractedCode);
                }
            });
        }
    });
}
Also used : JsArrayString(com.google.gwt.core.client.JsArrayString) JsArrayString(com.google.gwt.core.client.JsArrayString) InputEditorPosition(org.rstudio.studio.client.workbench.views.console.shell.editor.InputEditorPosition) Handler(org.rstudio.core.client.command.Handler) ChangeFontSizeHandler(org.rstudio.studio.client.application.events.ChangeFontSizeHandler) RecordNavigationPositionHandler(org.rstudio.studio.client.workbench.views.source.events.RecordNavigationPositionHandler) EnsureHeightHandler(org.rstudio.core.client.events.EnsureHeightHandler) EnsureVisibleHandler(org.rstudio.core.client.events.EnsureVisibleHandler) HideMessageHandler(org.rstudio.studio.client.workbench.views.source.editors.text.status.StatusBar.HideMessageHandler) FileChangeHandler(org.rstudio.studio.client.workbench.views.files.events.FileChangeHandler)

Example 40 with JsArrayString

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

the class TextEditingTarget method onExtractFunction.

@Handler
void onExtractFunction() {
    if (!isCursorInRMode()) {
        showRModeWarning("Extract Function");
        return;
    }
    docDisplay_.focus();
    String initialSelection = docDisplay_.getSelectionValue();
    final String refactoringName = "Extract Function";
    final String pleaseSelectCodeMessage = "Please select the code to " + "extract into a function.";
    if (checkSelectionAndAlert(refactoringName, pleaseSelectCodeMessage, initialSelection))
        return;
    docDisplay_.fitSelectionToLines(false);
    final String code = docDisplay_.getSelectionValue();
    if (checkSelectionAndAlert(refactoringName, pleaseSelectCodeMessage, code))
        return;
    final String indentation = extractIndentation(code);
    server_.detectFreeVars(code, new RefactorServerRequestCallback(refactoringName) {

        @Override
        void doExtract(final JsArrayString response) {
            globalDisplay_.promptForText(refactoringName, "Function Name", "", new OperationWithInput<String>() {

                public void execute(String input) {
                    String prefix;
                    if (docDisplay_.getSelectionOffset(true) == 0)
                        prefix = "";
                    else
                        prefix = "\n";
                    String args = response != null ? response.join(", ") : "";
                    docDisplay_.replaceSelection(prefix + indentation + input.trim() + " <- " + "function(" + args + ") {\n" + StringUtil.indent(code, "  ") + "\n" + indentation + "}");
                }
            });
        }
    });
}
Also used : JsArrayString(com.google.gwt.core.client.JsArrayString) JsArrayString(com.google.gwt.core.client.JsArrayString) Handler(org.rstudio.core.client.command.Handler) ChangeFontSizeHandler(org.rstudio.studio.client.application.events.ChangeFontSizeHandler) RecordNavigationPositionHandler(org.rstudio.studio.client.workbench.views.source.events.RecordNavigationPositionHandler) EnsureHeightHandler(org.rstudio.core.client.events.EnsureHeightHandler) EnsureVisibleHandler(org.rstudio.core.client.events.EnsureVisibleHandler) HideMessageHandler(org.rstudio.studio.client.workbench.views.source.editors.text.status.StatusBar.HideMessageHandler) FileChangeHandler(org.rstudio.studio.client.workbench.views.files.events.FileChangeHandler)

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