Search in sources :

Example 66 with TextAttributes

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

the class TodoDirNode method updateImpl.

@Override
protected void updateImpl(PresentationData data) {
    super.updateImpl(data);
    int fileCount = getFileCount(getValue());
    if (getValue() == null || !getValue().isValid() || fileCount == 0) {
        setValue(null);
        return;
    }
    VirtualFile directory = getValue().getVirtualFile();
    boolean isProjectRoot = !ProjectRootManager.getInstance(getProject()).getFileIndex().isInContent(directory);
    String newName = isProjectRoot || getStructure().getIsFlattenPackages() ? getValue().getVirtualFile().getPresentableUrl() : getValue().getName();
    int nameEndOffset = newName.length();
    int todoItemCount = getTodoItemCount(getValue());
    newName = IdeBundle.message("node.todo.group", newName, todoItemCount, fileCount);
    myHighlightedRegions.clear();
    TextAttributes textAttributes = new TextAttributes();
    Color newColor = FileStatusManager.getInstance(getProject()).getStatus(getValue().getVirtualFile()).getColor();
    if (CopyPasteManager.getInstance().isCutElement(getValue())) {
        newColor = CopyPasteManager.CUT_COLOR;
    }
    textAttributes.setForegroundColor(newColor);
    myHighlightedRegions.add(new HighlightedRegion(0, nameEndOffset, textAttributes));
    EditorColorsScheme colorsScheme = UsageTreeColorsScheme.getInstance().getScheme();
    myHighlightedRegions.add(new HighlightedRegion(nameEndOffset, newName.length(), colorsScheme.getAttributes(UsageTreeColors.NUMBER_OF_USAGES)));
    data.setPresentableText(newName);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) HighlightedRegion(com.intellij.ui.HighlightedRegion) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme)

Example 67 with TextAttributes

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

the class TodoFileNode method updateImpl.

@Override
protected void updateImpl(PresentationData data) {
    super.updateImpl(data);
    String newName;
    if (myBuilder.getTodoTreeStructure().isPackagesShown()) {
        newName = getValue().getName();
    } else {
        newName = mySingleFileMode ? getValue().getName() : getValue().getVirtualFile().getPresentableUrl();
    }
    int nameEndOffset = newName.length();
    int todoItemCount;
    try {
        todoItemCount = myBuilder.getTodoTreeStructure().getTodoItemCount(getValue());
    } catch (IndexNotReadyException e) {
        return;
    }
    if (mySingleFileMode) {
        if (todoItemCount == 0) {
            newName = IdeBundle.message("node.todo.no.items.found", newName);
        } else {
            newName = IdeBundle.message("node.todo.found.items", newName, todoItemCount);
        }
    } else {
        newName = IdeBundle.message("node.todo.items", newName, todoItemCount);
    }
    myHighlightedRegions.clear();
    TextAttributes textAttributes = new TextAttributes();
    textAttributes.setForegroundColor(myColor);
    myHighlightedRegions.add(new HighlightedRegion(0, nameEndOffset, textAttributes));
    EditorColorsScheme colorsScheme = UsageTreeColorsScheme.getInstance().getScheme();
    myHighlightedRegions.add(new HighlightedRegion(nameEndOffset, newName.length(), colorsScheme.getAttributes(UsageTreeColors.NUMBER_OF_USAGES)));
}
Also used : IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) HighlightedRegion(com.intellij.ui.HighlightedRegion) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme)

Example 68 with TextAttributes

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

the class TodoItemNode method update.

@Override
public void update(PresentationData presentation) {
    TodoItem todoItem = getValue().getTodoItem();
    RangeMarker myRangeMarker = getValue().getRangeMarker();
    if (!todoItem.getFile().isValid() || !myRangeMarker.isValid() || myRangeMarker.getStartOffset() == myRangeMarker.getEndOffset()) {
        myRangeMarker.dispose();
        setValue(null);
        return;
    }
    myHighlightedRegions.clear();
    // Update name
    Document document = getValue().getDocument();
    CharSequence chars = document.getCharsSequence();
    int startOffset = myRangeMarker.getStartOffset();
    int endOffset = myRangeMarker.getEndOffset();
    LOG.assertTrue(startOffset > -1);
    LOG.assertTrue(startOffset <= document.getTextLength());
    LOG.assertTrue(endOffset > -1);
    LOG.assertTrue(endOffset < document.getTextLength() + 1);
    int lineNumber = document.getLineNumber(startOffset);
    LOG.assertTrue(lineNumber > -1);
    LOG.assertTrue(lineNumber < document.getLineCount());
    int lineStartOffset = document.getLineStartOffset(lineNumber);
    LOG.assertTrue(lineStartOffset > -1);
    LOG.assertTrue(lineStartOffset <= startOffset);
    LOG.assertTrue(lineStartOffset <= document.getTextLength());
    int columnNumber = startOffset - lineStartOffset;
    LOG.assertTrue(columnNumber > -1);
    while (lineStartOffset < document.getTextLength() && (chars.charAt(lineStartOffset) == '\t' || chars.charAt(lineStartOffset) == ' ')) {
        lineStartOffset++;
    }
    int lineEndOffset = document.getLineEndOffset(lineNumber);
    LOG.assertTrue(lineEndOffset >= 0);
    LOG.assertTrue(lineEndOffset <= document.getTextLength());
    String lineColumnPrefix = "(" + (lineNumber + 1) + ", " + (columnNumber + 1) + ") ";
    String highlightedText = chars.subSequence(lineStartOffset, Math.min(lineEndOffset, chars.length())).toString();
    String newName = lineColumnPrefix + highlightedText;
    // Update icon
    Icon newIcon = todoItem.getPattern().getAttributes().getIcon();
    // Update highlighted regions
    myHighlightedRegions.clear();
    EditorHighlighter highlighter = myBuilder.getHighlighter(todoItem.getFile(), document);
    HighlighterIterator iterator = highlighter.createIterator(lineStartOffset);
    while (!iterator.atEnd()) {
        int start = Math.max(iterator.getStart(), lineStartOffset);
        int end = Math.min(iterator.getEnd(), lineEndOffset);
        if (lineEndOffset < start || lineEndOffset < end) {
            break;
        }
        TextAttributes attributes = iterator.getTextAttributes();
        int fontType = attributes.getFontType();
        if ((fontType & Font.BOLD) != 0) {
            // suppress bold attribute
            attributes = attributes.clone();
            attributes.setFontType(fontType & ~Font.BOLD);
        }
        HighlightedRegion region = new HighlightedRegion(lineColumnPrefix.length() + start - lineStartOffset, lineColumnPrefix.length() + end - lineStartOffset, attributes);
        myHighlightedRegions.add(region);
        iterator.advance();
    }
    TextAttributes attributes = todoItem.getPattern().getAttributes().getTextAttributes();
    HighlightedRegion region = new HighlightedRegion(lineColumnPrefix.length() + startOffset - lineStartOffset, lineColumnPrefix.length() + endOffset - lineStartOffset, attributes);
    myHighlightedRegions.add(region);
    //
    presentation.setPresentableText(newName);
    presentation.setIcon(newIcon);
}
Also used : TodoItem(com.intellij.psi.search.TodoItem) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) HighlightedRegion(com.intellij.ui.HighlightedRegion) RangeMarker(com.intellij.openapi.editor.RangeMarker) Document(com.intellij.openapi.editor.Document) HighlighterIterator(com.intellij.openapi.editor.highlighter.HighlighterIterator) EditorHighlighter(com.intellij.openapi.editor.highlighter.EditorHighlighter)

