Search in sources :

Example 21 with DocumentAdapter

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

the class MoveClassesOrPackagesDialog method createPackageChooser.

private ReferenceEditorComboWithBrowseButton createPackageChooser() {
    final ReferenceEditorComboWithBrowseButton packageChooser = new PackageNameReferenceEditorCombo("", myProject, RECENTS_KEY, RefactoringBundle.message("choose.destination.package"));
    final Document document = packageChooser.getChildComponent().getDocument();
    document.addDocumentListener(new DocumentAdapter() {

        public void documentChanged(DocumentEvent e) {
            validateButtons();
        }
    });
    return packageChooser;
}
Also used : DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) Document(com.intellij.openapi.editor.Document) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) ReferenceEditorComboWithBrowseButton(com.intellij.ui.ReferenceEditorComboWithBrowseButton) PackageNameReferenceEditorCombo(com.intellij.refactoring.ui.PackageNameReferenceEditorCombo)

Example 22 with DocumentAdapter

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

the class MoveClassesOrPackagesDialog method createUIComponents.

private void createUIComponents() {
    myMainPanel = new JPanel();
    myWithBrowseButtonReference = createPackageChooser();
    myClassPackageChooser = createPackageChooser();
    GlobalSearchScope scope = JavaProjectRootsUtil.getScopeWithoutGeneratedSources(ProjectScope.getProjectScope(myProject), myProject);
    myInnerClassChooser = new ClassNameReferenceEditor(myProject, null, scope);
    myInnerClassChooser.addDocumentListener(new DocumentAdapter() {

        public void documentChanged(DocumentEvent e) {
            validateButtons();
        }
    });
    // override CardLayout sizing behavior
    myCardPanel = new JPanel() {

        public Dimension getMinimumSize() {
            return myHavePackages ? myMovePackagePanel.getMinimumSize() : myMoveClassPanel.getMinimumSize();
        }

        public Dimension getPreferredSize() {
            return myHavePackages ? myMovePackagePanel.getPreferredSize() : myMoveClassPanel.getPreferredSize();
        }
    };
    myDestinationFolderCB = new DestinationFolderComboBox() {

        @Override
        public String getTargetPackage() {
            return MoveClassesOrPackagesDialog.this.getTargetPackage();
        }
    };
}
Also used : ClassNameReferenceEditor(com.intellij.refactoring.ui.ClassNameReferenceEditor) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent)

Example 23 with DocumentAdapter

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

the class MoveMembersDialog method createNorthPanel.

protected JComponent createNorthPanel() {
    JPanel panel = new JPanel(new BorderLayout());
    JPanel _panel;
    Box box = Box.createVerticalBox();
    _panel = new JPanel(new BorderLayout());
    JTextField sourceClassField = new JTextField();
    sourceClassField.setText(mySourceClassName);
    sourceClassField.setEditable(false);
    _panel.add(new JLabel(RefactoringBundle.message("move.members.move.members.from.label")), BorderLayout.NORTH);
    _panel.add(sourceClassField, BorderLayout.CENTER);
    box.add(_panel);
    box.add(Box.createVerticalStrut(10));
    _panel = new JPanel(new BorderLayout());
    JLabel label = new JLabel(RefactoringBundle.message("move.members.to.fully.qualified.name.label"));
    label.setLabelFor(myTfTargetClassName);
    _panel.add(label, BorderLayout.NORTH);
    _panel.add(myTfTargetClassName, BorderLayout.CENTER);
    _panel.add(myIntroduceEnumConstants, BorderLayout.SOUTH);
    box.add(_panel);
    myTfTargetClassName.getChildComponent().getDocument().addDocumentListener(new DocumentAdapter() {

        public void documentChanged(DocumentEvent e) {
            myMemberInfoModel.updateTargetClass();
            validateButtons();
        }
    });
    panel.add(box, BorderLayout.CENTER);
    panel.add(Box.createVerticalStrut(10), BorderLayout.SOUTH);
    validateButtons();
    return panel;
}
Also used : DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent)

Example 24 with DocumentAdapter

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

the class TextCompletionUtil method installCompletionHint.

public static void installCompletionHint(@NotNull EditorEx editor) {
    String completionShortcutText = KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction(IdeActions.ACTION_CODE_COMPLETION));
    if (!StringUtil.isEmpty(completionShortcutText)) {
        final Ref<Boolean> toShowHintRef = new Ref<>(true);
        editor.getDocument().addDocumentListener(new DocumentAdapter() {

            @Override
            public void documentChanged(DocumentEvent e) {
                toShowHintRef.set(false);
            }
        });
        editor.addFocusListener(new FocusChangeListener() {

            @Override
            public void focusGained(final Editor editor) {
                if (toShowHintRef.get() && editor.getDocument().getText().isEmpty()) {
                    ApplicationManager.getApplication().invokeLater(() -> HintManager.getInstance().showInformationHint(editor, "Code completion available ( " + completionShortcutText + " )"));
                }
            }

            @Override
            public void focusLost(Editor editor) {
            // Do nothing
            }
        });
    }
}
Also used : Ref(com.intellij.openapi.util.Ref) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) Editor(com.intellij.openapi.editor.Editor) FocusChangeListener(com.intellij.openapi.editor.ex.FocusChangeListener)

Example 25 with DocumentAdapter

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

the class JavaMethodCallElement method setupNonFilledArgumentRemoving.

private static void setupNonFilledArgumentRemoving(final Editor editor, final TemplateState templateState) {
    AtomicInteger maxEditedVariable = new AtomicInteger(-1);
    editor.getDocument().addDocumentListener(new DocumentAdapter() {

        @Override
        public void documentChanged(DocumentEvent e) {
            maxEditedVariable.set(Math.max(maxEditedVariable.get(), templateState.getCurrentVariableNumber()));
        }
    }, templateState);
    templateState.addTemplateStateListener(new TemplateEditingAdapter() {

        @Override
        public void currentVariableChanged(TemplateState templateState, Template template, int oldIndex, int newIndex) {
            maxEditedVariable.set(Math.max(maxEditedVariable.get(), oldIndex));
        }

        @Override
        public void beforeTemplateFinished(TemplateState state, Template template, boolean brokenOff) {
            if (brokenOff) {
                removeUntouchedArguments((TemplateImpl) template);
            }
        }

        private void removeUntouchedArguments(TemplateImpl template) {
            int firstUnchangedVar = maxEditedVariable.get() + 1;
            if (firstUnchangedVar >= template.getVariableCount())
                return;
            TextRange startRange = templateState.getVariableRange(template.getVariableNameAt(firstUnchangedVar));
            TextRange endRange = templateState.getVariableRange(template.getVariableNameAt(template.getVariableCount() - 1));
            if (startRange == null || endRange == null)
                return;
            WriteCommandAction.runWriteCommandAction(editor.getProject(), () -> editor.getDocument().deleteString(startRange.getStartOffset(), endRange.getEndOffset()));
        }
    });
}
Also used : TemplateImpl(com.intellij.codeInsight.template.impl.TemplateImpl) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) TextRange(com.intellij.openapi.util.TextRange) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) TemplateState(com.intellij.codeInsight.template.impl.TemplateState)

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