private void showEditorWarningMessage(final String message) { ApplicationManager.getApplication() .invokeLater( () -> { if (myEditor == null) return; final FileEditorManager fileEditorManager = FileEditorManager.getInstance(myProject); final VirtualFile vFile = myFile.getVirtualFile(); assert vFile != null; Map<FileEditor, EditorNotificationPanel> map = myFile.getCopyableUserData(NOTIFICATION_PANELS); if (map == null) { map = new HashMap<FileEditor, EditorNotificationPanel>(); myFile.putCopyableUserData(NOTIFICATION_PANELS, map); } final FileEditor[] editors = fileEditorManager.getAllEditors(vFile); for (final FileEditor editor : editors) { if (isCurrentEditor(editor)) { final EditorNotificationPanel panel = new EditorNotificationPanel() { { myLabel.setIcon(AllIcons.General.ExclMark); myLabel.setText(message); } }; panel.createActionLabel( "Close", () -> fileEditorManager.removeTopComponent(editor, panel)); map.put(editor, panel); fileEditorManager.addTopComponent(editor, panel); break; } } }); }
public void hideCoverageData() { if (myEditor == null) return; final FileEditorManager fileEditorManager = FileEditorManager.getInstance(myProject); final List<RangeHighlighter> highlighters = myEditor.getUserData(COVERAGE_HIGHLIGHTERS); if (highlighters != null) { for (final RangeHighlighter highlighter : highlighters) { ApplicationManager.getApplication().invokeLater(() -> highlighter.dispose()); } myEditor.putUserData(COVERAGE_HIGHLIGHTERS, null); } final Map<FileEditor, EditorNotificationPanel> map = myFile.getCopyableUserData(NOTIFICATION_PANELS); if (map != null) { final VirtualFile vFile = myFile.getVirtualFile(); LOG.assertTrue(vFile != null); boolean freeAll = !fileEditorManager.isFileOpen(vFile); myFile.putCopyableUserData(NOTIFICATION_PANELS, null); for (FileEditor fileEditor : map.keySet()) { if (!freeAll && !isCurrentEditor(fileEditor)) { continue; } fileEditorManager.removeTopComponent(fileEditor, map.get(fileEditor)); } } final DocumentListener documentListener = myEditor.getUserData(COVERAGE_DOCUMENT_LISTENER); if (documentListener != null) { myDocument.removeDocumentListener(documentListener); myEditor.putUserData(COVERAGE_DOCUMENT_LISTENER, null); } }
@NotNull public RangeHighlighter[] getHighlighters(@NotNull Editor editor) { Map<RangeHighlighter, HighlightInfo> highlightersMap = getHighlightInfoMap(editor, false); if (highlightersMap == null) return RangeHighlighter.EMPTY_ARRAY; Set<RangeHighlighter> set = new HashSet<RangeHighlighter>(); for (Map.Entry<RangeHighlighter, HighlightInfo> entry : highlightersMap.entrySet()) { HighlightInfo info = entry.getValue(); if (info.editor.equals(editor)) set.add(entry.getKey()); } return set.toArray(new RangeHighlighter[set.size()]); }
@Override public boolean removeSegmentHighlighter( @NotNull Editor editor, @NotNull RangeHighlighter highlighter) { Map<RangeHighlighter, HighlightInfo> map = getHighlightInfoMap(editor, false); if (map == null) return false; HighlightInfo info = map.get(highlighter); if (info == null) return false; MarkupModel markupModel = info.editor.getMarkupModel(); if (((MarkupModelEx) markupModel).containsHighlighter(highlighter)) { highlighter.dispose(); } map.remove(highlighter); return true; }
public boolean hideHighlights(@NotNull Editor editor, @HideFlags int mask) { Map<RangeHighlighter, HighlightInfo> map = getHighlightInfoMap(editor, false); if (map == null) return false; boolean done = false; ArrayList<RangeHighlighter> highlightersToRemove = new ArrayList<RangeHighlighter>(); for (RangeHighlighter highlighter : map.keySet()) { HighlightInfo info = map.get(highlighter); if (!info.editor.equals(editor)) continue; if ((info.flags & mask) != 0) { highlightersToRemove.add(highlighter); done = true; } } for (RangeHighlighter highlighter : highlightersToRemove) { removeSegmentHighlighter(editor, highlighter); } return done; }
private RangeHighlighter addSegmentHighlighter( @NotNull Editor editor, int startOffset, int endOffset, TextAttributes attributes, @HideFlags int flags) { RangeHighlighter highlighter = editor .getMarkupModel() .addRangeHighlighter( startOffset, endOffset, HighlighterLayer.SELECTION - 1, attributes, HighlighterTargetArea.EXACT_RANGE); HighlightInfo info = new HighlightInfo( editor instanceof EditorWindow ? ((EditorWindow) editor).getDelegate() : editor, flags); Map<RangeHighlighter, HighlightInfo> map = getHighlightInfoMap(editor, true); map.put(highlighter, info); return highlighter; }