Search in sources :

Example 6 with DocumentListener

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));
    }
}
Also used : DocumentListener(com.intellij.openapi.editor.event.DocumentListener) DocumentEventImpl(com.intellij.openapi.editor.impl.event.DocumentEventImpl) Document(com.intellij.openapi.editor.Document)

Example 7 with DocumentListener

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());
}
Also used : LightVirtualFile(com.intellij.testFramework.LightVirtualFile) MockVirtualFile(com.intellij.mock.MockVirtualFile) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DocumentListener(com.intellij.openapi.editor.event.DocumentListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) Document(com.intellij.openapi.editor.Document) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent)

Example 8 with DocumentListener

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);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DocumentListener(com.intellij.openapi.editor.event.DocumentListener) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent)

Example 9 with DocumentListener

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;
}
Also used : DocumentListener(com.intellij.openapi.editor.event.DocumentListener) LineBorder(javax.swing.border.LineBorder)

Example 10 with DocumentListener

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;
}
Also used : DocumentListener(com.intellij.openapi.editor.event.DocumentListener) EditorTextField(com.intellij.ui.EditorTextField)

Aggregations

DocumentListener (com.intellij.openapi.editor.event.DocumentListener)22 DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)13 Document (com.intellij.openapi.editor.Document)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 Editor (com.intellij.openapi.editor.Editor)3 EditorTextField (com.intellij.ui.EditorTextField)3 FileDocumentManager (com.intellij.openapi.fileEditor.FileDocumentManager)2 FileEditor (com.intellij.openapi.fileEditor.FileEditor)2 TextEditor (com.intellij.openapi.fileEditor.TextEditor)2 PsiFile (com.intellij.psi.PsiFile)2 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)2 EditorComboBoxEditor (com.intellij.ui.EditorComboBoxEditor)2 EditorComboBoxRenderer (com.intellij.ui.EditorComboBoxRenderer)2 StringComboboxEditor (com.intellij.ui.StringComboboxEditor)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 Log (com.android.ddmlib.Log)1 CompletionParameters (com.intellij.codeInsight.completion.CompletionParameters)1 DocumentContent (com.intellij.diff.contents.DocumentContent)1 Language (com.intellij.lang.Language)1