use of org.rstudio.studio.client.workbench.views.source.editors.text.ace.LineWidget in project rstudio by rstudio.
the class NotebookQueueState method getChunkDefAtRow.
private ChunkDefinition getChunkDefAtRow(int row, String newId) {
ChunkDefinition chunkDef;
// if there is an existing widget just modify it in place
LineWidget widget = docDisplay_.getLineWidgetForRow(row);
if (widget != null && widget.getType().equals(ChunkDefinition.LINE_WIDGET_TYPE)) {
chunkDef = widget.getData();
} else // otherwise create a new one
{
if (StringUtil.isNullOrEmpty(newId))
newId = "c" + StringUtil.makeRandomId(12);
chunkDef = ChunkDefinition.create(row, 1, true, ChunkOutputWidget.EXPANDED, RmdChunkOptions.create(), sentinel_.getId(), newId, TextEditingTargetNotebook.getKnitrChunkLabel(row, docDisplay_, new ScopeList(docDisplay_)));
if (newId == TextEditingTargetNotebook.SETUP_CHUNK_ID)
chunkDef.getOptions().setInclude(false);
RStudioGinjector.INSTANCE.getEventBus().fireEvent(new ChunkChangeEvent(sentinel_.getId(), chunkDef.getChunkId(), "", row, ChunkChangeEvent.CHANGE_CREATE));
}
return chunkDef;
}
use of org.rstudio.studio.client.workbench.views.source.editors.text.ace.LineWidget in project rstudio by rstudio.
the class MathJax method renderLatexLineWidget.
private void renderLatexLineWidget(LineWidget widget, final Range range, final String text, final MathJaxTypesetCallback callback) {
final Element el = DomUtils.getFirstElementWithClassName(widget.getElement(), MATHJAX_ROOT_CLASSNAME);
// call 'onLineWidgetChanged' to ensure the widget is attached
docDisplay_.onLineWidgetChanged(widget);
// defer typesetting just to ensure that the widget has actually been
// attached to the DOM
final LineWidget lineWidget = widget;
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
mathjaxTypeset(el, text, new MathJaxTypesetCallback() {
@Override
public void onMathJaxTypesetComplete(final boolean error) {
// force expansion
withExpandedLineWidget(lineWidget, new CommandWithArg<Boolean>() {
@Override
public void execute(Boolean stateChanged) {
// re-position the element
int height = el.getOffsetHeight() + 30;
Element ppElement = el.getParentElement().getParentElement();
ppElement.getStyle().setHeight(height, Unit.PX);
docDisplay_.onLineWidgetChanged(lineWidget);
// invoke supplied callback
if (callback != null)
callback.onMathJaxTypesetComplete(error);
}
});
}
});
}
});
}
use of org.rstudio.studio.client.workbench.views.source.editors.text.ace.LineWidget in project rstudio by rstudio.
the class MathJax method createMathJaxLineWidget.
private void createMathJaxLineWidget(int row, boolean bare, final CommandWithArg<LineWidget> onAttached) {
final FlowPanel panel = createMathJaxContainerWidget();
ChunkOutputHost host = new ChunkOutputHost() {
private int lastHeight_ = Integer.MAX_VALUE;
@Override
public void onOutputRemoved(final ChunkOutputWidget widget) {
removeChunkOutputWidget(widget);
}
@Override
public void onOutputHeightChanged(ChunkOutputWidget widget, int height, boolean ensureVisible) {
final PinnedLineWidget plw = cowToPlwMap_.get(widget);
if (plw == null)
return;
// munge the size of the frame, to avoid issues where the
// frame's size changes following a collapse + expand
boolean isExpansion = lastHeight_ <= height;
if (isExpansion)
widget.getFrame().setHeight((height + 4) + "px");
lastHeight_ = height;
// update the height and report to doc display
LineWidget lineWidget = plw.getLineWidget();
lineWidget.setPixelHeight(height);
docDisplay_.onLineWidgetChanged(lineWidget);
}
};
final ChunkOutputWidget outputWidget = new ChunkOutputWidget(StringUtil.makeRandomId(8), StringUtil.makeRandomId(8), RmdChunkOptions.create(), ChunkOutputWidget.EXPANDED, // can close
false, host, bare ? ChunkOutputSize.Bare : ChunkOutputSize.Default);
outputWidget.setRootWidget(panel);
outputWidget.hideSatellitePopup();
PinnedLineWidget plWidget = new PinnedLineWidget(LINE_WIDGET_TYPE, docDisplay_, outputWidget, row, null, new PinnedLineWidget.Host() {
@Override
public void onLineWidgetRemoved(LineWidget widget) {
// no action necessary here; this is taken care of by the
// hosting chunk (see onOutputRemoved)
}
@Override
public void onLineWidgetAdded(LineWidget widget) {
onAttached.execute(widget);
}
});
cowToPlwMap_.put(outputWidget, plWidget);
lwToPlwMap_.put(plWidget.getLineWidget(), outputWidget);
}
use of org.rstudio.studio.client.workbench.views.source.editors.text.ace.LineWidget in project rstudio by rstudio.
the class MathJax method renderLatexLineWidget.
private void renderLatexLineWidget(final Range range, final String text, final MathJaxTypesetCallback callback) {
// end a previous render session if necessary (e.g. if a popup is showing)
endRender();
// bail if we already have a pinned line widget here
final int row = range.getEnd().getRow();
LineWidget widget = docDisplay_.getLineWidgetForRow(row);
if (widget == null) {
// (ie a previous render is pending here)
for (Map.Entry<ChunkOutputWidget, PinnedLineWidget> entry : cowToPlwMap_.entrySet()) if (entry.getValue().getRow() == row)
return;
// if we don't have a widget, create one and render the LaTeX once
// the widget is attached to the editor
createMathJaxLineWidget(row, // render bare output if start and end are on the same line
range.getStart().getRow() == range.getEnd().getRow(), new CommandWithArg<LineWidget>() {
@Override
public void execute(LineWidget w) {
renderLatexLineWidget(w, range, text, callback);
}
});
} else {
renderLatexLineWidget(widget, range, text, callback);
}
}
use of org.rstudio.studio.client.workbench.views.source.editors.text.ace.LineWidget in project rstudio by rstudio.
the class MathJax method isLineWidgetCollapsed.
private boolean isLineWidgetCollapsed(int row) {
LineWidget widget = docDisplay_.getLineWidgetForRow(row);
if (widget == null)
return false;
ChunkOutputWidget cow = lwToPlwMap_.get(widget);
if (cow == null)
return false;
return cow.getExpansionState() == ChunkOutputWidget.COLLAPSED;
}
Aggregations