Search in sources :

Example 31 with OutlineItem

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

the class OutlineDropTargetListener method drop.

public void drop(DropTargetEvent event) {
    List<OutlineItem> dropItems = getDropItems(event);
    if (dropItems != null) {
        InsertLocation location = computeInsertLocation(event);
        Object targetData = event.item.getData();
        final AbstractDocumentCommand command = computeCommand(targetData, dropItems, location);
        if (command != null) {
            if (command.isEnabled()) {
                SafeRunnable.run(new ISafeRunnable() {

                    public void handleException(Throwable exception) {
                        WikiTextUiPlugin.getDefault().log(exception);
                        MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), Messages.OutlineDropTargetListener_0, NLS.bind(Messages.OutlineDropTargetListener_1, new Object[] { exception.getMessage() }));
                    }

                    public void run() throws Exception {
                        commandManager.perform(command);
                    }
                });
            } else {
                MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), Messages.OutlineDropTargetListener_2, NLS.bind(Messages.OutlineDropTargetListener_3, new Object[] { command.getProblemText() }));
            }
        }
    }
}
Also used : AbstractDocumentCommand(org.eclipse.mylyn.internal.wikitext.ui.editor.operations.AbstractDocumentCommand) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) InsertLocation(org.eclipse.mylyn.internal.wikitext.ui.editor.operations.InsertLocation) OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)

Example 32 with OutlineItem

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

the class WikiTextContextStructureBridge method getObjectForHandle.

@Override
public Object getObjectForHandle(String handle) {
    if (handle == null) {
        return null;
    }
    int idxOfSeparator = handle.indexOf(HANDLE_FILE_SEPARATOR);
    String filename = handle;
    if (idxOfSeparator != -1) {
        filename = handle.substring(0, idxOfSeparator);
    }
    IFile file;
    try {
        file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(filename));
    } catch (Exception e) {
        // be error-tolerant since we don't know much about the handle at this point
        return null;
    }
    if (file != null) {
        if (idxOfSeparator != -1) {
            String headingId = handle.substring(idxOfSeparator + 1);
            OutlineItem outline = getOutline(file);
            if (outline != null) {
                OutlineItem item = outline.findItemById(headingId);
                return item;
            }
        } else {
            return file;
        }
    }
    return null;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)

Example 33 with OutlineItem

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

the class TableOfContentsBlock method emitToc.

private void emitToc(OutlineItem item) {
    if (item.getChildren().isEmpty()) {
        return;
    }
    if ((item.getLevel() + 1) > maxLevel) {
        return;
    }
    Attributes nullAttributes = new Attributes();
    // $NON-NLS-1$ //$NON-NLS-2$
    builder.beginBlock(BlockType.NUMERIC_LIST, new Attributes(null, null, "list-style: " + style + ";", null));
    for (OutlineItem child : item.getChildren()) {
        builder.beginBlock(BlockType.LIST_ITEM, nullAttributes);
        builder.link('#' + child.getId(), child.getLabel());
        emitToc(child);
        builder.endBlock();
    }
    builder.endBlock();
}
Also used : Attributes(org.eclipse.mylyn.wikitext.parser.Attributes) OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)

Example 34 with OutlineItem

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

the class TableOfContentsBlock method processLineContent.

@Override
public int processLineContent(String line, int offset) {
    if (blockLineNumber++ > 0) {
        setClosed(true);
        return 0;
    }
    if (!getMarkupLanguage().isFilterGenerativeContents()) {
        String options = matcher.group(1);
        setOptions(options);
        OutlineParser outlineParser = new OutlineParser(new ConfluenceLanguage());
        OutlineItem rootItem = outlineParser.parse(state.getMarkupContent());
        emitToc(rootItem);
    }
    setClosed(true);
    return matcher.start(2);
}
Also used : ConfluenceLanguage(org.eclipse.mylyn.wikitext.confluence.ConfluenceLanguage) OutlineParser(org.eclipse.mylyn.wikitext.parser.outline.OutlineParser) OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)

Example 35 with OutlineItem

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

the class SplittingHtmlDocumentBuilder method emitToc.

private void emitToc(OutlineItem item, int level) {
    if (item.getChildren().isEmpty()) {
        return;
    }
    out.beginBlock(BlockType.NUMERIC_LIST, new Attributes());
    for (OutlineItem child : item.getChildren()) {
        Attributes itemAttributes = new Attributes();
        if (isExpandedInTableOfContents(child)) {
            // $NON-NLS-1$
            itemAttributes.appendCssClass("expanded");
        } else {
            // $NON-NLS-1$
            itemAttributes.appendCssClass("collapsed");
        }
        out.beginBlock(BlockType.LIST_ITEM, itemAttributes);
        out.link(getHrefOfHeading(child.getId()), child.getLabel());
        emitToc(child, level + 1);
        out.endBlock();
    }
    out.endBlock();
}
Also used : ImageAttributes(org.eclipse.mylyn.wikitext.parser.ImageAttributes) LinkAttributes(org.eclipse.mylyn.wikitext.parser.LinkAttributes) Attributes(org.eclipse.mylyn.wikitext.parser.Attributes) TableCellAttributes(org.eclipse.mylyn.wikitext.parser.TableCellAttributes) TableAttributes(org.eclipse.mylyn.wikitext.parser.TableAttributes) 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