use of org.eclipse.mylyn.wikitext.parser.outline.OutlineItem in project mylyn.docs by eclipse.
the class DitaTopicDocumentBuilder method computeDitaXref.
/**
* According to the DITA documentation, DITA content URLs use special syntax. this method translates internal URLs
* correctly according to the DITA rules.
*
* @return the href adjusted, or the original href if the given URL appears to be to non-document content
*/
private String computeDitaXref(String href) {
if (href.startsWith("#") && topicBreakLevel < Integer.MAX_VALUE) {
// $NON-NLS-1$
if (outline != null) {
OutlineItem item = outline.findItemById(href.substring(1));
if (item != null) {
OutlineItem topicItem = computeTopicFileItem(item);
String targetFilename = computeTargetFilename(topicItem);
String ref;
if (targetFilename.equals(filename)) {
ref = href;
} else {
ref = targetFilename + href;
}
return ref;
}
}
}
return href;
}
use of org.eclipse.mylyn.wikitext.parser.outline.OutlineItem in project mylyn.docs by eclipse.
the class MarkupEditor method createProjectionAnnotations.
private void createProjectionAnnotations(List<Annotation> newProjectionAnnotations, Map<HeadingProjectionAnnotation, Position> annotationToPosition, List<OutlineItem> children, int endOffset) {
final int size = children.size();
final int lastIndex = size - 1;
for (int x = 0; x < size; ++x) {
OutlineItem child = children.get(x);
if (child.getId() == null || child.getId().length() == 0) {
continue;
}
int offset = child.getOffset();
int end;
if (x == lastIndex) {
end = endOffset;
} else {
end = children.get(x + 1).getOffset();
}
int length = end - offset;
if (length > 0) {
HeadingProjectionAnnotation annotation = new HeadingProjectionAnnotation(child.getId());
Position position = new Position(offset, length);
newProjectionAnnotations.add(annotation);
annotationToPosition.put(annotation, position);
}
if (!child.getChildren().isEmpty()) {
createProjectionAnnotations(newProjectionAnnotations, annotationToPosition, child.getChildren(), end);
}
}
}
use of org.eclipse.mylyn.wikitext.parser.outline.OutlineItem in project mylyn.docs by eclipse.
the class MarkupEditor method updateProjectionAnnotations.
private void updateProjectionAnnotations() {
ProjectionViewer viewer = (ProjectionViewer) getSourceViewer();
ProjectionAnnotationModel projectionAnnotationModel = viewer.getProjectionAnnotationModel();
if (projectionAnnotationModel != null) {
List<Annotation> newProjectionAnnotations = new ArrayList<>(projectionAnnotationById == null ? 10 : projectionAnnotationById.size() + 2);
Map<HeadingProjectionAnnotation, Position> annotationToPosition = new HashMap<>();
List<OutlineItem> children = outlineModel.getChildren();
if (!children.isEmpty()) {
createProjectionAnnotations(newProjectionAnnotations, annotationToPosition, children, document.getLength());
}
if (newProjectionAnnotations.isEmpty() && (projectionAnnotationById == null || projectionAnnotationById.isEmpty())) {
return;
}
Map<String, HeadingProjectionAnnotation> newProjectionAnnotationById = new HashMap<>();
if (projectionAnnotationById != null) {
Set<HeadingProjectionAnnotation> toDelete = new HashSet<>(projectionAnnotationById.size());
Iterator<Entry<HeadingProjectionAnnotation, Position>> newPositionIt = annotationToPosition.entrySet().iterator();
while (newPositionIt.hasNext()) {
Entry<HeadingProjectionAnnotation, Position> newAnnotationEnt = newPositionIt.next();
HeadingProjectionAnnotation newAnnotation = newAnnotationEnt.getKey();
Position newPosition = newAnnotationEnt.getValue();
HeadingProjectionAnnotation annotation = projectionAnnotationById.get(newAnnotation.getHeadingId());
if (annotation != null) {
Position position = projectionAnnotationModel.getPosition(annotation);
if (newPosition.equals(position)) {
newPositionIt.remove();
newProjectionAnnotationById.put(annotation.getHeadingId(), annotation);
} else {
toDelete.add(annotation);
if (annotation.isCollapsed()) {
newAnnotation.markCollapsed();
} else {
newAnnotation.markExpanded();
}
newProjectionAnnotationById.put(annotation.getHeadingId(), newAnnotation);
}
} else {
newProjectionAnnotationById.put(newAnnotation.getHeadingId(), newAnnotation);
}
}
@SuppressWarnings("unchecked") Iterator<Annotation> annotationIt = projectionAnnotationModel.getAnnotationIterator();
while (annotationIt.hasNext()) {
Annotation annotation = annotationIt.next();
if (annotation instanceof HeadingProjectionAnnotation) {
HeadingProjectionAnnotation projectionAnnotation = (HeadingProjectionAnnotation) annotation;
if (!projectionAnnotationById.containsKey(projectionAnnotation.getHeadingId()) && !toDelete.contains(projectionAnnotation)) {
toDelete.add(projectionAnnotation);
}
}
}
projectionAnnotationModel.modifyAnnotations(toDelete.isEmpty() ? null : toDelete.toArray(new Annotation[toDelete.size()]), annotationToPosition, null);
} else {
projectionAnnotationModel.modifyAnnotations(null, annotationToPosition, null);
for (HeadingProjectionAnnotation annotation : annotationToPosition.keySet()) {
newProjectionAnnotationById.put(annotation.getHeadingId(), annotation);
}
}
projectionAnnotationById = newProjectionAnnotationById;
} else {
projectionAnnotationById = null;
}
}
use of org.eclipse.mylyn.wikitext.parser.outline.OutlineItem in project mylyn.docs by eclipse.
the class MarkupEditor method updateOutline.
private void updateOutline() {
if (!outlineDirty) {
return;
}
if (!isSourceViewerValid()) {
return;
}
// we maintain the outline even if the outline page is not in use, which allows us to use the outline for
// content assist and other things
MarkupLanguage markupLanguage = getMarkupLanguage();
if (markupLanguage == null) {
return;
}
final MarkupLanguage language = markupLanguage.clone();
final Display display = getSourceViewer().getTextWidget().getDisplay();
final String content = document.get();
final int contentGeneration;
synchronized (MarkupEditor.this) {
contentGeneration = documentGeneration;
}
// we parse the outline in another thread so that the UI remains responsive
Job parseOutlineJob = new // $NON-NLS-1$
Job(// $NON-NLS-1$
MarkupEditor.class.getSimpleName() + "#updateOutline") {
@Override
protected IStatus run(IProgressMonitor monitor) {
outlineParser.setMarkupLanguage(language);
if (shouldCancel()) {
return Status.CANCEL_STATUS;
}
final OutlineItem rootItem = outlineParser.parse(content);
if (shouldCancel()) {
return Status.CANCEL_STATUS;
}
display.asyncExec(new Runnable() {
public void run() {
updateOutline(contentGeneration, rootItem);
}
});
return Status.OK_STATUS;
}
private boolean shouldCancel() {
synchronized (MarkupEditor.this) {
if (contentGeneration != documentGeneration) {
return true;
}
}
return false;
}
};
parseOutlineJob.setPriority(Job.INTERACTIVE);
parseOutlineJob.setSystem(true);
parseOutlineJob.schedule();
}
use of org.eclipse.mylyn.wikitext.parser.outline.OutlineItem in project mylyn.docs by eclipse.
the class MarkupEditorOutline method revealInEditor.
private void revealInEditor(ISelection selection, boolean open) {
if (disableReveal) {
return;
}
if (selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
Object firstElement = structuredSelection.getFirstElement();
if (firstElement instanceof OutlineItem) {
OutlineItem item = (OutlineItem) firstElement;
editor.selectAndReveal(item);
}
}
}
Aggregations