Search in sources :

Example 1 with Counter

use of org.rstudio.core.client.Counter in project rstudio by rstudio.

the class DocumentOutlineWidget method rebuildScopeTree.

private void rebuildScopeTree(JsArray<Scope> scopeTree, Scope currentScope) {
    scopeTree_ = scopeTree;
    currentScope_ = currentScope;
    currentVisibleScope_ = getCurrentVisibleScope(currentScope_);
    if (scopeTree_.length() == 0) {
        setActiveWidget(emptyPlaceholder_);
        return;
    }
    setActiveWidget(tree_);
    int h1Count = 0;
    for (int i = 0; i < scopeTree_.length(); i++) {
        Scope node = scopeTree_.get(i);
        if (node.isMarkdownHeader()) {
            if (node.getDepth() == 1)
                h1Count++;
        }
    }
    int initialDepth = h1Count == 1 ? -1 : 0;
    Counter counter = new Counter(-1);
    for (int i = 0; i < scopeTree_.length(); i++) buildScopeTreeImpl(scopeTree_.get(i), initialDepth, counter);
    // Clean up leftovers in the tree. 
    int oldTreeSize = tree_.getItemCount();
    int newTreeSize = counter.increment();
    for (int i = oldTreeSize - 1; i >= newTreeSize; i--) {
        TreeItem item = tree_.getItem(i);
        if (item != null)
            item.remove();
    }
}
Also used : Counter(org.rstudio.core.client.Counter) Scope(org.rstudio.studio.client.workbench.views.source.editors.text.Scope) TreeItem(com.google.gwt.user.client.ui.TreeItem)

Aggregations

TreeItem (com.google.gwt.user.client.ui.TreeItem)1 Counter (org.rstudio.core.client.Counter)1 Scope (org.rstudio.studio.client.workbench.views.source.editors.text.Scope)1