private void editorCreated(@NotNull EditorFactoryEvent event) { final Editor editor = event.getEditor(); LineSelectionManager manager = new LineSelectionManager(editor); myLineSelectionManagers.put(editor, manager); myDelayedRunner.addRunnable(editor, () -> { myLineSelectionManagers.remove(editor); Disposer.dispose(manager); }); if (editor.getProject() != null) { PluginProjectComponent projectComponent = editor.getProject().getComponent(PluginProjectComponent.class); if (projectComponent != null) { projectComponent.editorCreated(editor); myDelayedRunner.addRunnable(editor, () -> { projectComponent.editorReleased(editor); }); } } if (mySettings.isOverrideStandardPaste()) { registerPasteOverrides(editor); myDelayedRunner.addRunnable(editor, () -> unRegisterPasteOverrides(editor)); } }
@Override public void releaseEditor(@NotNull Editor editor) { try { myEditorFactoryEventDispatcher.getMulticaster().editorReleased(new EditorFactoryEvent(this, editor)); } finally { try { ((EditorImpl)editor).release(); } finally { myEditors.remove(editor); if (LOG.isDebugEnabled()) { LOG.debug("number of Editor's:" + myEditors.size()); } } } }
public TemplateManagerImpl(Project project) { myProject = project; final EditorFactoryListener myEditorFactoryListener = new EditorFactoryAdapter() { @Override public void editorReleased(@NotNull EditorFactoryEvent event) { Editor editor = event.getEditor(); if (editor.getProject() != null && editor.getProject() != myProject) return; if (myProject.isDisposed() || !myProject.isOpen()) return; TemplateState state = getTemplateState(editor); if (state != null) { state.gotoEnd(); } clearTemplateState(editor); } }; EditorFactory.getInstance().addEditorFactoryListener(myEditorFactoryListener, myProject); }
@Override public void editorReleased(@NotNull EditorFactoryEvent event) { final EditorEx editor = (EditorEx)event.getEditor(); final Document document = editor.getDocument(); VirtualFile file = myDocumentManager.getFile(document); if (file == null) { file = editor.getVirtualFile(); } if (file != null && file.isValid()) { for (FileEditor fileEditor : myFileEditorManager.getAllEditors(file)) { if (fileEditor instanceof TextEditor && ((TextEditor)fileEditor).getEditor() != editor) { return; } } } removeDocListener(document, file); }
public void editorReleased(@NotNull EditorFactoryEvent event) { final Editor editor = event.getEditor(); if (editor.getProject() != myProject) return; try { final SrcFileAnnotator fileAnnotator; synchronized (ANNOTATORS_LOCK) { fileAnnotator = myAnnotators.remove(editor); } if (fileAnnotator != null) { Disposer.dispose(fileAnnotator); } } finally { final Runnable request = myCurrentEditors.remove(editor); if (request != null) { myAlarm.cancelRequest(request); } } }
@Override public void editorCreated(@NotNull EditorFactoryEvent event) { Editor editor = event.getEditor(); if (!openedEditors.contains(editor)) { reflectivelyCheckCurrentListeners("editorCreated.before", editor); openedEditors.add(editor); editor.getScrollingModel().addVisibleAreaListener(this); logger.info("editorCreated: createdCount=" + editorCreatedCount.incrementAndGet() + " listening for editor=" + shortObjectString(editor) + " openedEditors=" + listShortObjects(openedEditors)); reflectivelyCheckCurrentListeners("editorCreated.after", editor); } else { logger.warn("editorCreated: createdCount=" + editorCreatedCount.incrementAndGet() + " (should not happen) already contains editor=" + shortObjectString(editor)); } }
@Override public void editorReleased(@NotNull EditorFactoryEvent event) { Editor editor = event.getEditor(); if (openedEditors.contains(editor)) { logger.info("editorReleased: releasedCount=" + editorReleasedCount.incrementAndGet() + " removed listener for editor=" + shortObjectString(editor) + " openedEditors=" + listShortObjects(openedEditors)); reflectivelyCheckCurrentListeners("editorReleased.before", editor); editor.getScrollingModel().removeVisibleAreaListener(this); openedEditors.remove(editor); reflectivelyCheckCurrentListeners("editorReleased.after", editor); } else { logger.warn("editorReleased: releasedCount=" + editorReleasedCount.incrementAndGet() + " (should not happen) released editor we were not tracking editor=" + shortObjectString(editor)); } }
@Override public void editorReleased(@NotNull EditorFactoryEvent event) { Editor editor = event.getEditor(); final Document doc = editor.getDocument(); if (editor.getProject() != null && editor.getProject() != project) { return; } STGroupFileEditorListener listener = editor.getUserData(EDITOR_DOCUMENT_LISTENER_KEY); if (listener != null) { doc.removeDocumentListener(listener); doc.putUserData(EDITOR_DOCUMENT_LISTENER_KEY, null); } DocumentListener listener2 = editor.getUserData(EDITOR_STRUCTVIEW_LISTENER_KEY); if (listener2 != null) { doc.removeDocumentListener(listener2); doc.putUserData(EDITOR_STRUCTVIEW_LISTENER_KEY, null); } }
public void editorCreated(@NotNull EditorFactoryEvent event) { // note that in case of lazy loading of configurables, this event can happen // outside of EDT, so the EDT check mustn't be done here Editor editor = event.getEditor(); if (editor.getProject() != null && editor.getProject() != myProject) return; final Document document = editor.getDocument(); final VirtualFile virtualFile = FileDocumentManager.getInstance().getFile(document); new AbstractCalledLater(myProject, ModalityState.NON_MODAL) { @Override public void run() { if (shouldBeInstalled(virtualFile)) { installTracker(virtualFile, document); } } }.callMe(); }
@Override public void projectOpened() { final EditorFactoryListener myEditorFactoryListener = new EditorFactoryAdapter() { @Override public void editorReleased(@NotNull EditorFactoryEvent event) { Editor editor = event.getEditor(); if (editor.getProject() != null && editor.getProject() != myProject) return; if (myProject.isDisposed() || !myProject.isOpen()) return; TemplateState tState = getTemplateState(editor); if (tState != null) { tState.gotoEnd(); } editor.putUserData(TEMPLATE_STATE_KEY, null); } }; EditorFactory.getInstance().addEditorFactoryListener(myEditorFactoryListener, myProject); }
public void editorReleased(@Nonnull EditorFactoryEvent event) { final Editor editor = event.getEditor(); if (editor.getProject() != myProject) return; try { final SrcFileAnnotator fileAnnotator; synchronized (ANNOTATORS_LOCK) { fileAnnotator = myAnnotators.remove(editor); } if (fileAnnotator != null) { Disposer.dispose(fileAnnotator); } } finally { final Runnable request = myCurrentEditors.remove(editor); if (request != null) { myAlarm.cancelRequest(request); } } }
public EncodingManagerImpl(@Nonnull EditorFactory editorFactory) { editorFactory.getEventMulticaster().addDocumentListener(new DocumentAdapter() { @Override public void documentChanged(DocumentEvent e) { Document document = e.getDocument(); if (isEditorOpenedFor(document)) { queueUpdateEncodingFromContent(document); } } }, this); editorFactory.addEditorFactoryListener(new EditorFactoryAdapter() { @Override public void editorCreated(@Nonnull EditorFactoryEvent event) { queueUpdateEncodingFromContent(event.getEditor().getDocument()); } }, this); }
public static void disposeWithEditor(@Nonnull Editor editor, @Nonnull Disposable disposable) { ApplicationManager.getApplication().assertIsDispatchThread(); if (Disposer.isDisposed(disposable)) return; if (editor.isDisposed()) { Disposer.dispose(disposable); return; } // for injected editors disposal will happen only when host editor is disposed, // but this seems to be the best we can do (there are no notifications on disposal of injected editor) Editor hostEditor = editor instanceof EditorWindow ? ((EditorWindow)editor).getDelegate() : editor; EditorFactory.getInstance().addEditorFactoryListener(new EditorFactoryAdapter() { @Override public void editorReleased(@Nonnull EditorFactoryEvent event) { if (event.getEditor() == hostEditor) { Disposer.dispose(disposable); } } }, disposable); }
@Override public void releaseEditor(@Nonnull Editor editor) { try { myEditorFactoryEventDispatcher.getMulticaster().editorReleased(new EditorFactoryEvent(this, editor)); } finally { try { ((EditorImpl)editor).release(); } finally { myEditors.remove(editor); if (LOG.isDebugEnabled()) { LOG.debug("number of Editors after release: " + myEditors.size()); } } } }
public TemplateManagerImpl(Project project) { myProject = project; final EditorFactoryListener myEditorFactoryListener = new EditorFactoryAdapter() { @Override public void editorReleased(@Nonnull EditorFactoryEvent event) { Editor editor = event.getEditor(); if (editor.getProject() != null && editor.getProject() != myProject) return; if (myProject.isDisposed() || !myProject.isOpen()) return; TemplateState state = getTemplateState(editor); if (state != null) { state.gotoEnd(); } clearTemplateState(editor); } }; EditorFactory.getInstance().addEditorFactoryListener(myEditorFactoryListener, myProject); }
@Override public void editorCreated(@NotNull final EditorFactoryEvent event) { final Editor editor = event.getEditor(); final Project project = editor.getProject(); if (project == null) { return; } final Document document = editor.getDocument(); final VirtualFile openedFile = FileDocumentManager.getInstance().getFile(document); if (openedFile != null) { final TaskFile taskFile = StudyUtils.getTaskFile(project, openedFile); if (taskFile != null) { WolfTheProblemSolver.getInstance(project).clearProblems(openedFile); final ToolWindow studyToolWindow = ToolWindowManager.getInstance(project).getToolWindow(StudyToolWindowFactory.STUDY_TOOL_WINDOW); if (studyToolWindow != null) { StudyUtils.updateToolWindows(project); studyToolWindow.show(null); } Course course = StudyTaskManager.getInstance(project).getCourse(); if (course == null) { return; } StudyEditor.addDocumentListener(document, new EduDocumentListener(taskFile, true)); if (!taskFile.getAnswerPlaceholders().isEmpty()) { StudyNavigator.navigateToFirstAnswerPlaceholder(editor, taskFile); boolean isStudyProject = EduNames.STUDY.equals(course.getCourseMode()); StudyUtils.drawAllAnswerPlaceholders(editor, taskFile); if (isStudyProject) { editor.addEditorMouseListener(new WindowSelectionListener(taskFile)); } } } } }
@Override public void editorReleased(@NotNull EditorFactoryEvent event) { final Editor editor = event.getEditor(); final Document document = editor.getDocument(); StudyEditor.removeListener(document); editor.getMarkupModel().removeAllHighlighters(); editor.getSelectionModel().removeSelection(); }
public EncodingManagerImpl(@NotNull EditorFactory editorFactory) { editorFactory.getEventMulticaster().addDocumentListener(new DocumentAdapter() { @Override public void documentChanged(DocumentEvent e) { queueUpdateEncodingFromContent(e.getDocument()); } }, this); editorFactory.addEditorFactoryListener(new EditorFactoryAdapter() { @Override public void editorCreated(@NotNull EditorFactoryEvent event) { queueUpdateEncodingFromContent(event.getEditor().getDocument()); } }, this); }
private Editor createEditor(@NotNull Document document, boolean isViewer, Project project) { Document hostDocument = document instanceof DocumentWindow ? ((DocumentWindow)document).getDelegate() : document; EditorImpl editor = new EditorImpl(hostDocument, isViewer, project); myEditors.add(editor); myEditorEventMulticaster.registerEditor(editor); myEditorFactoryEventDispatcher.getMulticaster().editorCreated(new EditorFactoryEvent(this, editor)); if (LOG.isDebugEnabled()) { LOG.debug("number of Editor's:" + myEditors.size()); } return editor; }
@Override public void editorCreated(@NotNull EditorFactoryEvent event) { // note that in case of lazy loading of configurables, this event can happen // outside of EDT, so the EDT check mustn't be done here Editor editor = event.getEditor(); if (editor.getProject() != null && editor.getProject() != myProject) return; final Document document = editor.getDocument(); final VirtualFile virtualFile = FileDocumentManager.getInstance().getFile(document); if (virtualFile == null) return; if (shouldBeInstalled(virtualFile)) { installTracker(virtualFile, document); } }
@Override public void editorReleased(@NotNull EditorFactoryEvent event) { final Editor editor = event.getEditor(); if (editor.getProject() != null && editor.getProject() != myProject) return; final Document doc = editor.getDocument(); final Editor[] editors = event.getFactory().getEditors(doc, myProject); if (editors.length == 0) { releaseTracker(doc); } }
@Override public void editorReleased(@NotNull EditorFactoryEvent event) { final Editor editor = event.getEditor(); if (editor.getProject() != null && editor.getProject() != myProject) return; unregisterEditor(editor); executeOnRelease(editor); }
@Override public void editorCreated(@NotNull EditorFactoryEvent event) { Editor editor = event.getEditor(); Project project = editor.getProject(); if (project == null) { return; } VirtualFile virtualFile = FileDocumentManager.getInstance().getFile(editor.getDocument()); if (virtualFile == null) { return; } final CCProjectService service = CCProjectService.getInstance(project); Course course = service.getCourse(); if (course == null) { return; } final VirtualFile taskDir = virtualFile.getParent(); if (taskDir == null || !taskDir.getName().contains(EduNames.TASK)) { return; } final VirtualFile lessonDir = taskDir.getParent(); if (lessonDir == null) return; final TaskFile taskFile = service.getTaskFile(virtualFile); if (taskFile == null) { return; } EduDocumentListener listener = new EduDocumentListener(taskFile, true, true); CCProjectService.addDocumentListener(editor.getDocument(), listener); editor.getDocument().addDocumentListener(listener); EditorActionManager.getInstance() .setReadonlyFragmentModificationHandler(editor.getDocument(), new EduAnswerPlaceholderDeleteHandler(editor)); service.drawAnswerPlaceholders(virtualFile, editor); editor.getColorsScheme().setColor(EditorColors.READONLY_FRAGMENT_BACKGROUND_COLOR, null); EduAnswerPlaceholderPainter.createGuardedBlocks(editor, taskFile, false); }
@Override public void editorReleased(@NotNull EditorFactoryEvent event) { Editor editor = event.getEditor(); Document document = editor.getDocument(); EduDocumentListener listener = CCProjectService.getListener(document); if (listener != null) { document.removeDocumentListener(listener); CCProjectService.removeListener(document); } editor.getMarkupModel().removeAllHighlighters(); editor.getSelectionModel().removeSelection(); }
public XmlTagNameSynchronizer(EditorFactory editorFactory, FileDocumentManager manager, CommandProcessor processor) { myFileDocumentManager = manager; editorFactory.addEditorFactoryListener(new EditorFactoryAdapter() { @Override public void editorCreated(@NotNull EditorFactoryEvent event) { installSynchronizer(event.getEditor()); } }, ApplicationManager.getApplication()); processor.addCommandListener(this); }
@Override public void editorCreated(@NotNull EditorFactoryEvent event) { final Editor editor = event.getEditor(); final Document doc = editor.getDocument(); VirtualFile vfile = FileDocumentManager.getInstance().getFile(doc); if ( vfile!=null && vfile.getName().endsWith(".stg") ) { STGroupFileEditorListener listener = new STGroupFileEditorListener(); doc.putUserData(EDITOR_DOCUMENT_LISTENER_KEY, listener); doc.addDocumentListener(listener); } }
@Override public void editorCreated(EditorFactoryEvent editorFactoryEvent) { if(!editorBelongsToThisProject(editorFactoryEvent)) { return; } Editor editor = editorFactoryEvent.getEditor(); focusListener = new EditorFocusListener(editor); editor.getContentComponent().addFocusListener(focusListener); editorListenerMap.put(editor, new EditorListener(editor)); }
@Override public void editorReleased(EditorFactoryEvent editorFactoryEvent) { if(!editorBelongsToThisProject(editorFactoryEvent)) { return; } Editor editor = editorFactoryEvent.getEditor(); editor.getContentComponent().removeFocusListener(focusListener); editorListenerMap.remove(editor).removeListeners(); }
private boolean editorBelongsToThisProject(EditorFactoryEvent editorFactoryEvent) { try { return editorFactoryEvent.getEditor().getProject().getName().equals(myProjectName); } catch(NullPointerException e) { return false; } }
@Override public void releaseEditor(@NotNull Editor editor) { try { ((EditorImpl)editor).release(); } finally { myEditors.remove(editor); myEditorFactoryEventDispatcher.getMulticaster().editorReleased(new EditorFactoryEvent(this, editor)); if (LOG.isDebugEnabled()) { LOG.debug("number of Editor's:" + myEditors.size()); //Thread.dumpStack(); } } }
public void editorReleased(@NotNull EditorFactoryEvent event) { final Editor editor = event.getEditor(); if (editor.getProject() != null && editor.getProject() != myProject) return; final Document doc = editor.getDocument(); final Editor[] editors = event.getFactory().getEditors(doc, myProject); if (editors.length == 0) { new AbstractCalledLater(myProject, ModalityState.NON_MODAL) { @Override public void run() { releaseTracker(doc); } }.callMe(); } }
@Override public void editorReleased(@NotNull EditorFactoryEvent event) { final Editor editor = event.getEditor(); if (editor.getProject() != null && editor.getProject() != myProject) return; unregisterEditor(editor); dispose(editor); }
private Editor createEditor(@Nonnull Document document, boolean isViewer, Project project) { Document hostDocument = document instanceof DocumentWindow ? ((DocumentWindow)document).getDelegate() : document; EditorImpl editor = new EditorImpl(hostDocument, isViewer, project); myEditors.add(editor); myEditorEventMulticaster.registerEditor(editor); myEditorFactoryEventDispatcher.getMulticaster().editorCreated(new EditorFactoryEvent(this, editor)); if (LOG.isDebugEnabled()) { LOG.debug("number of Editors after create: " + myEditors.size()); } return editor; }
@Override public void editorCreated(@Nonnull EditorFactoryEvent event) { // note that in case of lazy loading of configurables, this event can happen // outside of EDT, so the EDT check mustn't be done here Editor editor = event.getEditor(); if (editor.getProject() != null && editor.getProject() != myProject) return; final Document document = editor.getDocument(); final VirtualFile virtualFile = FileDocumentManager.getInstance().getFile(document); if (virtualFile == null) return; if (shouldBeInstalled(virtualFile)) { installTracker(virtualFile, document); } }
@Override public void editorReleased(@Nonnull EditorFactoryEvent event) { final Editor editor = event.getEditor(); if (editor.getProject() != null && editor.getProject() != myProject) return; final Document doc = editor.getDocument(); final Editor[] editors = event.getFactory().getEditors(doc, myProject); if (editors.length == 0 || (editors.length == 1 && editor == editors[0])) { releaseTracker(doc); } }
@Override public void editorReleased(@Nonnull EditorFactoryEvent event) { final Editor editor = event.getEditor(); if (editor.getProject() != null && editor.getProject() != myProject) return; unregisterEditor(editor); executeOnRelease(editor); }