Search in sources :

Example 16 with OutlineItem

use of org.eclipse.mylyn.wikitext.parser.outline.OutlineItem in project mylyn.docs by eclipse.

the class OutlineParserTest method testSimple.

public void testSimple() {
    OutlineItem outline = outlineParser.parse("h1. First Header\n\nh2. Second Header\n\nh1. Third Header\n");
    assertEquals(2, outline.getChildren().size());
    assertEquals(1, outline.getChildren().get(0).getChildren().size());
    assertEquals(0, outline.getChildren().get(1).getChildren().size());
}
Also used : OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)

Example 17 with OutlineItem

use of org.eclipse.mylyn.wikitext.parser.outline.OutlineItem in project mylyn.docs by eclipse.

the class OutlineParserTest method testMoveChildren.

public void testMoveChildren() {
    String textile = "h1. First Header\n\nh2. Second Header\n\nh1. Third Header\n";
    OutlineItem outline = outlineParser.parse(textile);
    assertEquals(2, outline.getChildren().size());
    OutlineItem outline2 = outlineParser.createRootItem();
    outline2.moveChildren(outline);
    assertEquals(0, outline.getChildren().size());
    assertEquals(2, outline2.getChildren().size());
    assertSame(outline2, outline2.getChildren().get(0).getParent());
    assertSame(outline2, outline2.getChildren().get(1).getParent());
    outline = outlineParser.parse(textile);
    outline.moveChildren(outline2);
    assertEquals(0, outline2.getChildren().size());
    assertEquals(4, outline.getChildren().size());
    assertSame(outline, outline.getChildren().get(0).getParent());
    assertSame(outline, outline.getChildren().get(1).getParent());
    assertSame(outline, outline.getChildren().get(2).getParent());
    assertSame(outline, outline.getChildren().get(3).getParent());
}
Also used : OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)

Example 18 with OutlineItem

use of org.eclipse.mylyn.wikitext.parser.outline.OutlineItem in project mylyn.docs by eclipse.

the class ActiveFoldingListener method updateFolding.

private void updateFolding(boolean elementsDeleted) {
    if (!foldingStructure.isFoldingEnabled()) {
        return;
    }
    if (!foldingEnabled || !ContextCore.getContextManager().isContextActive()) {
        foldingStructure.expandAll();
    } else {
        OutlineItem outline = (OutlineItem) part.getAdapter(OutlineItem.class);
        if (outline != null) {
            final List<OutlineItem> toExpand = new ArrayList<OutlineItem>();
            outline.accept(new Visitor() {

                public boolean visit(OutlineItem item) {
                    String identifier = bridge.getHandleIdentifier(item);
                    IInteractionElement element = ContextCore.getContextManager().getElement(identifier);
                    if (element != null && element.getInterest().isInteresting()) {
                        toExpand.add(item);
                    }
                    return true;
                }
            });
            if (toExpand.isEmpty()) {
                foldingStructure.collapseAll(elementsDeleted);
            } else {
                foldingStructure.expandElementsExclusive(toExpand, elementsDeleted);
            }
        }
    }
}
Also used : Visitor(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem.Visitor) ArrayList(java.util.ArrayList) IInteractionElement(org.eclipse.mylyn.context.core.IInteractionElement) OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)

Example 19 with OutlineItem

use of org.eclipse.mylyn.wikitext.parser.outline.OutlineItem in project mylyn.docs by eclipse.

the class XslfoDocumentBuilder method emitToc.

private void emitToc(XmlStreamWriter writer, List<OutlineItem> children) {
    for (OutlineItem item : children) {
        // $NON-NLS-1$
        writer.writeStartElement("bookmark");
        // $NON-NLS-1$
        writer.writeAttribute("internal-destination", item.getId());
        // $NON-NLS-1$
        writer.writeStartElement("bookmark-title");
        writer.writeCharacters(item.getLabel());
        writer.writeEndElement();
        if (!item.getChildren().isEmpty()) {
            emitToc(writer, item.getChildren());
        }
        // bookmark
        writer.writeEndElement();
    }
}
Also used : OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)

Example 20 with OutlineItem

use of org.eclipse.mylyn.wikitext.parser.outline.OutlineItem in project mylyn.docs by eclipse.

the class MarkupToEclipseToc method emitToc.

private void emitToc(XmlStreamWriter writer, List<OutlineItem> children) {
    for (OutlineItem item : children) {
        // $NON-NLS-1$
        writer.writeStartElement("topic");
        String file = computeFile(item);
        file = adjustForPrefix(file);
        // $NON-NLS-1$
        String suffix = "";
        // bug 260065: only append document anchor name if this is not the first item in the file.
        OutlineItem previous = item.getPrevious();
        boolean hasPrevious = previous != null && previous.getParent() != null;
        if (hasPrevious) {
            String fileOfPrevious = computeFile(previous);
            fileOfPrevious = adjustForPrefix(fileOfPrevious);
            if (file.equals(fileOfPrevious)) {
                // $NON-NLS-1$
                suffix = "#" + item.getId();
            }
        }
        // $NON-NLS-1$
        writer.writeAttribute("href", file + suffix);
        // $NON-NLS-1$
        writer.writeAttribute("label", item.getLabel());
        if (!item.getChildren().isEmpty()) {
            emitToc(writer, item.getChildren());
        }
        if (item.getLevel() <= anchorLevel) {
            // $NON-NLS-1$
            writer.writeEmptyElement("anchor");
            // $NON-NLS-1$ //$NON-NLS-2$
            writer.writeAttribute("id", item.getId() + "-additions");
        }
        // topic
        writer.writeEndElement();
    }
}
Also used : OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)

Aggregations

OutlineItem (org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)58 OutlineParser (org.eclipse.mylyn.wikitext.parser.outline.OutlineParser)18 MediaWikiLanguage (org.eclipse.mylyn.wikitext.mediawiki.MediaWikiLanguage)9 Point (org.eclipse.swt.graphics.Point)8 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)7 ITextSelection (org.eclipse.jface.text.ITextSelection)5 Attributes (org.eclipse.mylyn.wikitext.parser.Attributes)5 MarkupLanguage (org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage)5 BufferedOutputStream (java.io.BufferedOutputStream)4 FileOutputStream (java.io.FileOutputStream)4 OutputStreamWriter (java.io.OutputStreamWriter)4 Writer (java.io.Writer)4 BuildException (org.apache.tools.ant.BuildException)4 ISelection (org.eclipse.jface.viewers.ISelection)4 AbstractMarkupLanguage (org.eclipse.mylyn.wikitext.parser.markup.AbstractMarkupLanguage)4 File (java.io.File)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 IMenuManager (org.eclipse.jface.action.IMenuManager)3 MenuManager (org.eclipse.jface.action.MenuManager)3