Search in sources :

Example 1 with EditSession

use of org.rstudio.studio.client.workbench.views.source.editors.text.ace.EditSession 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)

Aggregations

AceEditorWidget (org.rstudio.studio.client.workbench.views.source.editors.text.AceEditorWidget)1 EditSession (org.rstudio.studio.client.workbench.views.source.editors.text.ace.EditSession)1 CursorChangedEvent (org.rstudio.studio.client.workbench.views.source.editors.text.events.CursorChangedEvent)1 CursorChangedHandler (org.rstudio.studio.client.workbench.views.source.editors.text.events.CursorChangedHandler)1