Example 69 with TextAttributes

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

the class SingleInspectionProfilePanel method copyUsedSeveritiesIfUndefined.

private static void copyUsedSeveritiesIfUndefined(InspectionProfileImpl selectedProfile, BaseInspectionProfileManager profileManager) {
    final SeverityRegistrar registrar = profileManager.getSeverityRegistrar();
    final Set<HighlightSeverity> severities = selectedProfile.getUsedSeverities();
    for (Iterator<HighlightSeverity> iterator = severities.iterator(); iterator.hasNext(); ) {
        HighlightSeverity severity = iterator.next();
        if (registrar.isSeverityValid(severity.getName())) {
            iterator.remove();
        }
    }
    if (!severities.isEmpty()) {
        final SeverityRegistrar oppositeRegister = selectedProfile.getProfileManager().getSeverityRegistrar();
        for (HighlightSeverity severity : severities) {
            final TextAttributesKey attributesKey = TextAttributesKey.find(severity.getName());
            final TextAttributes textAttributes = oppositeRegister.getTextAttributesBySeverity(severity);
            if (textAttributes == null) {
                continue;
            }
            HighlightInfoType.HighlightInfoTypeImpl info = new HighlightInfoType.HighlightInfoTypeImpl(severity, attributesKey);
            registrar.registerSeverity(new SeverityRegistrar.SeverityBasedTextAttributes(textAttributes.clone(), info), textAttributes.getErrorStripeColor());
        }
    }
}
Also used : HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey) SeverityRegistrar(com.intellij.codeInsight.daemon.impl.SeverityRegistrar) HighlightInfoType(com.intellij.codeInsight.daemon.impl.HighlightInfoType)

Example 70 with TextAttributes

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

the class InplaceRefactoring method addHighlights.

protected void addHighlights(@NotNull Map<TextRange, TextAttributes> ranges, @NotNull Editor editor, @NotNull Collection<RangeHighlighter> highlighters, @NotNull HighlightManager highlightManager) {
    for (Map.Entry<TextRange, TextAttributes> entry : ranges.entrySet()) {
        TextRange range = entry.getKey();
        TextAttributes attributes = entry.getValue();
        highlightManager.addOccurrenceHighlight(editor, range.getStartOffset(), range.getEndOffset(), attributes, 0, highlighters, null);
    }
    for (RangeHighlighter highlighter : highlighters) {
        highlighter.setGreedyToLeft(true);
        highlighter.setGreedyToRight(true);
    }
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes)

Aggregations

TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)205 EditorColorsManager (com.intellij.openapi.editor.colors.EditorColorsManager)40 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)31 NotNull (org.jetbrains.annotations.NotNull)29 TextAttributesKey (com.intellij.openapi.editor.colors.TextAttributesKey)28 HighlightManager (com.intellij.codeInsight.highlighting.HighlightManager)26 RangeHighlighter (com.intellij.openapi.editor.markup.RangeHighlighter)26 SimpleTextAttributes (com.intellij.ui.SimpleTextAttributes)23 TextRange (com.intellij.openapi.util.TextRange)21 Nullable (org.jetbrains.annotations.Nullable)21 ArrayList (java.util.ArrayList)19 Editor (com.intellij.openapi.editor.Editor)18 Project (com.intellij.openapi.project.Project)17 PsiElement (com.intellij.psi.PsiElement)12 HighlightInfoType (com.intellij.codeInsight.daemon.impl.HighlightInfoType)10 VirtualFile (com.intellij.openapi.vfs.VirtualFile)10 JBColor (com.intellij.ui.JBColor)10 Document (com.intellij.openapi.editor.Document)9 ContainerUtil (com.intellij.util.containers.ContainerUtil)9 HighlightSeverity (com.intellij.lang.annotation.HighlightSeverity)8