Search in sources :

Example 1 with HighlightedRegion

use of com.intellij.ui.HighlightedRegion in project intellij-community by JetBrains.

the class ModuleToDoNode method update.

@Override
public void update(PresentationData presentation) {
    if (DumbService.getInstance(getProject()).isDumb())
        return;
    String newName = getValue().getName();
    int nameEndOffset = newName.length();
    int todoItemCount = getTodoItemCount(getValue());
    int fileCount = getFileCount(getValue());
    newName = IdeBundle.message("node.todo.group", newName, todoItemCount, fileCount);
    myHighlightedRegions.clear();
    TextAttributes textAttributes = new TextAttributes();
    if (CopyPasteManager.getInstance().isCutElement(getValue())) {
        textAttributes.setForegroundColor(CopyPasteManager.CUT_COLOR);
    }
    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)));
    presentation.setIcon(ModuleType.get(getValue()).getIcon());
    presentation.setPresentableText(newName);
}
Also used : TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) HighlightedRegion(com.intellij.ui.HighlightedRegion) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme)

Example 2 with HighlightedRegion

use of com.intellij.ui.HighlightedRegion 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 3 with HighlightedRegion

use of com.intellij.ui.HighlightedRegion 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 4 with HighlightedRegion

use of com.intellij.ui.HighlightedRegion 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 5 with HighlightedRegion

use of com.intellij.ui.HighlightedRegion in project intellij-community by JetBrains.

the class TodoPackageNode method update.

@Override
protected void update(PresentationData data) {
    super.update(data);
    final PackageElement packageElement = getValue();
    try {
        if (packageElement == null || !packageElement.getPackage().isValid()) {
            setValue(null);
            return;
        }
        int fileCount = getFileCount(packageElement);
        if (fileCount == 0) {
            setValue(null);
            return;
        }
        PsiPackage aPackage = packageElement.getPackage();
        String newName;
        if (getStructure().areFlattenPackages()) {
            newName = aPackage.getQualifiedName();
        } else {
            newName = myPresentationName != null ? myPresentationName : "";
        }
        int nameEndOffset = newName.length();
        int todoItemCount = getTodoItemCount(packageElement);
        newName = IdeBundle.message("node.todo.group", newName, todoItemCount, fileCount);
        myHighlightedRegions.clear();
        TextAttributes textAttributes = new TextAttributes();
        Color newColor = null;
        if (CopyPasteManager.getInstance().isCutElement(packageElement)) {
            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);
    } catch (IndexNotReadyException e) {
        LOG.info(e);
        data.setPresentableText("N/A");
    }
}
Also used : IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) HighlightedRegion(com.intellij.ui.HighlightedRegion) PsiPackage(com.intellij.psi.PsiPackage) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) PackageElement(com.intellij.ide.projectView.impl.nodes.PackageElement)

Aggregations

TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)5 HighlightedRegion (com.intellij.ui.HighlightedRegion)5 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)4 IndexNotReadyException (com.intellij.openapi.project.IndexNotReadyException)2 PackageElement (com.intellij.ide.projectView.impl.nodes.PackageElement)1 Document (com.intellij.openapi.editor.Document)1 RangeMarker (com.intellij.openapi.editor.RangeMarker)1 EditorHighlighter (com.intellij.openapi.editor.highlighter.EditorHighlighter)1 HighlighterIterator (com.intellij.openapi.editor.highlighter.HighlighterIterator)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiPackage (com.intellij.psi.PsiPackage)1 TodoItem (com.intellij.psi.search.TodoItem)1