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()]);
}
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;
}
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;
}
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);
}
}
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)));
}
}
}
}
}
Aggregations