Search in sources :

Example 56 with RangeMarker

use of com.intellij.openapi.editor.RangeMarker in project intellij-community by JetBrains.

the class EventLog method formatForLog.

public static LogEntry formatForLog(@NotNull final Notification notification, final String indent) {
    DocumentImpl logDoc = new DocumentImpl("", true);
    AtomicBoolean showMore = new AtomicBoolean(false);
    Map<RangeMarker, HyperlinkInfo> links = new LinkedHashMap<>();
    List<RangeMarker> lineSeparators = new ArrayList<>();
    String title = notification.getTitle();
    String subtitle = notification.getSubtitle();
    if (StringUtil.isNotEmpty(title) && StringUtil.isNotEmpty(subtitle)) {
        title += " (" + subtitle + ")";
    }
    title = truncateLongString(showMore, title);
    String content = truncateLongString(showMore, notification.getContent());
    RangeMarker afterTitle = null;
    boolean hasHtml = parseHtmlContent(addIndents(title, indent), notification, logDoc, showMore, links, lineSeparators);
    if (StringUtil.isNotEmpty(title)) {
        if (StringUtil.isNotEmpty(content)) {
            appendText(logDoc, ": ");
            afterTitle = logDoc.createRangeMarker(logDoc.getTextLength() - 2, logDoc.getTextLength());
        }
    }
    int titleLength = logDoc.getTextLength();
    hasHtml |= parseHtmlContent(addIndents(content, indent), notification, logDoc, showMore, links, lineSeparators);
    List<AnAction> actions = notification.getActions();
    if (!actions.isEmpty()) {
        String text = "<p>" + StringUtil.join(actions, new Function<AnAction, String>() {

            private int index;

            @Override
            public String fun(AnAction action) {
                return "<a href=\"" + index++ + "\">" + action.getTemplatePresentation().getText() + "</a>";
            }
        }, isLongLine(actions) ? "<br>" : "&nbsp;") + "</p>";
        Notification n = new Notification("", "", ".", NotificationType.INFORMATION, new NotificationListener() {

            @Override
            public void hyperlinkUpdate(@NotNull Notification n, @NotNull HyperlinkEvent event) {
                Notification.fire(notification, notification.getActions().get(Integer.parseInt(event.getDescription())));
            }
        });
        if (title.length() > 0 || content.length() > 0) {
            lineSeparators.add(logDoc.createRangeMarker(TextRange.from(logDoc.getTextLength(), 0)));
        }
        hasHtml |= parseHtmlContent(text, n, logDoc, showMore, links, lineSeparators);
    }
    String status = getStatusText(logDoc, showMore, lineSeparators, indent, hasHtml);
    indentNewLines(logDoc, lineSeparators, afterTitle, hasHtml, indent);
    ArrayList<Pair<TextRange, HyperlinkInfo>> list = new ArrayList<>();
    for (RangeMarker marker : links.keySet()) {
        if (!marker.isValid()) {
            showMore.set(true);
            continue;
        }
        list.add(Pair.create(new TextRange(marker.getStartOffset(), marker.getEndOffset()), links.get(marker)));
    }
    if (showMore.get()) {
        String sb = "show balloon";
        if (!logDoc.getText().endsWith(" ")) {
            appendText(logDoc, " ");
        }
        appendText(logDoc, "(" + sb + ")");
        list.add(new Pair<>(TextRange.from(logDoc.getTextLength() - 1 - sb.length(), sb.length()), new ShowBalloon(notification)));
    }
    return new LogEntry(logDoc.getText(), status, list, titleLength);
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) RangeMarker(com.intellij.openapi.editor.RangeMarker) DocumentImpl(com.intellij.openapi.editor.impl.DocumentImpl) AnAction(com.intellij.openapi.actionSystem.AnAction) RelativePoint(com.intellij.ui.awt.RelativePoint) LinkedHashMap(com.intellij.util.containers.hash.LinkedHashMap) HyperlinkInfo(com.intellij.execution.filters.HyperlinkInfo) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Example 57 with RangeMarker

use of com.intellij.openapi.editor.RangeMarker in project intellij-community by JetBrains.

the class DocumentWindowImpl method createRangeMarker.

@Override
@NotNull
public RangeMarker createRangeMarker(final int startOffset, final int endOffset, final boolean surviveOnExternalChange) {
    if (!surviveOnExternalChange) {
        return createRangeMarker(startOffset, endOffset);
    }
    ProperTextRange hostRange = injectedToHost(new ProperTextRange(startOffset, endOffset));
    //todo persistent?
    RangeMarker hostMarker = myDelegate.createRangeMarker(hostRange.getStartOffset(), hostRange.getEndOffset(), surviveOnExternalChange);
    int startShift = Math.max(0, hostToInjected(hostRange.getStartOffset()) - startOffset);
    int endShift = Math.max(0, endOffset - hostToInjected(hostRange.getEndOffset()) - startShift);
    return new RangeMarkerWindow(this, (RangeMarkerEx) hostMarker, startShift, endShift);
}
Also used : RangeMarker(com.intellij.openapi.editor.RangeMarker) NotNull(org.jetbrains.annotations.NotNull)

