use of com.intellij.openapi.editor.event.DocumentListener in project intellij-community by JetBrains.
the class ReferenceEditorWithBrowseButton method setText.
@Override
public void setText(@NotNull String text) {
Document oldDocument = getEditorTextField().getDocument();
String oldText = oldDocument.getText();
for (DocumentListener listener : myDocumentListeners) {
oldDocument.removeDocumentListener(listener);
}
Document document = myFactory.fun(text);
getEditorTextField().setDocument(document);
for (DocumentListener listener : myDocumentListeners) {
document.addDocumentListener(listener);
listener.documentChanged(new DocumentEventImpl(document, 0, oldText, text, -1, false));
}
}
use of com.intellij.openapi.editor.event.DocumentListener in project intellij-community by JetBrains.
the class FileDocumentManagerImplTest method testDocumentUnsavedInsideChangeListener.
public void testDocumentUnsavedInsideChangeListener() throws IOException {
VirtualFile file = createFile("a.txt", "a");
FileDocumentManager manager = FileDocumentManager.getInstance();
Document document = manager.getDocument(file);
assertFalse(manager.isDocumentUnsaved(document));
AtomicInteger invoked = new AtomicInteger();
AtomicBoolean expectUnsaved = new AtomicBoolean(true);
DocumentListener listener = new DocumentListener() {
@Override
public void beforeDocumentChange(DocumentEvent e) {
assertFalse(manager.isDocumentUnsaved(document));
}
@Override
public void documentChanged(DocumentEvent event) {
invoked.incrementAndGet();
assertEquals(expectUnsaved.get(), manager.isDocumentUnsaved(document));
}
};
document.addDocumentListener(listener, getTestRootDisposable());
EditorFactory.getInstance().getEventMulticaster().addDocumentListener(listener, getTestRootDisposable());
WriteCommandAction.runWriteCommandAction(myProject, () -> document.insertString(0, "b"));
assertTrue(manager.isDocumentUnsaved(document));
assertEquals(2, invoked.get());
expectUnsaved.set(false);
FileDocumentManager.getInstance().saveAllDocuments();
FileUtil.writeToFile(VfsUtilCore.virtualToIoFile(file), "something");
file.refresh(false, false);
assertEquals("something", document.getText());
assertFalse(manager.isDocumentUnsaved(document));
assertEquals(4, invoked.get());
}
use of com.intellij.openapi.editor.event.DocumentListener in project intellij-plugins by JetBrains.
the class DartAnalysisServerService method registerDocumentListener.
private void registerDocumentListener() {
final DocumentListener documentListener = new DocumentListener() {
@Override
public void beforeDocumentChange(DocumentEvent e) {
if (myServer == null)
return;
myServerData.onDocumentChanged(e);
final VirtualFile file = FileDocumentManager.getInstance().getFile(e.getDocument());
if (isLocalAnalyzableFile(file)) {
for (VirtualFile fileInEditor : FileEditorManager.getInstance(myProject).getOpenFiles()) {
if (fileInEditor.equals(file)) {
synchronized (myLock) {
myChangedDocuments.add(e.getDocument());
}
break;
}
}
}
myUpdateFilesAlarm.cancelAllRequests();
myUpdateFilesAlarm.addRequest(DartAnalysisServerService.this::updateFilesContent, UPDATE_FILES_TIMEOUT);
}
};
EditorFactory.getInstance().getEventMulticaster().addDocumentListener(documentListener, myProject);
}
use of com.intellij.openapi.editor.event.DocumentListener in project intellij-community by JetBrains.
the class CodeFragmentTableCellEditorBase method getTableCellEditorComponent.
@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;
}
use of com.intellij.openapi.editor.event.DocumentListener in project intellij-community by JetBrains.
the class StringTableCellEditor method getTableCellEditorComponent.
@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;
}
Aggregations