Search in sources :

Example 1 with DocumentAdapter

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());
}
Also used : MoveCaretLeftAction(com.intellij.openapi.editor.actions.MoveCaretLeftAction) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent)

Example 2 with DocumentAdapter

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);
}
Also used : EditorComboBoxEditor(com.intellij.ui.EditorComboBoxEditor) StringComboboxEditor(com.intellij.ui.StringComboboxEditor) ComboBox(com.intellij.openapi.ui.ComboBox) ModulesComboBox(com.intellij.application.options.ModulesComboBox) CompletionResultSet(com.intellij.codeInsight.completion.CompletionResultSet) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) LookupElement(com.intellij.codeInsight.lookup.LookupElement) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) NotNull(org.jetbrains.annotations.NotNull) TextFieldCompletionProviderDumbAware(com.intellij.util.TextFieldCompletionProviderDumbAware) EditorTextField(com.intellij.ui.EditorTextField) TextFieldCompletionProvider(com.intellij.util.TextFieldCompletionProvider) EditorComboBoxRenderer(com.intellij.ui.EditorComboBoxRenderer)

Example 3 with DocumentAdapter

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;
}
Also used : PsiNameHelper(com.intellij.psi.PsiNameHelper) CustomShortcutSet(com.intellij.openapi.actionSystem.CustomShortcutSet) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with DocumentAdapter

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());
        }
    });
}
Also used : ActionEvent(java.awt.event.ActionEvent) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) ReferenceEditorComboWithBrowseButton(com.intellij.ui.ReferenceEditorComboWithBrowseButton) ActionListener(java.awt.event.ActionListener) GroovyFile(org.jetbrains.plugins.groovy.lang.psi.GroovyFile)

Example 5 with DocumentAdapter

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();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Disposable(com.intellij.openapi.Disposable) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) ModuleListener(com.intellij.openapi.project.ModuleListener) ModuleRootListener(com.intellij.openapi.roots.ModuleRootListener) VirtualFilePointerListener(com.intellij.openapi.vfs.pointers.VirtualFilePointerListener) ModuleListener(com.intellij.openapi.project.ModuleListener) WriteAction(com.intellij.openapi.application.WriteAction) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) Document(com.intellij.openapi.editor.Document) Update(com.intellij.util.ui.update.Update) Result(com.intellij.openapi.application.Result) Project(com.intellij.openapi.project.Project) Module(com.intellij.openapi.module.Module)

Aggregations

DocumentAdapter (com.intellij.openapi.editor.event.DocumentAdapter)41 DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)40 Document (com.intellij.openapi.editor.Document)10 EditorTextField (com.intellij.ui.EditorTextField)6 ActionEvent (java.awt.event.ActionEvent)6 ActionListener (java.awt.event.ActionListener)6 Disposable (com.intellij.openapi.Disposable)4 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 ReferenceEditorComboWithBrowseButton (com.intellij.ui.ReferenceEditorComboWithBrowseButton)4 NotNull (org.jetbrains.annotations.NotNull)4 AnAction (com.intellij.openapi.actionSystem.AnAction)3 Editor (com.intellij.openapi.editor.Editor)3 Module (com.intellij.openapi.module.Module)3 Pair (com.intellij.openapi.util.Pair)3 Ref (com.intellij.openapi.util.Ref)3 Nullable (org.jetbrains.annotations.Nullable)3 TemplateState (com.intellij.codeInsight.template.impl.TemplateState)2 Language (com.intellij.lang.Language)2 CustomShortcutSet (com.intellij.openapi.actionSystem.CustomShortcutSet)2