use of org.eclipse.mylyn.wikitext.parser.outline.OutlineItem in project mylyn.docs by eclipse.
the class MarkupEditorOutline method createControl.
@Override
public void createControl(Composite parent) {
super.createControl(parent);
TreeViewer viewer = getTreeViewer();
viewer.setUseHashlookup(true);
viewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);
viewer.setContentProvider(new BaseWorkbenchContentProvider());
viewer.setLabelProvider(WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider());
viewer.setInput(editor.getOutlineModel());
viewer.addOpenListener(new IOpenListener() {
public void open(OpenEvent event) {
revealInEditor(event.getSelection(), true);
}
});
viewer.addPostSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
revealInEditor(event.getSelection(), false);
}
});
viewer.expandAll();
new ToolTip(viewer.getControl(), ToolTip.RECREATE, false) {
@Override
protected Composite createToolTipContentArea(Event event, Composite parent) {
Composite comp = new Composite(parent, SWT.NONE);
comp.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
GridLayout gl = new GridLayout(1, false);
gl.marginBottom = 2;
gl.marginTop = 2;
gl.marginHeight = 0;
gl.marginWidth = 0;
gl.marginLeft = 2;
gl.marginRight = 2;
gl.verticalSpacing = 1;
comp.setLayout(gl);
Object tipItem = getToolTipItem(new Point(event.x, event.y));
if (tipItem instanceof OutlineItem) {
OutlineItem outlineItem = (OutlineItem) tipItem;
Label label = new Label(comp, SWT.WRAP);
label.setBackground(comp.getBackground());
label.setText(outlineItem.getTooltip());
}
return comp;
}
@Override
protected boolean shouldCreateToolTip(Event event) {
final Object eventItem = getToolTipItem(new Point(event.x, event.y));
boolean shouldCreate = eventItem != null && eventItem instanceof OutlineItem && super.shouldCreateToolTip(event);
if (!shouldCreate) {
hide();
}
return shouldCreate;
}
protected Object getToolTipItem(Point point) {
TreeItem item = ((Tree) getTreeViewer().getControl()).getItem(point);
if (item != null) {
return item.getData();
}
return null;
}
};
IPageSite site = getSite();
site.setSelectionProvider(viewer);
configureActionBars(site);
// $NON-NLS-1$
MenuManager manager = new MenuManager("#PopUp");
manager.setRemoveAllWhenShown(true);
manager.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager menuManager) {
contextMenuAboutToShow(menuManager);
}
});
viewer.getTree().setMenu(manager.createContextMenu(viewer.getTree()));
// $NON-NLS-1$
site.registerContextMenu(MarkupEditor.ID + ".outlineContextMenu", manager, viewer);
configureDnd();
configureActions();
}
use of org.eclipse.mylyn.wikitext.parser.outline.OutlineItem in project mylyn.docs by eclipse.
the class OutlineParserTest method testPrevious.
public void testPrevious() {
String textile = "h1. First Header\n\nh2. Second Header\n\nh1. Third Header\n";
OutlineItem outline = outlineParser.parse(textile);
assertNull(outline.getPrevious());
assertSame(outline, outline.getChildren().get(0).getPrevious());
assertSame(outline.getChildren().get(0), outline.getChildren().get(1).getPrevious());
assertSame(outline.getChildren().get(0), outline.getChildren().get(0).getChildren().get(0).getPrevious());
}
use of org.eclipse.mylyn.wikitext.parser.outline.OutlineItem in project mylyn.docs by eclipse.
the class OutlineParserTest method testNearestItem.
public void testNearestItem() {
String textile = "h1. First Header\n\nh2. Second Header\n\nh1. Third Header\n";
OutlineItem outline = outlineParser.parse(textile);
int idxOfH2 = textile.indexOf("h2. Second");
assertTrue(idxOfH2 != -1);
OutlineItem h2Item = outline.findNearestMatchingOffset(idxOfH2);
assertNotNull(h2Item);
assertSame(outline.getChildren().get(0), h2Item.getParent());
assertEquals(2, h2Item.getLevel());
OutlineItem h1Item = outline.findNearestMatchingOffset(idxOfH2 - 1);
assertNotNull(h1Item);
assertSame(outline.getChildren().get(0), h1Item);
assertEquals(1, h1Item.getLevel());
int secondIdxOfH1 = textile.indexOf("h1. Third");
OutlineItem secondH1Item = outline.findNearestMatchingOffset(secondIdxOfH1);
assertNotNull(secondH1Item);
assertSame(outline.getChildren().get(1), secondH1Item);
assertEquals(1, secondH1Item.getLevel());
OutlineItem h2Item2 = outline.findNearestMatchingOffset(secondIdxOfH1 - 1);
assertSame(h2Item, h2Item2);
}
use of org.eclipse.mylyn.wikitext.parser.outline.OutlineItem in project mylyn.docs by eclipse.
the class OutlineParserTest method testHeadersWithHtmlTags.
public void testHeadersWithHtmlTags() {
// bug 374019
outlineParser = new OutlineParser(new MediaWikiLanguage());
OutlineItem outline = outlineParser.parse("= <span style=\"font-family:monospace\">Heading Text</span> =\n\n text");
assertEquals(1, outline.getChildren().size());
OutlineItem headingItem = outline.getChildren().get(0);
assertEquals("Heading_Text", headingItem.getId());
assertEquals("Heading Text", headingItem.getLabel());
}
use of org.eclipse.mylyn.wikitext.parser.outline.OutlineItem in project mylyn.docs by eclipse.
the class WikiTextContextUiBridge method open.
@Override
public void open(IInteractionElement element) {
AbstractContextStructureBridge structureBridge = ContextCore.getStructureBridge(WikiTextContextStructureBridge.CONTENT_TYPE);
if (structureBridge instanceof WikiTextContextStructureBridge) {
Object object = structureBridge.getObjectForHandle(element.getHandleIdentifier());
OutlineItem item = null;
if (object instanceof OutlineItem) {
item = (OutlineItem) object;
object = ((WikiTextContextStructureBridge) structureBridge).getFile(item);
}
if (object instanceof IFile) {
FileEditorInput editorInput = new FileEditorInput((IFile) object);
try {
IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(editorInput, // $NON-NLS-1$
"org.eclipse.mylyn.wikitext.ui.editor.markupEditor");
if (item != null && editor instanceof IShowInTarget) {
((IShowInTarget) editor).show(new ShowInContext(editorInput, new StructuredSelection(item)));
}
} catch (PartInitException e) {
WikiTextContextUiPlugin.getDefault().log(e);
}
}
}
}
Aggregations