Search in sources :

Example 1 with LineWidget

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;
}
Also used : ChunkChangeEvent(org.rstudio.studio.client.workbench.views.source.events.ChunkChangeEvent) ScopeList(org.rstudio.studio.client.workbench.views.source.editors.text.ScopeList) LineWidget(org.rstudio.studio.client.workbench.views.source.editors.text.ace.LineWidget)

Example 2 with LineWidget

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);
                        }
                    });
                }
            });
        }
    });
}
Also used : ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) Element(com.google.gwt.dom.client.Element) PinnedLineWidget(org.rstudio.studio.client.workbench.views.source.editors.text.PinnedLineWidget) LineWidget(org.rstudio.studio.client.workbench.views.source.editors.text.ace.LineWidget)

Example 3 with LineWidget

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);
}
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 LineWidget

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);
    }
}
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 LineWidget

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;
}
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

LineWidget (org.rstudio.studio.client.workbench.views.source.editors.text.ace.LineWidget)8 PinnedLineWidget (org.rstudio.studio.client.workbench.views.source.editors.text.PinnedLineWidget)5 ChunkOutputWidget (org.rstudio.studio.client.workbench.views.source.editors.text.ChunkOutputWidget)4 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)2 Element (com.google.gwt.dom.client.Element)2 Command (com.google.gwt.user.client.Command)2 Map (java.util.Map)2 FadeOutAnimation (org.rstudio.core.client.layout.FadeOutAnimation)2 ChunkOutputHost (org.rstudio.studio.client.workbench.views.source.editors.text.rmd.ChunkOutputHost)2 Style (com.google.gwt.dom.client.Style)1 HandlerRegistration (com.google.gwt.event.shared.HandlerRegistration)1 Event (com.google.gwt.user.client.Event)1 EventListener (com.google.gwt.user.client.EventListener)1 Timer (com.google.gwt.user.client.Timer)1 FlowPanel (com.google.gwt.user.client.ui.FlowPanel)1 Image (com.google.gwt.user.client.ui.Image)1 Label (com.google.gwt.user.client.ui.Label)1 SimplePanel (com.google.gwt.user.client.ui.SimplePanel)1 Widget (com.google.gwt.user.client.ui.Widget)1 ArrayList (java.util.ArrayList)1