Search in sources :

Example 11 with Handler

use of org.rstudio.core.client.command.Handler 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 12 with Handler

use of org.rstudio.core.client.command.Handler in project rstudio by rstudio.

the class Source method onFindInFiles.

@Handler
public void onFindInFiles() {
    String searchPattern = "";
    if (activeEditor_ != null && activeEditor_ instanceof TextEditingTarget) {
        TextEditingTarget textEditor = (TextEditingTarget) activeEditor_;
        String selection = textEditor.getSelectedText();
        boolean multiLineSelection = selection.indexOf('\n') != -1;
        if ((selection.length() != 0) && !multiLineSelection)
            searchPattern = selection;
    }
    events_.fireEvent(new FindInFilesEvent(searchPattern));
}
Also used : FindInFilesEvent(org.rstudio.studio.client.workbench.views.output.find.events.FindInFilesEvent) TextEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget) JSONString(com.google.gwt.json.client.JSONString) JsArrayString(com.google.gwt.core.client.JsArrayString) 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 13 with Handler

use of org.rstudio.core.client.command.Handler in project rstudio by rstudio.

the class CodeSearchLauncher method onGoToFileFunction.

@Handler
public void onGoToFileFunction() {
    if (dialog_ != null)
        dialog_.closeDialog();
    dialog_ = new CodeSearchDialog(pCodeSearch_);
    dialog_.showModal();
}
Also used : CodeSearchDialog(org.rstudio.studio.client.workbench.codesearch.ui.CodeSearchDialog) Handler(org.rstudio.core.client.command.Handler)

Example 14 with Handler

use of org.rstudio.core.client.command.Handler 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 15 with Handler

use of org.rstudio.core.client.command.Handler 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

Handler (org.rstudio.core.client.command.Handler)55 ChangeFontSizeHandler (org.rstudio.studio.client.application.events.ChangeFontSizeHandler)20 EnsureHeightHandler (org.rstudio.core.client.events.EnsureHeightHandler)19 EnsureVisibleHandler (org.rstudio.core.client.events.EnsureVisibleHandler)19 FileChangeHandler (org.rstudio.studio.client.workbench.views.files.events.FileChangeHandler)18 HideMessageHandler (org.rstudio.studio.client.workbench.views.source.editors.text.status.StatusBar.HideMessageHandler)18 RecordNavigationPositionHandler (org.rstudio.studio.client.workbench.views.source.events.RecordNavigationPositionHandler)18 JsArrayString (com.google.gwt.core.client.JsArrayString)12 ProgressIndicator (org.rstudio.core.client.widget.ProgressIndicator)12 ValueChangeHandler (com.google.gwt.event.logical.shared.ValueChangeHandler)11 FileSystemItem (org.rstudio.core.client.files.FileSystemItem)10 VoidServerRequestCallback (org.rstudio.studio.client.server.VoidServerRequestCallback)9 CloseHandler (com.google.gwt.event.logical.shared.CloseHandler)8 SelectionHandler (com.google.gwt.event.logical.shared.SelectionHandler)8 Command (com.google.gwt.user.client.Command)8 ServerError (org.rstudio.studio.client.server.ServerError)7 InputEditorPosition (org.rstudio.studio.client.workbench.views.console.shell.editor.InputEditorPosition)7 NativePreviewHandler (com.google.gwt.user.client.Event.NativePreviewHandler)6 Breakpoint (org.rstudio.studio.client.common.debugging.model.Breakpoint)6 Position (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position)6