use of com.intellij.openapi.editor.colors.EditorColorsManager in project intellij-community by JetBrains.
the class HighlightUtils method highlightElements.
public static void highlightElements(@NotNull final Collection<? extends PsiElement> elementCollection) {
if (elementCollection.isEmpty()) {
return;
}
if (elementCollection.contains(null)) {
throw new IllegalArgumentException("Nulls passed in collection: " + elementCollection);
}
final Application application = ApplicationManager.getApplication();
application.invokeLater(() -> {
final PsiElement[] elements = PsiUtilCore.toPsiElementArray(elementCollection);
final PsiElement firstElement = elements[0];
if (ContainerUtil.exists(elements, element -> !element.isValid())) {
return;
}
final Project project = firstElement.getProject();
if (project.isDisposed())
return;
final FileEditorManager editorManager = FileEditorManager.getInstance(project);
final EditorColorsManager editorColorsManager = EditorColorsManager.getInstance();
final Editor editor = editorManager.getSelectedTextEditor();
if (editor == null) {
return;
}
final EditorColorsScheme globalScheme = editorColorsManager.getGlobalScheme();
final TextAttributes textattributes = globalScheme.getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
final HighlightManager highlightManager = HighlightManager.getInstance(project);
highlightManager.addOccurrenceHighlights(editor, elements, textattributes, true, null);
final WindowManager windowManager = WindowManager.getInstance();
final StatusBar statusBar = windowManager.getStatusBar(project);
statusBar.setInfo(InspectionGadgetsBundle.message("press.escape.to.remove.highlighting.message"));
final FindManager findmanager = FindManager.getInstance(project);
FindModel findmodel = findmanager.getFindNextModel();
if (findmodel == null) {
findmodel = findmanager.getFindInFileModel();
}
findmodel.setSearchHighlighters(true);
findmanager.setFindWasPerformed();
findmanager.setFindNextModel(findmodel);
});
}
use of com.intellij.openapi.editor.colors.EditorColorsManager in project intellij-community by JetBrains.
the class UsagePreviewPanel method highlight.
public static void highlight(@NotNull final List<UsageInfo> infos, @NotNull final Editor editor, @NotNull final Project project, boolean highlightOnlyNameElements, int highlightLayer) {
LOG.assertTrue(!PsiDocumentManager.getInstance(project).hasUncommitedDocuments());
MarkupModel markupModel = editor.getMarkupModel();
for (RangeHighlighter highlighter : markupModel.getAllHighlighters()) {
if (highlighter.getUserData(IN_PREVIEW_USAGE_FLAG) != null) {
highlighter.dispose();
}
}
for (int i = infos.size() - 1; i >= 0; i--) {
// finish with the first usage so that caret end up there
UsageInfo info = infos.get(i);
PsiElement psiElement = info.getElement();
if (psiElement == null || !psiElement.isValid())
continue;
int offsetInFile = psiElement.getTextOffset();
EditorColorsManager colorManager = EditorColorsManager.getInstance();
TextAttributes attributes = colorManager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
TextRange elementRange = psiElement.getTextRange();
TextRange infoRange = info.getRangeInElement();
TextRange textRange = infoRange == null || infoRange.getStartOffset() > elementRange.getLength() || infoRange.getEndOffset() > elementRange.getLength() ? null : elementRange.cutOut(infoRange);
if (textRange == null)
textRange = elementRange;
// hack to determine element range to highlight
if (highlightOnlyNameElements && psiElement instanceof PsiNamedElement && !(psiElement instanceof PsiFile)) {
PsiFile psiFile = psiElement.getContainingFile();
PsiElement nameElement = psiFile.findElementAt(offsetInFile);
if (nameElement != null) {
textRange = nameElement.getTextRange();
}
}
// highlight injected element in host document textrange
textRange = InjectedLanguageManager.getInstance(project).injectedToHost(psiElement, textRange);
RangeHighlighter highlighter = markupModel.addRangeHighlighter(textRange.getStartOffset(), textRange.getEndOffset(), highlightLayer, attributes, HighlighterTargetArea.EXACT_RANGE);
highlighter.putUserData(IN_PREVIEW_USAGE_FLAG, Boolean.TRUE);
editor.getCaretModel().moveToOffset(textRange.getEndOffset());
}
editor.getScrollingModel().scrollToCaret(ScrollType.CENTER);
}
use of com.intellij.openapi.editor.colors.EditorColorsManager in project intellij-community by JetBrains.
the class ExtractMethodHandler method highlightPrepareError.
public static void highlightPrepareError(PrepareFailedException e, PsiFile file, Editor editor, final Project project) {
if (e.getFile() == file) {
final TextRange textRange = e.getTextRange();
final HighlightManager highlightManager = HighlightManager.getInstance(project);
EditorColorsManager colorsManager = EditorColorsManager.getInstance();
TextAttributes attributes = colorsManager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
highlightManager.addRangeHighlight(editor, textRange.getStartOffset(), textRange.getEndOffset(), attributes, true, null);
final LogicalPosition logicalPosition = editor.offsetToLogicalPosition(textRange.getStartOffset());
editor.getScrollingModel().scrollTo(logicalPosition, ScrollType.MAKE_VISIBLE);
WindowManager.getInstance().getStatusBar(project).setInfo(RefactoringBundle.message("press.escape.to.remove.the.highlighting"));
}
}
use of com.intellij.openapi.editor.colors.EditorColorsManager in project intellij-community by JetBrains.
the class RefactoringUtil method highlightAllOccurrences.
/**
* @return List of highlighters
*/
public static List<RangeHighlighter> highlightAllOccurrences(Project project, PsiElement[] occurrences, Editor editor) {
ArrayList<RangeHighlighter> highlighters = new ArrayList<>();
HighlightManager highlightManager = HighlightManager.getInstance(project);
EditorColorsManager colorsManager = EditorColorsManager.getInstance();
TextAttributes attributes = colorsManager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
if (occurrences.length > 1) {
for (PsiElement occurrence : occurrences) {
final RangeMarker rangeMarker = occurrence.getUserData(ElementToWorkOn.TEXT_RANGE);
if (rangeMarker != null && rangeMarker.isValid()) {
highlightManager.addRangeHighlight(editor, rangeMarker.getStartOffset(), rangeMarker.getEndOffset(), attributes, true, highlighters);
} else {
final TextRange textRange = occurrence.getTextRange();
highlightManager.addRangeHighlight(editor, textRange.getStartOffset(), textRange.getEndOffset(), attributes, true, highlighters);
}
}
}
return highlighters;
}
use of com.intellij.openapi.editor.colors.EditorColorsManager in project intellij-community by JetBrains.
the class DocumentationComponent method applyFontSize.
private void applyFontSize() {
Document document = myEditorPane.getDocument();
if (!(document instanceof StyledDocument)) {
return;
}
final StyledDocument styledDocument = (StyledDocument) document;
EditorColorsManager colorsManager = EditorColorsManager.getInstance();
EditorColorsScheme scheme = colorsManager.getGlobalScheme();
StyleConstants.setFontSize(myFontSizeStyle, JBUI.scale(getQuickDocFontSize().getSize()));
if (Registry.is("documentation.component.editor.font")) {
StyleConstants.setFontFamily(myFontSizeStyle, scheme.getEditorFontName());
}
ApplicationManager.getApplication().executeOnPooledThread(() -> styledDocument.setCharacterAttributes(0, styledDocument.getLength(), myFontSizeStyle, false));
}
Aggregations