use of com.intellij.openapi.editor.colors.EditorColorsManager in project intellij-community by JetBrains.
the class HighlightUsagesHandler method highlightReferences.
public static void highlightReferences(@NotNull Project project, @NotNull PsiElement element, @NotNull List<PsiReference> refs, Editor editor, PsiFile file, boolean clearHighlights) {
HighlightManager highlightManager = HighlightManager.getInstance(project);
EditorColorsManager manager = EditorColorsManager.getInstance();
TextAttributes attributes = manager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
TextAttributes writeAttributes = manager.getGlobalScheme().getAttributes(EditorColors.WRITE_SEARCH_RESULT_ATTRIBUTES);
setupFindModel(project);
ReadWriteAccessDetector detector = ReadWriteAccessDetector.findDetector(element);
if (detector != null) {
List<PsiReference> readRefs = new ArrayList<>();
List<PsiReference> writeRefs = new ArrayList<>();
for (PsiReference ref : refs) {
if (detector.getReferenceAccess(element, ref) == ReadWriteAccessDetector.Access.Read) {
readRefs.add(ref);
} else {
writeRefs.add(ref);
}
}
doHighlightRefs(highlightManager, editor, readRefs, attributes, clearHighlights);
doHighlightRefs(highlightManager, editor, writeRefs, writeAttributes, clearHighlights);
} else {
doHighlightRefs(highlightManager, editor, refs, attributes, clearHighlights);
}
TextRange range = getNameIdentifierRange(file, element);
if (range != null) {
TextAttributes nameAttributes = attributes;
if (detector != null && detector.isDeclarationWriteAccess(element)) {
nameAttributes = writeAttributes;
}
highlightRanges(highlightManager, editor, nameAttributes, clearHighlights, Arrays.asList(range));
}
}
use of com.intellij.openapi.editor.colors.EditorColorsManager in project intellij-community by JetBrains.
the class CopyReferenceAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
DataContext dataContext = e.getDataContext();
Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
Project project = CommonDataKeys.PROJECT.getData(dataContext);
List<PsiElement> elements = getElementsToCopy(editor, dataContext);
if (!doCopy(elements, project, editor) && editor != null && project != null) {
Document document = editor.getDocument();
PsiFile file = PsiDocumentManager.getInstance(project).getCachedPsiFile(document);
if (file != null) {
String toCopy = getFileFqn(file) + ":" + (editor.getCaretModel().getLogicalPosition().line + 1);
CopyPasteManager.getInstance().setContents(new StringSelection(toCopy));
setStatusBarText(project, toCopy + " has been copied");
}
return;
}
HighlightManager highlightManager = HighlightManager.getInstance(project);
EditorColorsManager manager = EditorColorsManager.getInstance();
TextAttributes attributes = manager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
if (elements.size() == 1 && editor != null && project != null) {
PsiElement element = elements.get(0);
PsiElement nameIdentifier = IdentifierUtil.getNameIdentifier(element);
if (nameIdentifier != null) {
highlightManager.addOccurrenceHighlights(editor, new PsiElement[] { nameIdentifier }, attributes, true, null);
} else {
PsiReference reference = TargetElementUtil.findReference(editor, editor.getCaretModel().getOffset());
if (reference != null) {
highlightManager.addOccurrenceHighlights(editor, new PsiReference[] { reference }, attributes, true, null);
} else if (element != PsiDocumentManager.getInstance(project).getCachedPsiFile(editor.getDocument())) {
highlightManager.addOccurrenceHighlights(editor, new PsiElement[] { element }, attributes, true, null);
}
}
}
}
use of com.intellij.openapi.editor.colors.EditorColorsManager in project intellij-community by JetBrains.
the class PythonHighlightingTest method testDeclarations.
public void testDeclarations() {
EditorColorsManager manager = EditorColorsManager.getInstance();
EditorColorsScheme scheme = (EditorColorsScheme) manager.getGlobalScheme().clone();
manager.addColorsScheme(scheme);
EditorColorsManager.getInstance().setGlobalScheme(scheme);
TextAttributesKey xKey = TextAttributesKey.find("PY.CLASS_DEFINITION");
TextAttributes xAttributes = new TextAttributes(Color.blue, Color.black, Color.white, EffectType.BOXED, Font.BOLD);
scheme.setAttributes(xKey, xAttributes);
xKey = TextAttributesKey.find("PY.FUNC_DEFINITION");
xAttributes = new TextAttributes(Color.red, Color.black, Color.white, EffectType.BOXED, Font.BOLD);
scheme.setAttributes(xKey, xAttributes);
xKey = TextAttributesKey.find("PY.PREDEFINED_DEFINITION");
xAttributes = new TextAttributes(Color.green, Color.black, Color.white, EffectType.BOXED, Font.BOLD);
scheme.setAttributes(xKey, xAttributes);
doTest();
}
Aggregations