use of org.rstudio.studio.client.workbench.views.source.editors.text.AceEditorWidget 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;
}
Aggregations