Search in sources :

Example 46 with OutlineItem

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

the class AnchorCompletionProcessor method computeCompletionProposals.

public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
    if (outline == null) {
        return null;
    }
    ITextSelection selection = (ITextSelection) viewer.getSelectionProvider().getSelection();
    // adjust offset to end of normalized selection
    if (selection.getOffset() == offset) {
        offset = selection.getOffset() + selection.getLength();
    }
    final String prefix = extractPrefix(viewer, offset);
    if (prefix == null) {
        return null;
    }
    final List<CompletionProposal> suggestions = new ArrayList<>(20);
    final int prefixOffset = offset - prefix.length();
    outline.accept(new Visitor() {

        public boolean visit(OutlineItem item) {
            if (item != outline) {
                String id = item.getId();
                if (id != null && id.length() > 0) {
                    suggestions.add(createProposal(prefix, prefixOffset, id));
                }
            }
            return true;
        }
    });
    if (suggestions.isEmpty()) {
        return null;
    }
    Collections.sort(suggestions, PROPOSAL_COMPARATOR);
    return suggestions.toArray(new ICompletionProposal[suggestions.size()]);
}
Also used : ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) Visitor(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem.Visitor) ArrayList(java.util.ArrayList) ITextSelection(org.eclipse.jface.text.ITextSelection) Point(org.eclipse.swt.graphics.Point) OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)

Example 47 with OutlineItem

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

the class ShowInTargetBridge method show.

public boolean show(ShowInContext context) {
    ISelection selection = context.getSelection();
    if (selection instanceof IStructuredSelection) {
        for (Object element : ((IStructuredSelection) selection).toArray()) {
            if (element instanceof OutlineItem) {
                OutlineItem item = (OutlineItem) element;
                viewer.setSelection(new TextSelection(item.getOffset(), item.getLength()), true);
                return true;
            }
        }
    } else if (selection instanceof ITextSelection) {
        viewer.setSelection(selection, true);
        return true;
    }
    return false;
}
Also used : TextSelection(org.eclipse.jface.text.TextSelection) ITextSelection(org.eclipse.jface.text.ITextSelection) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ITextSelection(org.eclipse.jface.text.ITextSelection) OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)

Example 48 with OutlineItem

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

the class WikiTextSourceEditor method show.

public boolean show(ShowInContext context) {
    ISelection selection = context.getSelection();
    if (selection instanceof IStructuredSelection) {
        for (Object element : ((IStructuredSelection) selection).toArray()) {
            if (element instanceof OutlineItem) {
                OutlineItem item = (OutlineItem) element;
                selectAndReveal(item);
                if (outlinePage != null && outlinePage.getControl() != null && !outlinePage.getControl().isDisposed()) {
                    outlinePage.setSelection(selection);
                }
                return true;
            }
        }
    } else if (selection instanceof ITextSelection) {
        ITextSelection textSel = (ITextSelection) selection;
        selectAndReveal(textSel.getOffset(), textSel.getLength());
        return true;
    }
    return false;
}
Also used : ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ITextSelection(org.eclipse.jface.text.ITextSelection) OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)

Example 49 with OutlineItem

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

the class WikiTextSourceEditor method detectOutlineLocationChanged.

private void detectOutlineLocationChanged() {
    OutlineItem nearestItem = getNearestMatchingOutlineItem();
    if (nearestItem != outlineLocation && (nearestItem == null || !nearestItem.equals(outlineLocation))) {
        outlineLocation = nearestItem;
        firePropertyChange(PROP_OUTLINE_LOCATION);
    }
}
Also used : OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)

Example 50 with OutlineItem

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

the class DefaultWikiTextSourceEditorOutline method revealInEditor.

private void revealInEditor(ISelection selection) {
    if (disableReveal) {
        return;
    }
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structuredSelection = (IStructuredSelection) selection;
        Object firstElement = structuredSelection.getFirstElement();
        if (firstElement instanceof OutlineItem) {
            OutlineItem item = (OutlineItem) firstElement;
            if (getEditor() != null) {
                IShowInTarget target = (IShowInTarget) getEditor().getAdapter(IShowInTarget.class);
                if (target != null) {
                    target.show(new ShowInContext(null, new StructuredSelection(item)));
                }
            }
        }
    }
}
Also used : IShowInTarget(org.eclipse.ui.part.IShowInTarget) ShowInContext(org.eclipse.ui.part.ShowInContext) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) 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