Java Code Examples for com.intellij.codeInsight.highlighting.HighlightManager#getInstance()
The following examples show how to use
com.intellij.codeInsight.highlighting.HighlightManager#getInstance() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FlowInPlaceRenamer.java From mule-intellij-plugins with Apache License 2.0 | 6 votes |
private static void addHighlights(List<TextRange> ranges, Editor editor, ArrayList<RangeHighlighter> highlighters) { EditorColorsManager colorsManager = EditorColorsManager.getInstance(); TextAttributes attributes = colorsManager.getGlobalScheme().getAttributes(EditorColors.WRITE_SEARCH_RESULT_ATTRIBUTES); HighlightManager highlightManager = HighlightManager.getInstance(editor.getProject()); Iterator iterator = ranges.iterator(); while (iterator.hasNext()) { TextRange range = (TextRange) iterator.next(); //highlightManager.addOccurrenceHighlight(editor, range.getStartOffset() + 1, range.getEndOffset() - 1, attributes, 0, highlighters, (Color) null); highlightManager.addRangeHighlight(editor, range.getStartOffset() + 1, range.getEndOffset() - 1, attributes, false, highlighters); } iterator = highlighters.iterator(); while (iterator.hasNext()) { RangeHighlighter highlighter = (RangeHighlighter) iterator.next(); highlighter.setGreedyToLeft(true); highlighter.setGreedyToRight(true); } }
Example 2
Source File: HighlightingUtil.java From needsmoredojo with Apache License 2.0 | 6 votes |
public static void highlightElement(Editor editor, @NotNull com.intellij.openapi.project.Project project, @NotNull PsiElement[] elements) { final HighlightManager highlightManager = HighlightManager.getInstance(project); final EditorColorsManager editorColorsManager = EditorColorsManager.getInstance(); final EditorColorsScheme globalScheme = editorColorsManager.getGlobalScheme(); final TextAttributes textattributes = globalScheme.getAttributes( EditorColors.TEXT_SEARCH_RESULT_ATTRIBUTES); highlightManager.addOccurrenceHighlights( editor, elements, textattributes, true, null); final WindowManager windowManager = WindowManager.getInstance(); final StatusBar statusBar = windowManager.getStatusBar(project); statusBar.setInfo("Press Esc to remove highlighting"); }
Example 3
Source File: InplaceRefactoring.java From consulo with Apache License 2.0 | 6 votes |
public void finish(boolean success) { if (!ourRenamersStack.isEmpty() && ourRenamersStack.peek() == this) { ourRenamersStack.pop(); } if (myHighlighters != null) { if (!myProject.isDisposed()) { final HighlightManager highlightManager = HighlightManager.getInstance(myProject); for (RangeHighlighter highlighter : myHighlighters) { highlightManager.removeSegmentHighlighter(myEditor, highlighter); } } myHighlighters = null; myEditor.putUserData(INPLACE_RENAMER, null); } if (myBalloon != null) { if (!isRestart()) { myBalloon.hide(); } } }
Example 4
Source File: FlowInPlaceRenamer.java From mule-intellij-plugins with Apache License 2.0 | 5 votes |
private void finish() { ourRenamersStack.pop(); if (this.myHighlighters != null) { Project project = this.myEditor.getProject(); if (project != null && !project.isDisposed()) { HighlightManager highlightManager = HighlightManager.getInstance(project); Iterator var3 = this.myHighlighters.iterator(); while (var3.hasNext()) { RangeHighlighter highlighter = (RangeHighlighter) var3.next(); highlightManager.removeSegmentHighlighter(this.myEditor, highlighter); } } } }
Example 5
Source File: HippieWordCompletionHandler.java From consulo with Apache License 2.0 | 5 votes |
private static void highlightWord(final CompletionVariant variant, final Project project, CompletionData data) { int delta = data.startOffset < variant.offset ? variant.variant.length() - data.myWordUnderCursor.length() : 0; HighlightManager highlightManager = HighlightManager.getInstance(project); EditorColorsManager colorManager = EditorColorsManager.getInstance(); TextAttributes attributes = colorManager.getGlobalScheme().getAttributes(EditorColors.TEXT_SEARCH_RESULT_ATTRIBUTES); highlightManager.addOccurrenceHighlight(variant.editor, variant.offset + delta, variant.offset + variant.variant.length() + delta, attributes, HighlightManager.HIDE_BY_ANY_KEY, null, null); }
Example 6
Source File: BreadcrumbsWrapper.java From consulo with Apache License 2.0 | 5 votes |
private void itemHovered(Crumb crumb, @SuppressWarnings("unused") InputEvent event) { if (!Registry.is("editor.breadcrumbs.highlight.on.hover")) { return; } HighlightManager hm = HighlightManager.getInstance(myProject); if (myHighlighed != null) { for (RangeHighlighter highlighter : myHighlighed) { hm.removeSegmentHighlighter(myEditor, highlighter); } myHighlighed = null; } if (crumb instanceof NavigatableCrumb) { final TextRange range = ((NavigatableCrumb)crumb).getHighlightRange(); if (range == null) return; final TextAttributes attributes = new TextAttributes(); final CrumbPresentation p = PsiCrumb.getPresentation(crumb); Color color = p == null ? null : p.getBackgroundColor(false, false, false); if (color == null) color = BreadcrumbsComponent.ButtonSettings.getBackgroundColor(false, false, false, false); if (color == null) color = UIUtil.getLabelBackground(); final Color background = EditorColorsManager.getInstance().getGlobalScheme().getColor(EditorColors.CARET_ROW_COLOR); attributes.setBackgroundColor(makeTransparent(color, background != null ? background : Gray._200, 0.3)); myHighlighed = new ArrayList<>(1); int flags = HighlightManager.HIDE_BY_ESCAPE | HighlightManager.HIDE_BY_TEXT_CHANGE | HighlightManager.HIDE_BY_ANY_KEY; hm.addOccurrenceHighlight(myEditor, range.getStartOffset(), range.getEndOffset(), attributes, flags, myHighlighed, null); } }
Example 7
Source File: CopyReferenceAction.java From consulo with Apache License 2.0 | 5 votes |
@RequiredUIAccess @Override public void actionPerformed(@Nonnull AnActionEvent e) { DataContext dataContext = e.getDataContext(); Editor editor = dataContext.getData(CommonDataKeys.EDITOR); Project project = dataContext.getData(CommonDataKeys.PROJECT); 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); } } } }
Example 8
Source File: CallerChooserBase.java From consulo with Apache License 2.0 | 5 votes |
private void updateEditorTexts(final MethodNodeBase<M> node) { final MethodNodeBase<M> parentNode = (MethodNodeBase)node.getParent(); final String callerText = node != myRoot ? getText(node.getMethod()) : ""; final Document callerDocument = myCallerEditor.getDocument(); final String calleeText = node != myRoot ? getText(parentNode.getMethod()) : ""; final Document calleeDocument = myCalleeEditor.getDocument(); ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { callerDocument.setText(callerText); calleeDocument.setText(calleeText); } }); final M caller = node.getMethod(); final PsiElement callee = parentNode != null ? parentNode.getElementToSearch() : null; if (caller != null && caller.isPhysical() && callee != null) { HighlightManager highlighter = HighlightManager.getInstance(myProject); EditorColorsManager colorManager = EditorColorsManager.getInstance(); TextAttributes attributes = colorManager.getGlobalScheme().getAttributes(EditorColors.TEXT_SEARCH_RESULT_ATTRIBUTES); int start = getStartOffset(caller); for (PsiElement element : findElementsToHighlight(caller, callee)) { highlighter.addRangeHighlight(myCallerEditor, element.getTextRange().getStartOffset() - start, element.getTextRange().getEndOffset() - start, attributes, false, null); } } }
Example 9
Source File: InplaceChangeSignature.java From consulo with Apache License 2.0 | 5 votes |
public InplaceChangeSignature(Project project, Editor editor, @Nonnull PsiElement element) { myDocumentManager = PsiDocumentManager.getInstance(project); myProject = project; try { myMarkAction = StartMarkAction.start(editor, project, ChangeSignatureHandler.REFACTORING_NAME); } catch (StartMarkAction.AlreadyStartedException e) { final int exitCode = Messages.showYesNoDialog(myProject, e.getMessage(), ChangeSignatureHandler.REFACTORING_NAME, "Navigate to Started", "Cancel", Messages.getErrorIcon()); if (exitCode == Messages.CANCEL) return; PsiElement method = myStableChange.getMethod(); VirtualFile virtualFile = PsiUtilCore.getVirtualFile(method); new OpenFileDescriptor(project, virtualFile, method.getTextOffset()).navigate(true); return; } myEditor = editor; myDetector = LanguageChangeSignatureDetectors.INSTANCE.forLanguage(element.getLanguage()); myStableChange = myDetector.createInitialChangeInfo(element); myInitialSignature = myDetector.extractSignature(myStableChange); myInitialName = DescriptiveNameUtil.getDescriptiveName(myStableChange.getMethod()); TextRange highlightingRange = myDetector.getHighlightingRange(myStableChange); HighlightManager highlightManager = HighlightManager.getInstance(myProject); TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(EditorColors.LIVE_TEMPLATE_ATTRIBUTES); highlightManager.addRangeHighlight(editor, highlightingRange.getStartOffset(), highlightingRange.getEndOffset(), attributes, false, myHighlighters); for (RangeHighlighter highlighter : myHighlighters) { highlighter.setGreedyToRight(true); highlighter.setGreedyToLeft(true); } myEditor.getDocument().addDocumentListener(this); myEditor.putUserData(INPLACE_CHANGE_SIGNATURE, this); myPreview = InplaceRefactoring.createPreviewComponent(project, myDetector.getFileType()); showBalloon(); }
Example 10
Source File: InplaceChangeSignature.java From consulo with Apache License 2.0 | 5 votes |
public void detach() { myEditor.getDocument().removeDocumentListener(this); HighlightManager highlightManager = HighlightManager.getInstance(myProject); for (RangeHighlighter highlighter : myHighlighters) { highlightManager.removeSegmentHighlighter(myEditor, highlighter); } myHighlighters.clear(); myBalloon.hide(); myDetector = null; FinishMarkAction.finish(myProject, myEditor, myMarkAction); myEditor.putUserData(INPLACE_CHANGE_SIGNATURE, null); }
Example 11
Source File: ExtractMethodHelper.java From consulo with Apache License 2.0 | 5 votes |
private static void highlightInEditor(@Nonnull final Project project, @Nonnull final SimpleMatch match, @Nonnull final Editor editor, Map<SimpleMatch, RangeHighlighter> highlighterMap) { final List<RangeHighlighter> highlighters = new ArrayList<>(); final HighlightManager highlightManager = HighlightManager.getInstance(project); final EditorColorsManager colorsManager = EditorColorsManager.getInstance(); final TextAttributes attributes = colorsManager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES); final int startOffset = match.getStartElement().getTextRange().getStartOffset(); final int endOffset = match.getEndElement().getTextRange().getEndOffset(); highlightManager.addRangeHighlight(editor, startOffset, endOffset, attributes, true, highlighters); highlighterMap.put(match, highlighters.get(0)); final LogicalPosition logicalPosition = editor.offsetToLogicalPosition(startOffset); editor.getScrollingModel().scrollTo(logicalPosition, ScrollType.MAKE_VISIBLE); }
Example 12
Source File: ExtractIncludeFileBase.java From consulo with Apache License 2.0 | 5 votes |
private static void highlightInEditor(final Project project, final IncludeDuplicate pair, final Editor editor) { final HighlightManager highlightManager = HighlightManager.getInstance(project); EditorColorsManager colorsManager = EditorColorsManager.getInstance(); TextAttributes attributes = colorsManager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES); final int startOffset = pair.getStart().getTextRange().getStartOffset(); final int endOffset = pair.getEnd().getTextRange().getEndOffset(); highlightManager.addRangeHighlight(editor, startOffset, endOffset, attributes, true, null); final LogicalPosition logicalPosition = editor.offsetToLogicalPosition(startOffset); editor.getScrollingModel().scrollTo(logicalPosition, ScrollType.MAKE_VISIBLE); }
Example 13
Source File: JSGraphQLQueryContextHighlightVisitor.java From js-graphql-intellij-plugin with MIT License | 4 votes |
private static void removeHighlights(Editor editor, Project project) { HighlightManagerImpl highlightManager = (HighlightManagerImpl) HighlightManager.getInstance(project); for (RangeHighlighter rangeHighlighter : highlightManager.getHighlighters(editor)) { highlightManager.removeSegmentHighlighter(editor, rangeHighlighter); } }
Example 14
Source File: ExtractMethodHelper.java From consulo with Apache License 2.0 | 4 votes |
/** * Notifies user about found duplicates and then highlights each of them in the editor and asks user how to proceed. * * @param callElement generated expression or statement that contains invocation of the new method * @param editor instance of editor where refactoring is performed * @param replacer strategy of substituting each duplicate occurence with the replacement fragment * @param duplicates discovered duplicates of extracted code fragment * @see #collectDuplicates(SimpleDuplicatesFinder, List, PsiElement) */ public static void replaceDuplicates(@Nonnull PsiElement callElement, @Nonnull Editor editor, @Nonnull Consumer<Pair<SimpleMatch, PsiElement>> replacer, @Nonnull List<SimpleMatch> duplicates) { if (!duplicates.isEmpty()) { final String message = RefactoringBundle .message("0.has.detected.1.code.fragments.in.this.file.that.can.be.replaced.with.a.call.to.extracted.method", ApplicationNamesInfo.getInstance().getProductName(), duplicates.size()); final boolean isUnittest = ApplicationManager.getApplication().isUnitTestMode(); final Project project = callElement.getProject(); final int exitCode = !isUnittest ? Messages.showYesNoDialog(project, message, RefactoringBundle.message("refactoring.extract.method.dialog.title"), Messages.getInformationIcon()) : Messages.YES; if (exitCode == Messages.YES) { boolean replaceAll = false; final Map<SimpleMatch, RangeHighlighter> highlighterMap = new HashMap<>(); for (SimpleMatch match : duplicates) { if (!match.getStartElement().isValid() || !match.getEndElement().isValid()) continue; final Pair<SimpleMatch, PsiElement> replacement = Pair.create(match, callElement); if (!replaceAll) { highlightInEditor(project, match, editor, highlighterMap); int promptResult = FindManager.PromptResult.ALL; //noinspection ConstantConditions if (!isUnittest) { ReplacePromptDialog promptDialog = new ReplacePromptDialog(false, RefactoringBundle.message("replace.fragment"), project); promptDialog.show(); promptResult = promptDialog.getExitCode(); } if (promptResult == FindManager.PromptResult.SKIP) { final HighlightManager highlightManager = HighlightManager.getInstance(project); final RangeHighlighter highlighter = highlighterMap.get(match); if (highlighter != null) highlightManager.removeSegmentHighlighter(editor, highlighter); continue; } if (promptResult == FindManager.PromptResult.CANCEL) break; if (promptResult == FindManager.PromptResult.OK) { replaceDuplicate(project, replacer, replacement); } else if (promptResult == FindManager.PromptResult.ALL) { replaceDuplicate(project, replacer, replacement); replaceAll = true; } } else { replaceDuplicate(project, replacer, replacement); } } } } }