use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.
the class ExternalAnnotationsManagerImpl method chooseAnnotationsPlace.
@Override
@NotNull
public AnnotationPlace chooseAnnotationsPlace(@NotNull final PsiElement element) {
ApplicationManager.getApplication().assertIsDispatchThread();
//element just created
if (!element.isPhysical())
return AnnotationPlace.IN_CODE;
if (!element.getManager().isInProject(element))
return AnnotationPlace.EXTERNAL;
final Project project = myPsiManager.getProject();
//otherwise external annotations should be read-only
if (CodeStyleSettingsManager.getSettings(project).USE_EXTERNAL_ANNOTATIONS) {
final PsiFile containingFile = element.getContainingFile();
final VirtualFile virtualFile = containingFile.getVirtualFile();
LOG.assertTrue(virtualFile != null);
final List<OrderEntry> entries = ProjectRootManager.getInstance(project).getFileIndex().getOrderEntriesForFile(virtualFile);
if (!entries.isEmpty()) {
for (OrderEntry entry : entries) {
if (!(entry instanceof ModuleOrderEntry)) {
if (AnnotationOrderRootType.getUrls(entry).length > 0) {
return AnnotationPlace.EXTERNAL;
}
break;
}
}
}
final MyExternalPromptDialog dialog = ApplicationManager.getApplication().isUnitTestMode() || ApplicationManager.getApplication().isHeadlessEnvironment() ? null : new MyExternalPromptDialog(project);
if (dialog != null && dialog.isToBeShown()) {
final PsiElement highlightElement = element instanceof PsiNameIdentifierOwner ? ((PsiNameIdentifierOwner) element).getNameIdentifier() : element.getNavigationElement();
LOG.assertTrue(highlightElement != null);
final Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
final List<RangeHighlighter> highlighters = new ArrayList<>();
final boolean highlight = editor != null && editor.getDocument() == PsiDocumentManager.getInstance(project).getDocument(containingFile);
try {
if (highlight) {
//do not highlight for batch inspections
final EditorColorsManager colorsManager = EditorColorsManager.getInstance();
final TextAttributes attributes = colorsManager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
final TextRange textRange = highlightElement.getTextRange();
HighlightManager.getInstance(project).addRangeHighlight(editor, textRange.getStartOffset(), textRange.getEndOffset(), attributes, true, highlighters);
final LogicalPosition logicalPosition = editor.offsetToLogicalPosition(textRange.getStartOffset());
editor.getScrollingModel().scrollTo(logicalPosition, ScrollType.CENTER);
}
dialog.show();
if (dialog.getExitCode() == 2) {
return AnnotationPlace.EXTERNAL;
} else if (dialog.getExitCode() == 1) {
return AnnotationPlace.NOWHERE;
}
} finally {
if (highlight) {
HighlightManager.getInstance(project).removeSegmentHighlighter(editor, highlighters.get(0));
}
}
} else if (dialog != null) {
dialog.close(DialogWrapper.OK_EXIT_CODE);
}
}
return AnnotationPlace.IN_CODE;
}
use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.
the class GrIntroduceHandlerBase method showDialog.
@Nullable
private Settings showDialog(@NotNull GrIntroduceContext context) {
// Add occurrences highlighting
ArrayList<RangeHighlighter> highlighters = new ArrayList<>();
HighlightManager highlightManager = null;
if (context.getEditor() != null) {
highlightManager = HighlightManager.getInstance(context.getProject());
EditorColorsManager colorsManager = EditorColorsManager.getInstance();
TextAttributes attributes = colorsManager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
if (context.getOccurrences().length > 1) {
highlightManager.addOccurrenceHighlights(context.getEditor(), context.getOccurrences(), attributes, true, highlighters);
}
}
GrIntroduceDialog<Settings> dialog = getDialog(context);
dialog.show();
if (dialog.isOK()) {
if (context.getEditor() != null) {
for (RangeHighlighter highlighter : highlighters) {
highlightManager.removeSegmentHighlighter(context.getEditor(), highlighter);
}
}
return dialog.getSettings();
} else {
if (context.getOccurrences().length > 1) {
WindowManager.getInstance().getStatusBar(context.getProject()).setInfo(GroovyRefactoringBundle.message("press.escape.to.remove.the.highlighting"));
}
}
return null;
}
use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.
the class GroovyRefactoringUtil method highlightOccurrencesByRanges.
public static void highlightOccurrencesByRanges(Project project, Editor editor, TextRange[] ranges) {
if (editor == null)
return;
ArrayList<RangeHighlighter> highlighters = new ArrayList<>();
HighlightManager highlightManager = HighlightManager.getInstance(project);
EditorColorsManager colorsManager = EditorColorsManager.getInstance();
TextAttributes attributes = colorsManager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
for (TextRange range : ranges) {
highlightManager.addRangeHighlight(editor, range.getStartOffset(), range.getEndOffset(), attributes, false, highlighters);
}
}
use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.
the class ShowXPathAction method actionPerformed.
public void actionPerformed(AnActionEvent e) {
final Editor editor = CommonDataKeys.EDITOR.getData(e.getDataContext());
if (editor == null) {
return;
}
final Project project = editor.getProject();
if (project == null) {
return;
}
final PsiDocumentManager docmgr = PsiDocumentManager.getInstance(project);
final Document document = editor.getDocument();
docmgr.commitDocument(document);
final PsiFile psiFile = docmgr.getPsiFile(document);
if (!(psiFile instanceof XmlFile)) {
return;
}
final PsiElement element = psiFile.findElementAt(editor.getCaretModel().getOffset());
if (!(element instanceof XmlElement || element instanceof PsiWhiteSpace)) {
XPathAppComponent.showEditorHint("No suitable context for an XPath-expression selected.", editor);
return;
}
final PsiElement node = XPathExpressionGenerator.transformToValidShowPathNode(element);
if (node == null) {
XPathAppComponent.showEditorHint("No suitable context for an XPath-expression selected.", editor);
return;
}
final Config cfg = XPathAppComponent.getInstance().getConfig();
final RangeHighlighter h = HighlighterUtil.highlightNode(editor, node, cfg.getContextAttributes(), cfg);
final String path = XPathSupport.getInstance().getUniquePath((XmlElement) node, null);
final JTextField label = new JTextField(path);
label.setPreferredSize(new Dimension(label.getPreferredSize().width + new JLabel("M").getPreferredSize().width, label.getPreferredSize().height));
label.setOpaque(false);
label.setEditable(false);
label.setBorder(null);
label.setHorizontalAlignment(SwingConstants.CENTER);
label.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
final JPanel p = new NonOpaquePanel(new BorderLayout());
final JLabel l = new JLabel("XPath:");
p.add(l, BorderLayout.WEST);
p.add(label, BorderLayout.CENTER);
InplaceButton copy = new InplaceButton(ActionsBundle.message("action.EditorCopy.text"), PlatformIcons.COPY_ICON, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
CopyPasteManager.getInstance().setContents(new StringSelection(path));
}
});
p.add(copy, BorderLayout.EAST);
final LightweightHint hint = new LightweightHint(p) {
public void hide() {
super.hide();
HighlighterUtil.removeHighlighter(editor, h);
}
};
final Point point = editor.visualPositionToXY(editor.getCaretModel().getVisualPosition());
point.y += editor.getLineHeight() / 2;
HintHint hintHint = new HintHint(editor, point).setAwtTooltip(true).setContentActive(true).setExplicitClose(true).setShowImmediately(true);
HintManagerImpl.getInstanceImpl().showEditorHint(hint, editor, point, HintManager.HIDE_BY_ANY_KEY, 0, false, hintHint);
}
use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.
the class AbstractInplaceIntroducer method addHighlights.
@Override
protected void addHighlights(@NotNull Map<TextRange, TextAttributes> ranges, @NotNull Editor editor, @NotNull Collection<RangeHighlighter> highlighters, @NotNull HighlightManager highlightManager) {
final TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
final V variable = getVariable();
if (variable != null) {
final String name = variable.getName();
LOG.assertTrue(name != null, variable);
final int variableNameLength = name.length();
if (isReplaceAllOccurrences()) {
for (RangeMarker marker : getOccurrenceMarkers()) {
final int startOffset = marker.getStartOffset();
highlightManager.addOccurrenceHighlight(editor, startOffset, startOffset + variableNameLength, attributes, 0, highlighters, null);
}
} else if (getExpr() != null) {
final int startOffset = getExprMarker().getStartOffset();
highlightManager.addOccurrenceHighlight(editor, startOffset, startOffset + variableNameLength, attributes, 0, highlighters, null);
}
}
for (RangeHighlighter highlighter : highlighters) {
highlighter.setGreedyToLeft(true);
highlighter.setGreedyToRight(true);
}
}
Aggregations