private void setupAutoStartDocumentListener(boolean enabled) { final EditorEventMulticaster editorEventMulticaster = EditorFactory.getInstance().getEventMulticaster(); if (autoStartDocumentListener != null) { editorEventMulticaster.removeDocumentListener(autoStartDocumentListener); autoStartDocumentListener = null; } if (enabled) { editorEventMulticaster.addDocumentListener(autoStartDocumentListener = new DocumentListener() { @Override public void documentChanged(DocumentEvent e) { if (running) return; //getSelectedTextEditor() must be run from event dispatch thread EventQueue.invokeLater(() -> { final Editor selectedTextEditor = FileEditorManager.getInstance(project).getSelectedTextEditor(); if (selectedTextEditor == null) return; if(e.getDocument().equals(selectedTextEditor.getDocument())) { setRunning(true); } }); } }); } }
@Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { final EditorTextField editorTextField = new EditorTextField((String) value, myProject, StdFileTypes.JAVA) { @Override protected boolean shouldHaveBorder() { return false; } }; myDocument = editorTextField.getDocument(); if (myDocument != null) { for (DocumentListener listener : myListeners) { editorTextField.addDocumentListener(listener); } } return editorTextField; }
@Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { myCodeFragment = (PsiCodeFragment)value; myDocument = PsiDocumentManager.getInstance(myProject).getDocument(myCodeFragment); myEditorTextField = createEditorField(myDocument); if (myEditorTextField != null) { for (DocumentListener listener : myListeners) { myEditorTextField.addDocumentListener(listener); } myEditorTextField.setDocument(myDocument); myEditorTextField.setBorder(new LineBorder(table.getSelectionBackground())); } return myEditorTextField; }
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { myCodeFragment = (PsiCodeFragment)((Pair)value).getFirst(); myDocument = PsiDocumentManager.getInstance(myProject).getDocument(myCodeFragment); JPanel panel = new JPanel(); myEditorTextField = createEditorField(myDocument); if (myEditorTextField != null) { for (DocumentListener listener : myListeners) { myEditorTextField.addDocumentListener(listener); } myEditorTextField.setDocument(myDocument); myEditorTextField.setBorder(new LineBorder(table.getSelectionBackground())); } panel.add(myEditorTextField); panel.add(new JCheckBox()); return panel; }
@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); } }
private void changedUpdate(@NotNull DocumentEvent event, long newModificationStamp) { try { getLineSet().changedUpdate(event); setModificationStamp(newModificationStamp); if (!ShutDownTracker.isShutdownHookRunning()) { DocumentListener[] listeners = getCachedListeners(); for (DocumentListener listener : listeners) { try { listener.documentChanged(event); } catch (Throwable e) { log(e); } } } } finally { myEventsHandling = false; } }
private void changedUpdate(DocumentEvent event, long newModificationStamp) { try { if (LOG.isDebugEnabled()) LOG.debug(event.toString()); myLineSet.changedUpdate(event); setModificationStamp(newModificationStamp); if (!ShutDownTracker.isShutdownHookRunning()) { DocumentListener[] listeners = getCachedListeners(); for (DocumentListener listener : listeners) { try { listener.documentChanged(event); } catch (Throwable e) { LOG.error(e); } } } } finally { myEventsHandling = false; } }
@Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { final EditorTextField editorTextField = new EditorTextField((String) value, myProject, InternalStdFileTypes.JAVA) { @Override protected boolean shouldHaveBorder() { return false; } }; myDocument = editorTextField.getDocument(); if (myDocument != null) { for (DocumentListener listener : myListeners) { editorTextField.addDocumentListener(listener); } } return editorTextField; }
@Override public void execute(@NotNull final Editor editor, char cha, @NotNull DataContext dataContext) { if (!listenedDocuments.contains(editor.getDocument()) && isThisCorrectProject()) { DocumentListener docl = new TextInputListener(); editor.getDocument().addDocumentListener(docl); listenedDocuments.add(editor.getDocument()); logger.info("Added document listener to ", editor.getDocument().toString()); UsagesCollector.doPersistProjectUsages(new ObjectFinder().findCurrentProject()); } handler.execute(editor, cha, dataContext); }
private void fireMoveText(int start, int end, int newBase) { for (DocumentListener listener : getCachedListeners()) { if (listener instanceof PrioritizedInternalDocumentListener) { ((PrioritizedInternalDocumentListener)listener).moveTextHappened(start, end, newBase); } } }
private void doBeforeChangedUpdate(DocumentEvent event) { Application app = ApplicationManager.getApplication(); if (app != null) { FileDocumentManager manager = FileDocumentManager.getInstance(); VirtualFile file = manager.getFile(this); if (file != null && !file.isValid()) { LOG.error("File of this document has been deleted."); } } assertInsideCommand(); getLineSet(); // initialize line set to track changed lines if (!ShutDownTracker.isShutdownHookRunning()) { DocumentListener[] listeners = getCachedListeners(); for (int i = listeners.length - 1; i >= 0; i--) { try { listeners[i].beforeDocumentChange(event); } catch (Throwable e) { LOG.error(e); } } } myEventsHandling = true; }
private void changedUpdate(@NotNull DocumentEvent event, long newModificationStamp, ImmutableText prevText) { try { if (LOG.isDebugEnabled()) LOG.debug(event.toString()); myLineSet = getLineSet().update(prevText, event.getOffset(), event.getOffset() + event.getOldLength(), event.getNewFragment(), event.isWholeTextReplaced()); myFrozen = null; if (myTabTrackingRequestors > 0) { updateMightContainTabs(event.getNewFragment()); } setModificationStamp(newModificationStamp); if (!ShutDownTracker.isShutdownHookRunning()) { DocumentListener[] listeners = getCachedListeners(); for (DocumentListener listener : listeners) { try { listener.documentChanged(event); } catch (Throwable e) { LOG.error(e); } } } } finally { myEventsHandling = false; } }
@Override public void addDocumentListener(@NotNull DocumentListener listener) { myCachedDocumentListeners.set(null); if (myDocumentListeners.contains(listener)) { LOG.error("Already registered: " + listener); } boolean added = myDocumentListeners.add(listener); LOG.assertTrue(added, listener); }
private DocumentListenerDisposable(@NotNull DocumentListener listener, @NotNull Ref<DocumentListener[]> cachedDocumentListenersRef, @NotNull List<DocumentListener> documentListeners) { myListener = listener; myCachedDocumentListenersRef = cachedDocumentListenersRef; myDocumentListeners = documentListeners; }
private static void doRemoveDocumentListener(@NotNull DocumentListener listener, @NotNull Ref<DocumentListener[]> cachedDocumentListenersRef, @NotNull List<DocumentListener> documentListeners) { cachedDocumentListenersRef.set(null); boolean success = documentListeners.remove(listener); if (!success) { LOG.error("Can't remove document listener (" + listener + "). Registered listeners: " + documentListeners); } }
@NotNull private DocumentListener[] getCachedListeners() { DocumentListener[] cachedListeners = myCachedDocumentListeners.get(); if (cachedListeners == null) { DocumentListener[] listeners = ArrayUtil.stripTrailingNulls(myDocumentListeners.toArray(new DocumentListener[myDocumentListeners.size()])); Arrays.sort(listeners, PrioritizedDocumentListener.COMPARATOR); cachedListeners = listeners; myCachedDocumentListeners.set(cachedListeners); } return cachedListeners; }
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(new Runnable() { @Override public void run() { 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); } }
/** Invalidate tree upon doc change */ public void registerStructureViewModel(final Editor editor, final STGroupStructureViewModel model) { final Document doc = editor.getDocument(); final DocumentListener listener = new DocumentAdapter() { @Override public void documentChanged(DocumentEvent e) { model.invalidate(); } }; DocumentListener oldListener = doc.getUserData(EDITOR_STRUCTVIEW_LISTENER_KEY); if ( oldListener!=null ) { doc.removeDocumentListener(oldListener); } doc.putUserData(EDITOR_STRUCTVIEW_LISTENER_KEY, listener); doc.addDocumentListener(listener); }
@NotNull private DocumentEvent doBeforeChangedUpdate(int offset, CharSequence oldString, CharSequence newString, boolean wholeTextReplaced) { Application app = ApplicationManager.getApplication(); if (app != null) { FileDocumentManager manager = FileDocumentManager.getInstance(); if (manager != null) { VirtualFile file = manager.getFile(this); if (file != null && !file.isValid()) log("File of this document has been deleted."); } } getLineSet(); // initialize line set to track changed lines DocumentEvent event = new DocumentEventImpl(this, offset, oldString, newString, myModificationStamp, wholeTextReplaced); if (!ShutDownTracker.isShutdownHookRunning()) { DocumentListener[] listeners = getCachedListeners(); for (int i = listeners.length - 1; i >= 0; i--) { try { listeners[i].beforeDocumentChange(event); } catch (Throwable e) { log(e); } } } myEventsHandling = true; return event; }
@Override public void addDocumentListener(@NotNull DocumentListener listener) { myCachedDocumentListeners.set(null); if (myDocumentListeners.contains(listener)) { log("Already registered: " + listener); } boolean added = myDocumentListeners.add(listener); assert added : listener; }
public DocumentListenerDisposable(@NotNull DocumentListener listener, @NotNull Ref<DocumentListener[]> cachedDocumentListenersRef, @NotNull List<DocumentListener> documentListeners) { myListener = listener; myCachedDocumentListenersRef = cachedDocumentListenersRef; myDocumentListeners = documentListeners; }
private static void doRemoveDocumentListener(@NotNull DocumentListener listener, @NotNull Ref<DocumentListener[]> cachedDocumentListenersRef, @NotNull List<DocumentListener> documentListeners) { cachedDocumentListenersRef.set(null); boolean success = documentListeners.remove(listener); if (!success) { log("Can't remove document listener (" + listener + "). Registered listeners: " + documentListeners); } }
@NotNull private DocumentListener[] getCachedListeners() { DocumentListener[] cachedListeners = myCachedDocumentListeners.get(); if (cachedListeners == null) { DocumentListener[] listeners = myDocumentListeners.toArray(new DocumentListener[myDocumentListeners.size()]); Arrays.sort(listeners, PrioritizedDocumentListener.COMPARATOR); cachedListeners = listeners; myCachedDocumentListeners.set(cachedListeners); } return cachedListeners; }
@Override public void beforeDocumentChange(DocumentEvent event) { if (myBulkUpdateInProgress) { return; } myUpdateInProgress = true; if (!isSoftWrappingEnabled()) { myDirty = true; return; } for (DocumentListener listener : myDocumentListeners) { listener.beforeDocumentChange(event); } }
@Override public void documentChanged(DocumentEvent event) { if (myBulkUpdateInProgress) { return; } myUpdateInProgress = false; if (!isSoftWrappingEnabled()) { return; } for (DocumentListener listener : myDocumentListeners) { listener.documentChanged(event); } }
@NotNull private DocumentEvent doBeforeChangedUpdate(int offset, CharSequence oldString, CharSequence newString, boolean wholeTextReplaced) { FileDocumentManager manager = FileDocumentManager.getInstance(); if (manager != null) { VirtualFile file = manager.getFile(this); if (file != null && !file.isValid()) { LOG.error("File of this document has been deleted."); } } DocumentEvent event = new DocumentEventImpl(this, offset, oldString, newString, myModificationStamp, wholeTextReplaced); if (!ShutDownTracker.isShutdownHookRunning()) { DocumentListener[] listeners = getCachedListeners(); for (int i = listeners.length - 1; i >= 0; i--) { try { listeners[i].beforeDocumentChange(event); } catch (Throwable e) { LOG.error(e); } } } myEventsHandling = true; return event; }
@Override public void addDocumentListener(@NotNull DocumentListener listener) { if (myCachedDocumentListeners != null) { myCachedDocumentListeners.set(null); } LOG.assertTrue(!myDocumentListeners.contains(listener), "Already registered: " + listener); boolean added = myDocumentListeners.add(listener); LOG.assertTrue(added, listener); }
private static void doRemoveDocumentListener(DocumentListener listener, Ref<DocumentListener[]> cachedDocumentListenersRef, List<DocumentListener> documentListeners) { if (cachedDocumentListenersRef != null) { cachedDocumentListenersRef.set(null); } boolean success = documentListeners.remove(listener); if (!success) { LOG.error("Can't remove document listener (" + listener + "). Registered cachedDocumentListenersRef: " + documentListeners); } }
@Override public void addDocumentListener(javax.swing.event.DocumentListener documentListener) { if (myListeners == null) { myListeners = new ArrayList<>(2); } myListeners.add(documentListener); }
private void fireMoveText(int start, int end, int newBase) { for (DocumentListener listener : getListeners()) { if (listener instanceof PrioritizedInternalDocumentListener) { ((PrioritizedInternalDocumentListener)listener).moveTextHappened(start, end, newBase); } } }
private void beforeChangedUpdate(DocumentEvent event) { Application app = ApplicationManager.getApplication(); if (app != null) { FileDocumentManager manager = FileDocumentManager.getInstance(); VirtualFile file = manager.getFile(this); if (file != null && !file.isValid()) { LOG.error("File of this document has been deleted: "+file); } } assertInsideCommand(); getLineSet(); // initialize line set to track changed lines if (!ShutDownTracker.isShutdownHookRunning()) { DocumentListener[] listeners = getListeners(); for (int i = listeners.length - 1; i >= 0; i--) { try { listeners[i].beforeDocumentChange(event); } catch (Throwable e) { LOG.error(e); } } } myEventsHandling = true; }
@Override public void addDocumentListener(@Nonnull DocumentListener listener) { if (ArrayUtil.contains(listener, getListeners())) { LOG.error("Already registered: " + listener); } myDocumentListeners.add(listener); }
@Override public void removeDocumentListener(@Nonnull DocumentListener listener) { boolean success = myDocumentListeners.remove(listener); if (!success) { LOG.error("Can't remove document listener (" + listener + "). Registered listeners: " + Arrays.toString(getListeners())); } }