Search in sources :

Example 1 with ChunkOutputWidget

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

the class TextEditingTargetNotebook method onNotebookToggleExpansion.

public void onNotebookToggleExpansion() {
    String chunkId = getCurrentChunkId();
    if (chunkId == null || !outputs_.containsKey(chunkId))
        return;
    ChunkOutputWidget widget = outputs_.get(chunkId).getOutputWidget();
    widget.setExpansionState(widget.getExpansionState() == ChunkOutputWidget.COLLAPSED ? ChunkOutputWidget.EXPANDED : ChunkOutputWidget.COLLAPSED);
}
Also used : ChunkOutputWidget(org.rstudio.studio.client.workbench.views.source.editors.text.ChunkOutputWidget)

Example 2 with ChunkOutputWidget

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

the class MathJax method withExpandedLineWidget.

private void withExpandedLineWidget(LineWidget widget, final CommandWithArg<Boolean> onExpansionCompleted) {
    ChunkOutputWidget cow = lwToPlwMap_.get(widget);
    if (cow == null) {
        onExpansionCompleted.execute(false);
        return;
    }
    cow.setExpansionState(ChunkOutputWidget.EXPANDED, onExpansionCompleted);
}
Also used : ChunkOutputWidget(org.rstudio.studio.client.workbench.views.source.editors.text.ChunkOutputWidget)

Example 3 with ChunkOutputWidget

use of org.rstudio.studio.client.workbench.views.source.editors.text.ChunkOutputWidget 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);
}
Also used : ChunkOutputHost(org.rstudio.studio.client.workbench.views.source.editors.text.rmd.ChunkOutputHost) ChunkOutputWidget(org.rstudio.studio.client.workbench.views.source.editors.text.ChunkOutputWidget) FlowPanel(com.google.gwt.user.client.ui.FlowPanel) PinnedLineWidget(org.rstudio.studio.client.workbench.views.source.editors.text.PinnedLineWidget) LineWidget(org.rstudio.studio.client.workbench.views.source.editors.text.ace.LineWidget) PinnedLineWidget(org.rstudio.studio.client.workbench.views.source.editors.text.PinnedLineWidget)

Example 4 with ChunkOutputWidget

use of org.rstudio.studio.client.workbench.views.source.editors.text.ChunkOutputWidget 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);
    }
}
Also used : ChunkOutputWidget(org.rstudio.studio.client.workbench.views.source.editors.text.ChunkOutputWidget) PinnedLineWidget(org.rstudio.studio.client.workbench.views.source.editors.text.PinnedLineWidget) LineWidget(org.rstudio.studio.client.workbench.views.source.editors.text.ace.LineWidget) PinnedLineWidget(org.rstudio.studio.client.workbench.views.source.editors.text.PinnedLineWidget) Map(java.util.Map) SafeMap(org.rstudio.core.client.container.SafeMap)

Example 5 with ChunkOutputWidget

use of org.rstudio.studio.client.workbench.views.source.editors.text.ChunkOutputWidget 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;
}
Also used : ChunkOutputWidget(org.rstudio.studio.client.workbench.views.source.editors.text.ChunkOutputWidget) PinnedLineWidget(org.rstudio.studio.client.workbench.views.source.editors.text.PinnedLineWidget) LineWidget(org.rstudio.studio.client.workbench.views.source.editors.text.ace.LineWidget)

Aggregations

ChunkOutputWidget (org.rstudio.studio.client.workbench.views.source.editors.text.ChunkOutputWidget)6 PinnedLineWidget (org.rstudio.studio.client.workbench.views.source.editors.text.PinnedLineWidget)3 LineWidget (org.rstudio.studio.client.workbench.views.source.editors.text.ace.LineWidget)3 FlowPanel (com.google.gwt.user.client.ui.FlowPanel)1 Map (java.util.Map)1 SafeMap (org.rstudio.core.client.container.SafeMap)1 Scope (org.rstudio.studio.client.workbench.views.source.editors.text.Scope)1 ChunkOutputHost (org.rstudio.studio.client.workbench.views.source.editors.text.rmd.ChunkOutputHost)1