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); } }
@Override public void propertyChanged(@NotNull VirtualFilePropertyEvent event) { if (VirtualFile.PROP_NAME.equals(event.getPropertyName())) { FileEditorManager fileEditorManager = FileEditorManager.getInstance(myProject); VirtualFile file = event.getFile(); if (fileEditorManager.isFileOpen(file)) { reinitBreadcrumbsComponent(fileEditorManager, file); } } }
public void dispose() { final EditorFactory editorFactory = EditorFactory.getInstance(); editorFactory.releaseEditor(myConsoleEditor); editorFactory.releaseEditor(myHistoryViewer); final FileEditorManager editorManager = FileEditorManager.getInstance(getProject()); final boolean isOpen = editorManager.isFileOpen(myVirtualFile); if (isOpen) { editorManager.closeFile(myVirtualFile); } }
private void installEditorFactoryListener() { final FileEditorManagerAdapter fileEditorListener = new FileEditorManagerAdapter() { @Override public void fileOpened(FileEditorManager source, VirtualFile file) { if (!Comparing.equal(file, myVirtualFile) || myConsoleEditor == null) return; Editor selectedTextEditor = source.getSelectedTextEditor(); for (FileEditor fileEditor : source.getAllEditors(file)) { if (!(fileEditor instanceof TextEditor)) continue; final EditorEx editor = (EditorEx) ((TextEditor) fileEditor).getEditor(); editor.addFocusListener(myFocusListener); if (selectedTextEditor == editor) { // already focused myCurrentEditor = editor; } EmptyAction.registerActionShortcuts( editor.getComponent(), myConsoleEditor.getComponent()); editor .getCaretModel() .addCaretListener( new CaretListener() { public void caretPositionChanged(CaretEvent e) { queueUiUpdate(false); } }); } queueUiUpdate(false); } @Override public void fileClosed(FileEditorManager source, VirtualFile file) { if (!Comparing.equal(file, myVirtualFile)) return; if (myUiUpdateRunnable != null && !Boolean.TRUE.equals( file.getUserData(FileEditorManagerImpl.CLOSING_TO_REOPEN))) { if (myCurrentEditor != null && myCurrentEditor.isDisposed()) myCurrentEditor = null; ApplicationManager.getApplication().runReadAction(myUiUpdateRunnable); } } }; myProject .getMessageBus() .connect(this) .subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, fileEditorListener); FileEditorManager editorManager = FileEditorManager.getInstance(getProject()); if (editorManager.isFileOpen(myVirtualFile)) { fileEditorListener.fileOpened(editorManager, myVirtualFile); } }
private static boolean activatePsiElementIfOpen( @NotNull PsiElement elt, boolean searchForOpen, boolean requestFocus) { if (!elt.isValid()) return false; elt = elt.getNavigationElement(); final PsiFile file = elt.getContainingFile(); if (file == null || !file.isValid()) return false; VirtualFile vFile = file.getVirtualFile(); if (vFile == null) return false; if (!EditorHistoryManager.getInstance(elt.getProject()).hasBeenOpen(vFile)) return false; final FileEditorManager fem = FileEditorManager.getInstance(elt.getProject()); if (!fem.isFileOpen(vFile)) { fem.openFile(vFile, requestFocus, searchForOpen); } final TextRange range = elt.getTextRange(); if (range == null) return false; final FileEditor[] editors = fem.getEditors(vFile); for (FileEditor editor : editors) { if (editor instanceof TextEditor) { final Editor text = ((TextEditor) editor).getEditor(); final int offset = text.getCaretModel().getOffset(); if (range.containsOffset(offset)) { // select the file fem.openFile(vFile, requestFocus, searchForOpen); return true; } } } return false; }