Search in sources :

Example 1 with ChunkChangeEvent

use of org.rstudio.studio.client.workbench.views.source.events.ChunkChangeEvent 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 ChunkChangeEvent

use of org.rstudio.studio.client.workbench.views.source.events.ChunkChangeEvent in project rstudio by rstudio.

the class TextEditingTargetNotebook method onRmdChunkOutput.

@Override
public void onRmdChunkOutput(RmdChunkOutputEvent event) {
    // ignore if not targeted at this document
    if (event.getOutput().getDocId() != docUpdateSentinel_.getId())
        return;
    // the server, so clean it up here.
    if (event.getOutput().isEmpty() && !queue_.isExecuting()) {
        events_.fireEvent(new ChunkChangeEvent(docUpdateSentinel_.getId(), event.getOutput().getChunkId(), event.getOutput().getRequestId(), 0, ChunkChangeEvent.CHANGE_REMOVE));
        return;
    }
    String chunkId = event.getOutput().getChunkId();
    // ignore requests performed to initialize satellite chunks
    if (satelliteChunkRequestIds_.contains(event.getOutput().getRequestId()))
        return;
    // if this is the currently executing chunk and it has an error...
    NotebookQueueUnit unit = queue_.executingUnit();
    if (unit != null && unit.getChunkId() == event.getOutput().getChunkId() && event.getOutput().getType() == RmdChunkOutput.TYPE_SINGLE_UNIT && event.getOutput().getUnit().getType() == RmdChunkOutputUnit.TYPE_ERROR) {
        // draw the error 
        Scope scope = getChunkScope(unit.getChunkId());
        if (scope != null) {
            int offset = scope.getBodyStart().getRow();
            List<Integer> lines = unit.getExecutingLines();
            for (Integer line : lines) docDisplay_.setChunkLineExecState(line + offset, line + offset, ChunkRowExecState.LINE_ERROR);
        }
        // error = FALSE
        if (!outputs_.containsKey(chunkId) || !outputs_.get(chunkId).getOptions().error()) {
            clearChunkExecQueue();
        }
    }
    // show output in matching chunk
    if (outputs_.containsKey(chunkId)) {
        // by default, ensure chunks are visible if we aren't replaying them
        // from the cache
        boolean ensureVisible = !event.getOutput().isReplay();
        int mode = queue_.getChunkExecMode(chunkId);
        // no need to make chunks visible in batch mode
        if (ensureVisible && mode == NotebookQueueUnit.EXEC_MODE_BATCH)
            ensureVisible = false;
        outputs_.get(chunkId).getOutputWidget().showChunkOutput(event.getOutput(), mode, NotebookQueueUnit.EXEC_SCOPE_PARTIAL, !queue_.isChunkExecuting(chunkId), ensureVisible);
    }
}
Also used : ChunkChangeEvent(org.rstudio.studio.client.workbench.views.source.events.ChunkChangeEvent) Scope(org.rstudio.studio.client.workbench.views.source.editors.text.Scope) NotebookQueueUnit(org.rstudio.studio.client.rmarkdown.model.NotebookQueueUnit)

Example 3 with ChunkChangeEvent

use of org.rstudio.studio.client.workbench.views.source.events.ChunkChangeEvent in project rstudio by rstudio.

the class TextEditingTargetNotebook method clearChunkOutput.

public void clearChunkOutput(Scope chunk) {
    if (chunk == null) {
        // no-op if cursor is not inside a chunk
        return;
    }
    String chunkId = getRowChunkId(chunk.getPreamble().getRow());
    if (chunkId == null) {
        // no-op if we don't have known output 
        return;
    }
    events_.fireEvent(new ChunkChangeEvent(docUpdateSentinel_.getId(), chunkId, "", 0, ChunkChangeEvent.CHANGE_REMOVE));
}
Also used : ChunkChangeEvent(org.rstudio.studio.client.workbench.views.source.events.ChunkChangeEvent)

Example 4 with ChunkChangeEvent

use of org.rstudio.studio.client.workbench.views.source.events.ChunkChangeEvent in project rstudio by rstudio.

the class TextEditingTargetNotebook method onScopeTreeReady.

@Override
public void onScopeTreeReady(ScopeTreeReadyEvent event) {
    Scope thisScope = event.getCurrentScope();
    // initialization 
    if (lastStart_ == null && lastEnd_ == null) {
        if (thisScope != null) {
            lastStart_ = Position.create(thisScope.getBodyStart());
            lastEnd_ = Position.create(thisScope.getEnd());
        }
        return;
    }
    // avoid it)
    if (thisScope != null) {
        Position thisStart = thisScope.getBodyStart();
        Position thisEnd = thisScope.getEnd();
        if (((lastStart_ == null && thisStart == null) || (lastStart_ != null && lastStart_.compareTo(thisStart) == 0)) && ((lastEnd_ == null && thisEnd == null) || (lastEnd_ != null && lastEnd_.compareTo(thisEnd) == 0))) {
            return;
        }
        lastStart_ = Position.create(thisScope.getBodyStart());
        lastEnd_ = Position.create(thisScope.getEnd());
    } else {
        lastStart_ = null;
        lastEnd_ = null;
    }
    for (ChunkOutputUi output : outputs_.values()) {
        Scope scope = output.getScope();
        // remove the widget
        if (scope == null || !scope.isChunk() || scope.getBodyStart() == null || scope.getEnd() == null || scope.getEnd().getRow() - output.getCurrentRow() > 1) {
            events_.fireEvent(new ChunkChangeEvent(docUpdateSentinel_.getId(), output.getChunkId(), "", 0, ChunkChangeEvent.CHANGE_REMOVE));
        }
    }
}
Also used : Scope(org.rstudio.studio.client.workbench.views.source.editors.text.Scope) ChunkChangeEvent(org.rstudio.studio.client.workbench.views.source.events.ChunkChangeEvent) Position(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position)

Aggregations

ChunkChangeEvent (org.rstudio.studio.client.workbench.views.source.events.ChunkChangeEvent)4 Scope (org.rstudio.studio.client.workbench.views.source.editors.text.Scope)2 NotebookQueueUnit (org.rstudio.studio.client.rmarkdown.model.NotebookQueueUnit)1 ScopeList (org.rstudio.studio.client.workbench.views.source.editors.text.ScopeList)1 LineWidget (org.rstudio.studio.client.workbench.views.source.editors.text.ace.LineWidget)1 Position (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position)1