Search in sources :

Example 36 with OutlineItem

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;
}
Also used : OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)

Example 37 with OutlineItem

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);
        }
    }
}
Also used : Position(org.eclipse.jface.text.Position) Point(org.eclipse.swt.graphics.Point) OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)

Example 38 with OutlineItem

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;
    }
}
Also used : Position(org.eclipse.jface.text.Position) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Annotation(org.eclipse.jface.text.source.Annotation) OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem) ProjectionAnnotationModel(org.eclipse.jface.text.source.projection.ProjectionAnnotationModel) Entry(java.util.Map.Entry) ProjectionViewer(org.eclipse.jface.text.source.projection.ProjectionViewer) HashSet(java.util.HashSet)

Example 39 with OutlineItem

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();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) AbstractMarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.AbstractMarkupLanguage) MarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage) UIJob(org.eclipse.ui.progress.UIJob) Job(org.eclipse.core.runtime.jobs.Job) Point(org.eclipse.swt.graphics.Point) Display(org.eclipse.swt.widgets.Display) OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)

Example 40 with OutlineItem

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);
        }
    }
}
Also used : 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