Example 58 with RangeMarker

use of com.intellij.openapi.editor.RangeMarker in project intellij-community by JetBrains.

the class DocumentWindowImpl method createRangeMarker.

@Override
@NotNull
public RangeMarker createRangeMarker(final int startOffset, final int endOffset) {
    ProperTextRange hostRange = injectedToHost(new ProperTextRange(startOffset, endOffset));
    RangeMarker hostMarker = myDelegate.createRangeMarker(hostRange);
    int startShift = Math.max(0, hostToInjected(hostRange.getStartOffset()) - startOffset);
    int endShift = Math.max(0, endOffset - hostToInjected(hostRange.getEndOffset()) - startShift);
    return new RangeMarkerWindow(this, (RangeMarkerEx) hostMarker, startShift, endShift);
}
Also used : RangeMarker(com.intellij.openapi.editor.RangeMarker) NotNull(org.jetbrains.annotations.NotNull)

Example 59 with RangeMarker

use of com.intellij.openapi.editor.RangeMarker in project intellij-community by JetBrains.

the class SliceTestUtil method extract.

private static void extract(final Document document, final Map<String, RangeMarker> sliceUsageName2Offset, final String name) {
    WriteCommandAction.runWriteCommandAction(null, () -> {
        for (int i = 1; i < 9; i++) {
            String newName = name + i;
            String s = "<flown" + newName + ">";
            if (!document.getText().contains(s))
                break;
            int off = document.getText().indexOf(s);
            document.deleteString(off, off + s.length());
            RangeMarker prev = sliceUsageName2Offset.put(newName, document.createRangeMarker(off, off));
            assertNull(prev);
            extract(document, sliceUsageName2Offset, newName);
        }
    });
}
Also used : RangeMarker(com.intellij.openapi.editor.RangeMarker)

Example 60 with RangeMarker

use of com.intellij.openapi.editor.RangeMarker in project intellij-community by JetBrains.

the class ExpectedHighlightingData method refreshLineMarkers.

private void refreshLineMarkers() {
    for (Map.Entry<RangeMarker, LineMarkerInfo> entry : myLineMarkerInfos.entrySet()) {
        RangeMarker rangeMarker = entry.getKey();
        int startOffset = rangeMarker.getStartOffset();
        int endOffset = rangeMarker.getEndOffset();
        LineMarkerInfo value = entry.getValue();
        PsiElement element = value.getElement();
        assert element != null : value;
        TextRange range = new TextRange(startOffset, endOffset);
        final String tooltip = value.getLineMarkerTooltip();
        LineMarkerInfo markerInfo = new LineMarkerInfo<>(element, range, null, value.updatePass, e -> tooltip, null, GutterIconRenderer.Alignment.RIGHT);
        entry.setValue(markerInfo);
    }
}
Also used : LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) RangeMarker(com.intellij.openapi.editor.RangeMarker) THashMap(gnu.trove.THashMap) PsiElement(com.intellij.psi.PsiElement)

Aggregations

RangeMarker (com.intellij.openapi.editor.RangeMarker)111 Document (com.intellij.openapi.editor.Document)33 TextRange (com.intellij.openapi.util.TextRange)20 Project (com.intellij.openapi.project.Project)19 PsiFile (com.intellij.psi.PsiFile)14 PsiElement (com.intellij.psi.PsiElement)13 IncorrectOperationException (com.intellij.util.IncorrectOperationException)13 Editor (com.intellij.openapi.editor.Editor)11 Nullable (org.jetbrains.annotations.Nullable)11 NotNull (org.jetbrains.annotations.NotNull)10 Template (com.intellij.codeInsight.template.Template)8 TemplateBuilderImpl (com.intellij.codeInsight.template.TemplateBuilderImpl)7 TemplateEditingAdapter (com.intellij.codeInsight.template.TemplateEditingAdapter)6 PsiDocumentManager (com.intellij.psi.PsiDocumentManager)6 RangeHighlighterEx (com.intellij.openapi.editor.ex.RangeHighlighterEx)5 THashMap (gnu.trove.THashMap)5 GutterMark (com.intellij.codeInsight.daemon.GutterMark)4 HighlightSeverity (com.intellij.lang.annotation.HighlightSeverity)4 ApplicationManager (com.intellij.openapi.application.ApplicationManager)4 RelativePoint (com.intellij.ui.awt.RelativePoint)4