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);
}
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)));
}
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);
}
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());
}
}
}
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);
}
}
Aggregations