Search in sources :

Example 1 with CursorChangedEvent

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

the class ConnectionCodePanel method setCode.

public void setCode(String code, String connectVia) {
    settingCode_ = true;
    // clear existing code viewer
    if (codeViewer_ != null) {
        codeViewer_.removeFromParent();
        codeViewer_ = null;
    }
    // create new code viewer
    codeViewer_ = new AceEditorWidget(false);
    codeViewer_.addStyleName(RES.styles().codeViewer());
    codeViewer_.getEditor().getSession().setEditorMode(EditorLanguage.LANG_R.getParserName(), false);
    codeViewer_.getEditor().getSession().setUseWrapMode(true);
    codeViewer_.getEditor().getRenderer().setShowGutter(false);
    codeViewer_.getEditor().setReadOnly(false);
    codeViewer_.addCursorChangedHandler(new CursorChangedHandler() {

        @Override
        public void onCursorChanged(CursorChangedEvent event) {
            EditSession session = codeViewer_.getEditor().getSession();
            String selectedCode = session.getTextRange(session.getSelection().getRange());
            if (!settingCode_ && selectedCode.trim().equals(session.getValue().trim())) {
                setConnectVia(ConnectionOptions.CONNECT_COPY_TO_CLIPBOARD);
            }
        }
    });
    codeViewer_.setCode(code);
    container_.add(codeViewer_);
    // update connectVia
    if (connectVia != null) {
        setConnectVia(connectVia);
        updateConnectViaUI_.execute();
    }
    onResize();
    settingCode_ = false;
}
Also used : CursorChangedHandler(org.rstudio.studio.client.workbench.views.source.editors.text.events.CursorChangedHandler) EditSession(org.rstudio.studio.client.workbench.views.source.editors.text.ace.EditSession) AceEditorWidget(org.rstudio.studio.client.workbench.views.source.editors.text.AceEditorWidget) CursorChangedEvent(org.rstudio.studio.client.workbench.views.source.editors.text.events.CursorChangedEvent)

Example 2 with CursorChangedEvent

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

the class MathJax method beginCursorMonitoring.

private void beginCursorMonitoring() {
    endCursorMonitoring();
    cursorChangedHandler_ = docDisplay_.addCursorChangedHandler(new CursorChangedHandler() {

        @Override
        public void onCursorChanged(CursorChangedEvent event) {
            Position position = event.getPosition();
            if (anchor_ == null || !anchor_.getRange().contains(position))
                endRender();
        }
    });
}
Also used : Position(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position) CursorChangedHandler(org.rstudio.studio.client.workbench.views.source.editors.text.events.CursorChangedHandler) CursorChangedEvent(org.rstudio.studio.client.workbench.views.source.editors.text.events.CursorChangedEvent)

Example 3 with CursorChangedEvent

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

the class TextEditingTargetIdleMonitor method beginMonitoring.

public void beginMonitoring() {
    endMonitoring();
    monitors_.add(display_.addEditorModeChangedHandler(new EditorModeChangedEvent.Handler() {

        @Override
        public void onEditorModeChanged(EditorModeChangedEvent event) {
            Scheduler.get().scheduleDeferred(new ScheduledCommand() {

                @Override
                public void execute() {
                    refreshCommands();
                }
            });
        }
    }));
    monitors_.add(display_.addCursorChangedHandler(new CursorChangedHandler() {

        @Override
        public void onCursorChanged(CursorChangedEvent event) {
            mouseMovedLast_ = false;
            timer_.schedule(DELAY_MS);
        }
    }));
    monitors_.add(display_.addAttachHandler(new AttachEvent.Handler() {

        @Override
        public void onAttachOrDetach(AttachEvent event) {
            if (!event.isAttached())
                onDetach();
        }
    }));
}
Also used : EditorModeChangedEvent(org.rstudio.studio.client.workbench.views.source.editors.text.events.EditorModeChangedEvent) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) AttachEvent(com.google.gwt.event.logical.shared.AttachEvent) CursorChangedHandler(org.rstudio.studio.client.workbench.views.source.editors.text.events.CursorChangedHandler) NativePreviewHandler(com.google.gwt.user.client.Event.NativePreviewHandler) CursorChangedHandler(org.rstudio.studio.client.workbench.views.source.editors.text.events.CursorChangedHandler) CursorChangedEvent(org.rstudio.studio.client.workbench.views.source.editors.text.events.CursorChangedEvent)

