Search in sources :

Example 1 with TextEditingTarget

use of org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget in project rstudio by rstudio.

the class Source method onGetEditorContext.

@Override
public void onGetEditorContext(GetEditorContextEvent event) {
    GetEditorContextEvent.Data data = event.getData();
    int type = data.getType();
    if (type == GetEditorContextEvent.TYPE_ACTIVE_EDITOR) {
        if (consoleEditorHadFocusLast() || activeEditor_ == null)
            type = GetEditorContextEvent.TYPE_CONSOLE_EDITOR;
        else
            type = GetEditorContextEvent.TYPE_SOURCE_EDITOR;
    }
    if (type == GetEditorContextEvent.TYPE_CONSOLE_EDITOR) {
        InputEditorDisplay editor = consoleEditorProvider_.getConsoleEditor();
        if (editor != null && editor instanceof DocDisplay) {
            getEditorContext("#console", "", (DocDisplay) editor);
            return;
        }
    } else if (type == GetEditorContextEvent.TYPE_SOURCE_EDITOR) {
        EditingTarget target = activeEditor_;
        if (target != null && target instanceof TextEditingTarget) {
            getEditorContext(target.getId(), target.getPath(), ((TextEditingTarget) target).getDocDisplay());
            return;
        }
    }
    // We need to ensure a 'getEditorContext' event is always
    // returned as we have a 'wait-for' event on the server side
    server_.getEditorContextCompleted(GetEditorContextEvent.SelectionData.create(), new VoidServerRequestCallback());
}
Also used : InputEditorDisplay(org.rstudio.studio.client.workbench.views.console.shell.editor.InputEditorDisplay) GetEditorContextEvent(org.rstudio.studio.client.events.GetEditorContextEvent) 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) TextEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget) VoidServerRequestCallback(org.rstudio.studio.client.server.VoidServerRequestCallback) DocDisplay(org.rstudio.studio.client.workbench.views.source.editors.text.DocDisplay)

Example 2 with TextEditingTarget

use of org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget in project rstudio by rstudio.

the class Source method saveActiveSourceDoc.

private void saveActiveSourceDoc() {
    if (activeEditor_ != null && activeEditor_ instanceof TextEditingTarget) {
        TextEditingTarget target = (TextEditingTarget) activeEditor_;
        target.save();
    }
}
Also used : TextEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget)

Example 3 with TextEditingTarget

use of org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget 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 4 with TextEditingTarget

use of org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget in project rstudio by rstudio.

the class Source method dispatchEditorEvent.

private void dispatchEditorEvent(final String id, final CommandWithArg<DocDisplay> command) {
    InputEditorDisplay console = consoleEditorProvider_.getConsoleEditor();
    boolean isConsoleEvent = false;
    if (console != null) {
        isConsoleEvent = (StringUtil.isNullOrEmpty(id) && console.isFocused()) || "#console".equals(id);
    }
    if (isConsoleEvent) {
        command.execute((DocDisplay) console);
    } else {
        withTarget(id, new CommandWithArg<TextEditingTarget>() {

            @Override
            public void execute(TextEditingTarget target) {
                command.execute(target.getDocDisplay());
            }
        });
    }
}
Also used : InputEditorDisplay(org.rstudio.studio.client.workbench.views.console.shell.editor.InputEditorDisplay) TextEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget)

Example 5 with TextEditingTarget

use of org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget in project rstudio by rstudio.

the class Source method reflowText.

private void reflowText() {
    if (activeEditor_ != null && activeEditor_ instanceof TextEditingTarget) {
        TextEditingTarget editor = (TextEditingTarget) activeEditor_;
        editor.reflowText();
    }
}
Also used : TextEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget)

Aggregations

TextEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget)13 EditingTarget (org.rstudio.studio.client.workbench.views.source.editors.EditingTarget)5 CodeBrowserEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.codebrowser.CodeBrowserEditingTarget)5 DataEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.data.DataEditingTarget)5 ServerError (org.rstudio.studio.client.server.ServerError)4 JsArrayString (com.google.gwt.core.client.JsArrayString)2 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)2 JSONString (com.google.gwt.json.client.JSONString)2 Command (com.google.gwt.user.client.Command)2 AppCommand (org.rstudio.core.client.command.AppCommand)2 VoidServerRequestCallback (org.rstudio.studio.client.server.VoidServerRequestCallback)2 InputEditorDisplay (org.rstudio.studio.client.workbench.views.console.shell.editor.InputEditorDisplay)2 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)1 CloseHandler (com.google.gwt.event.logical.shared.CloseHandler)1 SelectionHandler (com.google.gwt.event.logical.shared.SelectionHandler)1 ValueChangeHandler (com.google.gwt.event.logical.shared.ValueChangeHandler)1 NativePreviewHandler (com.google.gwt.user.client.Event.NativePreviewHandler)1 Handler (org.rstudio.core.client.command.Handler)1 EditableFileType (org.rstudio.studio.client.common.filetypes.EditableFileType)1 OpenSourceFileHandler (org.rstudio.studio.client.common.filetypes.events.OpenSourceFileHandler)1