use of com.intellij.openapi.editor.event.DocumentAdapter in project intellij-community by JetBrains.
the class XmlSyncTagCommunityTest method testDoNotFireDocumentChangeEventIfTagWasNotChanged.
public void testDoNotFireDocumentChangeEventIfTagWasNotChanged() {
myFixture.configureByText(XmlFileType.INSTANCE, "<di<caret>></di>");
type("v");
Ref<Boolean> eventSent = Ref.create(false);
myFixture.getEditor().getDocument().addDocumentListener(new DocumentAdapter() {
@Override
public void documentChanged(DocumentEvent e) {
eventSent.set(true);
}
}, myFixture.getTestRootDisposable());
myFixture.testAction(new MoveCaretLeftAction());
assertFalse(eventSent.get());
}
use of com.intellij.openapi.editor.event.DocumentAdapter in project intellij-community by JetBrains.
the class MvcRunTargetDialog method createUIComponents.
private void createUIComponents() {
myTargetField = new ComboBox(MvcRunTargetHistoryService.getInstance().getHistory());
myTargetField.setLightWeightPopupEnabled(false);
EditorComboBoxEditor editor = new StringComboboxEditor(myModule.getProject(), PlainTextFileType.INSTANCE, myTargetField);
myTargetField.setRenderer(new EditorComboBoxRenderer(editor));
myTargetField.setEditable(true);
myTargetField.setEditor(editor);
EditorTextField editorTextField = editor.getEditorComponent();
myFakePanel = new JPanel(new BorderLayout());
myFakePanel.add(myTargetField, BorderLayout.CENTER);
TextFieldCompletionProvider vmOptionCompletionProvider = new TextFieldCompletionProviderDumbAware() {
@NotNull
@Override
protected String getPrefix(@NotNull String currentTextPrefix) {
return MvcRunTargetDialog.getPrefix(currentTextPrefix);
}
@Override
protected void addCompletionVariants(@NotNull String text, int offset, @NotNull String prefix, @NotNull CompletionResultSet result) {
if (prefix.endsWith("-D")) {
result.addAllElements(MvcTargetDialogCompletionUtils.getSystemPropertiesVariants());
}
}
};
myVmOptionsField = vmOptionCompletionProvider.createEditor(myModule.getProject());
new TextFieldCompletionProviderDumbAware() {
@NotNull
@Override
protected String getPrefix(@NotNull String currentTextPrefix) {
return MvcRunTargetDialog.getPrefix(currentTextPrefix);
}
@Override
protected void addCompletionVariants(@NotNull String text, int offset, @NotNull String prefix, @NotNull CompletionResultSet result) {
for (LookupElement variant : MvcTargetDialogCompletionUtils.collectVariants(myModule, text, offset, prefix)) {
result.addElement(variant);
}
}
}.apply(editorTextField);
editorTextField.getDocument().addDocumentListener(new DocumentAdapter() {
@Override
public void documentChanged(DocumentEvent e) {
setOKActionEnabled(!StringUtil.isEmptyOrSpaces(e.getDocument().getText()));
}
});
setOKActionEnabled(false);
}
use of com.intellij.openapi.editor.event.DocumentAdapter in project intellij-community by JetBrains.
the class GroovyCreateClassDialog method createCenterPanel.
@Override
@Nullable
protected JComponent createCenterPanel() {
myPackageTextField.getDocument().addDocumentListener(new DocumentAdapter() {
@Override
public void documentChanged(DocumentEvent e) {
PsiNameHelper nameHelper = PsiNameHelper.getInstance(myProject);
String packageName = getPackageName();
getOKAction().setEnabled(nameHelper.isQualifiedName(packageName) || packageName != null && packageName.isEmpty());
}
});
new AnAction() {
@Override
public void actionPerformed(AnActionEvent e) {
myPackageChooseButton.doClick();
}
}.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.SHIFT_DOWN_MASK)), myPackageTextField);
return myContentPane;
}
use of com.intellij.openapi.editor.event.DocumentAdapter in project intellij-community by JetBrains.
the class GrIntroduceConstantDialog method initializeTargetClassEditor.
private void initializeTargetClassEditor() {
myTargetClassEditor = new ReferenceEditorComboWithBrowseButton(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
TreeClassChooser chooser = TreeClassChooserFactory.getInstance(myContext.getProject()).createWithInnerClassesScopeChooser(RefactoringBundle.message("choose.destination.class"), GlobalSearchScope.projectScope(myContext.getProject()), new ClassFilter() {
@Override
public boolean isAccepted(PsiClass aClass) {
return aClass.getParent() instanceof GroovyFile || aClass.hasModifierProperty(PsiModifier.STATIC);
}
}, null);
if (myTargetClass != null) {
chooser.selectDirectory(myTargetClass.getContainingFile().getContainingDirectory());
}
chooser.showDialog();
PsiClass aClass = chooser.getSelected();
if (aClass != null) {
myTargetClassEditor.setText(aClass.getQualifiedName());
}
}
}, "", myContext.getProject(), true, RECENTS_KEY);
myTargetClassPanel.setLayout(new BorderLayout());
myTargetClassPanel.add(myTargetClassLabel, BorderLayout.NORTH);
myTargetClassPanel.add(myTargetClassEditor, BorderLayout.CENTER);
Set<String> possibleClassNames = new LinkedHashSet<>();
for (final PsiElement occurrence : myContext.getOccurrences()) {
final PsiClass parentClass = getParentClass(occurrence);
if (parentClass != null && parentClass.getQualifiedName() != null) {
possibleClassNames.add(parentClass.getQualifiedName());
}
}
for (String possibleClassName : possibleClassNames) {
myTargetClassEditor.prependItem(possibleClassName);
}
if (myDefaultTargetClass != null) {
myTargetClassEditor.prependItem(myDefaultTargetClass.getQualifiedName());
}
myTargetClassEditor.getChildComponent().addDocumentListener(new DocumentAdapter() {
@Override
public void documentChanged(DocumentEvent e) {
targetClassChanged();
updateOkStatus();
// enableEnumDependant(introduceEnumConstant());
}
});
}
use of com.intellij.openapi.editor.event.DocumentAdapter in project intellij-community by JetBrains.
the class MavenProjectsManagerWatcher method start.
public synchronized void start() {
final MessageBusConnection myBusConnection = myProject.getMessageBus().connect(myChangedDocumentsQueue);
myBusConnection.subscribe(VirtualFileManager.VFS_CHANGES, new MyFileChangeListener());
myBusConnection.subscribe(ProjectTopics.PROJECT_ROOTS, new MyRootChangesListener());
myChangedDocumentsQueue.makeUserAware(myProject);
myChangedDocumentsQueue.activate();
myBusConnection.subscribe(ProjectTopics.MODULES, new ModuleListener() {
@Override
public void moduleRemoved(@NotNull Project project, @NotNull Module module) {
MavenProject mavenProject = myManager.findProject(module);
if (mavenProject != null && !myManager.isIgnored(mavenProject)) {
VirtualFile file = mavenProject.getFile();
if (myManager.isManagedFile(file) && myManager.getModules(mavenProject).isEmpty()) {
myManager.removeManagedFiles(Collections.singletonList(file));
} else {
myManager.setIgnoredState(Collections.singletonList(mavenProject), true);
}
}
}
@Override
public void moduleAdded(@NotNull final Project project, @NotNull final Module module) {
// this method is needed to return non-ignored status for modules that were deleted (and thus ignored) and then created again with a different module type
if (myManager.isMavenizedModule(module)) {
MavenProject mavenProject = myManager.findProject(module);
if (mavenProject != null)
myManager.setIgnoredState(Collections.singletonList(mavenProject), false);
}
}
});
DocumentAdapter myDocumentListener = new DocumentAdapter() {
@Override
public void documentChanged(DocumentEvent event) {
Document doc = event.getDocument();
VirtualFile file = FileDocumentManager.getInstance().getFile(doc);
if (file == null)
return;
String fileName = file.getName();
boolean isMavenFile = fileName.equals(MavenConstants.POM_XML) || fileName.equals(MavenConstants.PROFILES_XML) || isSettingsFile(file) || fileName.startsWith("pom.");
if (!isMavenFile)
return;
synchronized (myChangedDocuments) {
myChangedDocuments.add(doc);
}
myChangedDocumentsQueue.queue(new Update(MavenProjectsManagerWatcher.this) {
@Override
public void run() {
final Document[] copy;
synchronized (myChangedDocuments) {
copy = myChangedDocuments.toArray(new Document[myChangedDocuments.size()]);
myChangedDocuments.clear();
}
MavenUtil.invokeLater(myProject, () -> new WriteAction() {
@Override
protected void run(@NotNull Result result) throws Throwable {
for (Document each : copy) {
PsiDocumentManager.getInstance(myProject).commitDocument(each);
((FileDocumentManagerImpl) FileDocumentManager.getInstance()).saveDocument(each, false);
}
}
}.execute());
}
});
}
};
EditorFactory.getInstance().getEventMulticaster().addDocumentListener(myDocumentListener, myBusConnection);
final MavenGeneralSettings.Listener mySettingsPathsChangesListener = new MavenGeneralSettings.Listener() {
@Override
public void changed() {
updateSettingsFilePointers();
onSettingsChange();
}
};
myGeneralSettings.addListener(mySettingsPathsChangesListener);
Disposer.register(myChangedDocumentsQueue, new Disposable() {
@Override
public void dispose() {
myGeneralSettings.removeListener(mySettingsPathsChangesListener);
mySettingsFilesPointers.clear();
}
});
updateSettingsFilePointers();
}
Aggregations