Search in sources :

Example 1 with DocumentListener

use of com.intellij.openapi.editor.event.DocumentListener in project intellij-community by JetBrains.

the class PyIntroduceDialog method setUpNameComboBox.

private void setUpNameComboBox(Collection<String> possibleNames) {
    final EditorComboBoxEditor comboEditor = new StringComboboxEditor(myProject, PythonFileType.INSTANCE, myNameComboBox);
    myNameComboBox.setEditor(comboEditor);
    myNameComboBox.setRenderer(new EditorComboBoxRenderer(comboEditor));
    myNameComboBox.setEditable(true);
    myNameComboBox.setMaximumRowCount(8);
    myNameComboBox.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            updateControls();
        }
    });
    ((EditorTextField) myNameComboBox.getEditor().getEditorComponent()).addDocumentListener(new DocumentListener() {

        public void beforeDocumentChange(DocumentEvent event) {
        }

        public void documentChanged(DocumentEvent event) {
            updateControls();
        }
    });
    myContentPane.registerKeyboardAction(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
                IdeFocusManager.getGlobalInstance().requestFocus(myNameComboBox, true);
            });
        }
    }, KeyStroke.getKeyStroke(KeyEvent.VK_N, KeyEvent.ALT_MASK), JComponent.WHEN_IN_FOCUSED_WINDOW);
    for (String possibleName : possibleNames) {
        myNameComboBox.addItem(possibleName);
    }
}
Also used : EditorComboBoxEditor(com.intellij.ui.EditorComboBoxEditor) DocumentListener(com.intellij.openapi.editor.event.DocumentListener) StringComboboxEditor(com.intellij.ui.StringComboboxEditor) EditorTextField(com.intellij.ui.EditorTextField) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) EditorComboBoxRenderer(com.intellij.ui.EditorComboBoxRenderer)

Example 2 with DocumentListener

use of com.intellij.openapi.editor.event.DocumentListener in project ideavim by JetBrains.

the class DocumentManager method addListeners.

public void addListeners(@NotNull Document doc) {
    Object marker = doc.getUserData(LISTENER_MARKER);
    if (marker != null) {
        return;
    }
    doc.putUserData(LISTENER_MARKER, "foo");
    for (DocumentListener docListener : docListeners) {
        EventFacade.getInstance().addDocumentListener(doc, docListener);
    }
}
Also used : DocumentListener(com.intellij.openapi.editor.event.DocumentListener)

Example 3 with DocumentListener

use of com.intellij.openapi.editor.event.DocumentListener in project ideavim by JetBrains.

the class DocumentManager method removeListeners.

public void removeListeners(@NotNull Document doc) {
    Object marker = doc.getUserData(LISTENER_MARKER);
    if (marker == null) {
        return;
    }
    doc.putUserData(LISTENER_MARKER, null);
    for (DocumentListener docListener : docListeners) {
        EventFacade.getInstance().removeDocumentListener(doc, docListener);
    }
}
Also used : DocumentListener(com.intellij.openapi.editor.event.DocumentListener)

Example 4 with DocumentListener

use of com.intellij.openapi.editor.event.DocumentListener in project intellij-community by JetBrains.

the class ListenerDiffViewerBase method onInit.

@Override
protected void onInit() {
    super.onInit();
    VirtualFileListener fileListener = createFileListener(myRequest);
    if (fileListener != null)
        VirtualFileManager.getInstance().addVirtualFileListener(fileListener, this);
    DocumentListener documentListener = createDocumentListener();
    List<Document> documents = ContainerUtil.mapNotNull(myRequest.getContents(), (content) -> {
        return content instanceof DocumentContent ? ((DocumentContent) content).getDocument() : null;
    });
    TextDiffViewerUtil.installDocumentListeners(documentListener, documents, this);
}
Also used : DocumentListener(com.intellij.openapi.editor.event.DocumentListener) DocumentContent(com.intellij.diff.contents.DocumentContent) Document(com.intellij.openapi.editor.Document)

Example 5 with DocumentListener

use of com.intellij.openapi.editor.event.DocumentListener in project intellij-community by JetBrains.

the class SmartPsiElementPointersTest method testCreatePointerInBeforeDocumentChange.

public void testCreatePointerInBeforeDocumentChange() {
    final PsiClass aClass = myJavaFacade.findClass("AClass", GlobalSearchScope.allScope(getProject()));
    assertNotNull(aClass);
    Document document = PsiDocumentManager.getInstance(myProject).getDocument(aClass.getContainingFile());
    final SmartPsiElementPointer[] pointer = new SmartPsiElementPointer[1];
    int offset = aClass.getTextOffset();
    DocumentListener listener = new DocumentListener() {

        @Override
        public void beforeDocumentChange(DocumentEvent event) {
            pointer[0] = createPointer(aClass);
        }

        @Override
        public void documentChanged(DocumentEvent event) {
        }
    };
    EditorEventMulticaster multicaster = EditorFactory.getInstance().getEventMulticaster();
    multicaster.addDocumentListener(listener);
    try {
        insertString(document, offset, "/******/");
    } finally {
        multicaster.removeDocumentListener(listener);
    }
    pointer[0].getElement();
    insertString(document, 0, "/**/");
    PsiDocumentManager.getInstance(myProject).commitAllDocuments();
    PsiElement element = pointer[0].getElement();
    assertNotNull(element);
    assertTrue(element instanceof PsiClass);
    assertTrue(element.isValid());
}
Also used : DocumentListener(com.intellij.openapi.editor.event.DocumentListener) EditorEventMulticaster(com.intellij.openapi.editor.event.EditorEventMulticaster) Document(com.intellij.openapi.editor.Document) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent)

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