Example 4 with CursorChangedEvent

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

the class EditingTargetInlineChunkExecution method execute.

public void execute(Range range) {
    // synthesize an identifier for this chunk execution
    final String chunkId = "i" + StringUtil.makeRandomId(12);
    // are, remove it to make way for the new one
    for (ChunkInlineOutput output : outputs_.values()) {
        if (output.range().isEqualTo(range)) {
            if (output.state() == ChunkInlineOutput.State.Finished) {
                // remove old, completed output for this input
                output.hide();
                outputs_.remove(output.chunkId());
            } else {
                // unintended duplicate.
                return;
            }
        }
    }
    // create dummy scope for execution
    Scope scope = Scope.createRScopeNode(chunkId, range.getStart(), range.getEnd(), Scope.SCOPE_TYPE_CHUNK);
    // create popup panel to host output
    final ChunkInlineOutput output = new ChunkInlineOutput(chunkId, display_.createAnchoredSelection(range.getStart(), range.getEnd()));
    // auto dismiss the panel when the cursor leaves the inline chunk
    final Mutable<HandlerRegistration> cursorHandler = new Mutable<HandlerRegistration>();
    cursorHandler.set(display_.addCursorChangedHandler(new CursorChangedHandler() {

        @Override
        public void onCursorChanged(CursorChangedEvent event) {
            Position position = event.getPosition();
            if (!output.range().contains(position)) {
                output.hide();
            }
        }
    }));
    // when the popup is dismissed, clean up local state
    output.addCloseHandler(new CloseHandler<PopupPanel>() {

        @Override
        public void onClose(CloseEvent<PopupPanel> event) {
            outputs_.remove(chunkId);
            cursorHandler.get().removeHandler();
        }
    });
    // render offscreen until complete
    output.setPopupPosition(-100000, -100000);
    output.show();
    outputs_.put(chunkId, output);
    SendToChunkConsoleEvent event = new SendToChunkConsoleEvent(docId_, scope, range, NotebookQueueUnit.EXEC_SCOPE_INLINE);
    events_.fireEvent(event);
}
Also used : HandlerRegistration(com.google.gwt.event.shared.HandlerRegistration) Position(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position) PopupPanel(com.google.gwt.user.client.ui.PopupPanel) CursorChangedEvent(org.rstudio.studio.client.workbench.views.source.editors.text.events.CursorChangedEvent) ChunkInlineOutput(org.rstudio.studio.client.workbench.views.source.editors.text.ChunkInlineOutput) Mutable(org.rstudio.core.client.Mutable) Scope(org.rstudio.studio.client.workbench.views.source.editors.text.Scope) CursorChangedHandler(org.rstudio.studio.client.workbench.views.source.editors.text.events.CursorChangedHandler) SendToChunkConsoleEvent(org.rstudio.studio.client.rmarkdown.events.SendToChunkConsoleEvent)

Aggregations

CursorChangedEvent (org.rstudio.studio.client.workbench.views.source.editors.text.events.CursorChangedEvent)4 CursorChangedHandler (org.rstudio.studio.client.workbench.views.source.editors.text.events.CursorChangedHandler)4 Position (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position)2 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)1 AttachEvent (com.google.gwt.event.logical.shared.AttachEvent)1 HandlerRegistration (com.google.gwt.event.shared.HandlerRegistration)1 NativePreviewHandler (com.google.gwt.user.client.Event.NativePreviewHandler)1 PopupPanel (com.google.gwt.user.client.ui.PopupPanel)1 Mutable (org.rstudio.core.client.Mutable)1 SendToChunkConsoleEvent (org.rstudio.studio.client.rmarkdown.events.SendToChunkConsoleEvent)1 AceEditorWidget (org.rstudio.studio.client.workbench.views.source.editors.text.AceEditorWidget)1 ChunkInlineOutput (org.rstudio.studio.client.workbench.views.source.editors.text.ChunkInlineOutput)1 Scope (org.rstudio.studio.client.workbench.views.source.editors.text.Scope)1 EditSession (org.rstudio.studio.client.workbench.views.source.editors.text.ace.EditSession)1 EditorModeChangedEvent (org.rstudio.studio.client.workbench.views.source.editors.text.events.EditorModeChangedEvent)1