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