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);
}
}
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);
}
}
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);
}
}
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);
}
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());
}
Aggregations