use of com.intellij.openapi.editor.markup.TextAttributes in project intellij-community by JetBrains.
the class HighlightUsagesHandlerBase method performHighlighting.
protected void performHighlighting() {
boolean clearHighlights = HighlightUsagesHandler.isClearHighlights(myEditor);
EditorColorsManager manager = EditorColorsManager.getInstance();
TextAttributes attributes = manager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
TextAttributes writeAttributes = manager.getGlobalScheme().getAttributes(EditorColors.WRITE_SEARCH_RESULT_ATTRIBUTES);
HighlightUsagesHandler.highlightRanges(HighlightManager.getInstance(myEditor.getProject()), myEditor, attributes, clearHighlights, myReadUsages);
HighlightUsagesHandler.highlightRanges(HighlightManager.getInstance(myEditor.getProject()), myEditor, writeAttributes, clearHighlights, myWriteUsages);
if (!clearHighlights) {
WindowManager.getInstance().getStatusBar(myEditor.getProject()).setInfo(myStatusText);
// enable f3 navigation
HighlightHandlerBase.setupFindModel(myEditor.getProject());
}
if (myHintText != null) {
HintManager.getInstance().showInformationHint(myEditor, myHintText);
}
}
use of com.intellij.openapi.editor.markup.TextAttributes in project intellij-community by JetBrains.
the class SeverityEditorDialog method doOKAction.
@Override
protected void doOKAction() {
apply((SeverityBasedTextAttributes) myOptionsList.getSelectedValue());
final Collection<SeverityBasedTextAttributes> infoTypes = new HashSet<>(SeverityUtil.getRegisteredHighlightingInfoTypes(mySeverityRegistrar));
final ListModel listModel = myOptionsList.getModel();
final List<HighlightSeverity> order = new ArrayList<>();
for (int i = listModel.getSize() - 1; i >= 0; i--) {
SeverityBasedTextAttributes info = (SeverityBasedTextAttributes) listModel.getElementAt(i);
order.add(info.getSeverity());
if (!mySeverityRegistrar.isDefaultSeverity(info.getSeverity())) {
infoTypes.remove(info);
final Color stripeColor = info.getAttributes().getErrorStripeColor();
final boolean exists = mySeverityRegistrar.getSeverity(info.getSeverity().getName()) != null;
if (exists) {
info.getType().getAttributesKey().getDefaultAttributes().setErrorStripeColor(stripeColor);
} else {
HighlightInfoType.HighlightInfoTypeImpl type = info.getType();
TextAttributesKey key = type.getAttributesKey();
final TextAttributes defaultAttributes = key.getDefaultAttributes().clone();
defaultAttributes.setErrorStripeColor(stripeColor);
key = TextAttributesKey.createTextAttributesKey(key.getExternalName(), defaultAttributes);
type = new HighlightInfoType.HighlightInfoTypeImpl(type.getSeverity(null), key);
info = new SeverityBasedTextAttributes(info.getAttributes(), type);
}
mySeverityRegistrar.registerSeverity(info, stripeColor != null ? stripeColor : LightColors.YELLOW);
}
}
for (SeverityBasedTextAttributes info : infoTypes) {
mySeverityRegistrar.unregisterSeverity(info.getSeverity());
}
mySeverityRegistrar.setOrder(order);
super.doOKAction();
}
use of com.intellij.openapi.editor.markup.TextAttributes in project intellij-community by JetBrains.
the class FindUtil method doSearch.
@Nullable
private static FindResult doSearch(@NotNull Project project, @NotNull final Editor editor, int offset, boolean toWarn, @NotNull FindModel model, boolean adjustEditor) {
FindManager findManager = FindManager.getInstance(project);
Document document = editor.getDocument();
final FindResult result = findManager.findString(document.getCharsSequence(), offset, model, getVirtualFile(editor));
boolean isFound = result.isStringFound();
final SelectionModel selection = editor.getSelectionModel();
if (isFound && !model.isGlobal()) {
if (!selectionMayContainRange(selection, result)) {
isFound = false;
} else if (!selectionStrictlyContainsRange(selection, result)) {
final int[] starts = selection.getBlockSelectionStarts();
for (int newOffset : starts) {
if (newOffset > result.getStartOffset()) {
return doSearch(project, editor, newOffset, toWarn, model, adjustEditor);
}
}
}
}
if (!isFound) {
if (toWarn) {
processNotFound(editor, model.getStringToFind(), model, project);
}
return null;
}
if (adjustEditor) {
final CaretModel caretModel = editor.getCaretModel();
final ScrollingModel scrollingModel = editor.getScrollingModel();
int oldCaretOffset = caretModel.getOffset();
boolean forward = oldCaretOffset < result.getStartOffset();
final ScrollType scrollType = forward ? ScrollType.CENTER_DOWN : ScrollType.CENTER_UP;
if (model.isGlobal()) {
int targetCaretPosition = result.getEndOffset();
if (selection.getSelectionEnd() - selection.getSelectionStart() == result.getLength()) {
// keeping caret's position relative to selection
// use case: FindNext is used after SelectNextOccurrence action
targetCaretPosition = caretModel.getOffset() - selection.getSelectionStart() + result.getStartOffset();
}
if (caretModel.getCaretAt(editor.offsetToVisualPosition(targetCaretPosition)) != null) {
// use case: FindNext is used after SelectNextOccurrence action
return result;
}
caretModel.moveToOffset(targetCaretPosition);
selection.removeSelection();
scrollingModel.scrollToCaret(scrollType);
scrollingModel.runActionOnScrollingFinished(() -> {
scrollingModel.scrollTo(editor.offsetToLogicalPosition(result.getStartOffset()), scrollType);
scrollingModel.scrollTo(editor.offsetToLogicalPosition(result.getEndOffset()), scrollType);
});
} else {
moveCaretAndDontChangeSelection(editor, result.getStartOffset(), scrollType);
moveCaretAndDontChangeSelection(editor, result.getEndOffset(), scrollType);
}
IdeDocumentHistory.getInstance(project).includeCurrentCommandAsNavigation();
EditorColorsManager manager = EditorColorsManager.getInstance();
TextAttributes selectionAttributes = manager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
if (!model.isGlobal()) {
final RangeHighlighterEx segmentHighlighter = (RangeHighlighterEx) editor.getMarkupModel().addRangeHighlighter(result.getStartOffset(), result.getEndOffset(), HighlighterLayer.SELECTION + 1, selectionAttributes, HighlighterTargetArea.EXACT_RANGE);
MyListener listener = new MyListener(editor, segmentHighlighter);
caretModel.addCaretListener(listener);
} else {
selection.setSelection(result.getStartOffset(), result.getEndOffset());
}
}
return result;
}
use of com.intellij.openapi.editor.markup.TextAttributes in project intellij-community by JetBrains.
the class SearchEverywherePsiRenderer method customizeNonPsiElementLeftRenderer.
@Override
protected boolean customizeNonPsiElementLeftRenderer(ColoredListCellRenderer renderer, JList list, Object value, int index, boolean selected, boolean hasFocus) {
if (!(value instanceof NavigationItem))
return false;
NavigationItem item = (NavigationItem) value;
TextAttributes attributes = getNavigationItemAttributes(item);
SimpleTextAttributes nameAttributes = attributes != null ? SimpleTextAttributes.fromTextAttributes(attributes) : null;
Color color = list.getForeground();
if (nameAttributes == null)
nameAttributes = new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, color);
renderer.append(item + " ", nameAttributes);
ItemPresentation itemPresentation = item.getPresentation();
assert itemPresentation != null;
renderer.setIcon(itemPresentation.getIcon(true));
String locationString = itemPresentation.getLocationString();
if (!StringUtil.isEmpty(locationString)) {
renderer.append(locationString, new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, JBColor.GRAY));
}
return true;
}
use of com.intellij.openapi.editor.markup.TextAttributes 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);
}
Aggregations