Search in sources :

Example 11 with DocumentEvent

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

the class LiveTemplateSettingsEditor method createComponents.

private void createComponents(boolean allowNoContexts) {
    JPanel panel = new JPanel(new GridBagLayout());
    GridBag gb = new GridBag().setDefaultInsets(4, 4, 4, 4).setDefaultWeightY(1).setDefaultFill(GridBagConstraints.BOTH);
    JPanel editorPanel = new JPanel(new BorderLayout(4, 4));
    editorPanel.setPreferredSize(JBUI.size(250, 100));
    editorPanel.setMinimumSize(editorPanel.getPreferredSize());
    editorPanel.add(myTemplateEditor.getComponent(), BorderLayout.CENTER);
    JLabel templateTextLabel = new JLabel(CodeInsightBundle.message("dialog.edit.template.template.text.title"));
    templateTextLabel.setLabelFor(myTemplateEditor.getContentComponent());
    editorPanel.add(templateTextLabel, BorderLayout.NORTH);
    editorPanel.setFocusable(false);
    panel.add(editorPanel, gb.nextLine().next().weighty(1).weightx(1).coverColumn(2));
    myEditVariablesButton = new JButton(CodeInsightBundle.message("dialog.edit.template.button.edit.variables"));
    myEditVariablesButton.setDefaultCapable(false);
    myEditVariablesButton.setMaximumSize(myEditVariablesButton.getPreferredSize());
    panel.add(myEditVariablesButton, gb.next().weighty(0));
    myTemplateOptionsPanel = new JPanel(new BorderLayout());
    myTemplateOptionsPanel.add(createTemplateOptionsPanel());
    panel.add(myTemplateOptionsPanel, gb.nextLine().next().next().coverColumn(2).weighty(1));
    panel.add(createShortContextPanel(allowNoContexts), gb.nextLine().next().weighty(0).fillCellNone().anchor(GridBagConstraints.WEST));
    myTemplateEditor.getDocument().addDocumentListener(new DocumentAdapter() {

        @Override
        public void documentChanged(DocumentEvent e) {
            validateEditVariablesButton();
            myTemplate.setString(myTemplateEditor.getDocument().getText());
            applyVariables(updateVariablesByTemplateText());
            myNodeChanged.run();
        }
    });
    myEditVariablesButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(@NotNull ActionEvent e) {
            editVariables();
        }
    });
    add(createNorthPanel(), BorderLayout.NORTH);
    add(panel, BorderLayout.CENTER);
}
Also used : DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) GridBag(com.intellij.util.ui.GridBag) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent)

Example 12 with DocumentEvent

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

the class FindDialog method initCombobox.

private void initCombobox(@NotNull final ComboBox comboBox) {
    comboBox.setEditable(true);
    comboBox.setMaximumRowCount(8);
    comboBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            validateFindButton();
        }
    });
    final Component editorComponent = comboBox.getEditor().getEditorComponent();
    if (editorComponent instanceof EditorTextField) {
        final EditorTextField etf = (EditorTextField) editorComponent;
        DocumentAdapter listener = new DocumentAdapter() {

            @Override
            public void documentChanged(final DocumentEvent e) {
                handleComboBoxValueChanged(comboBox);
            }
        };
        etf.addDocumentListener(listener);
        myComboBoxListeners.put(etf, listener);
    } else {
        if (editorComponent instanceof JTextComponent) {
            final javax.swing.text.Document document = ((JTextComponent) editorComponent).getDocument();
            final com.intellij.ui.DocumentAdapter documentAdapter = new com.intellij.ui.DocumentAdapter() {

                @Override
                protected void textChanged(javax.swing.event.DocumentEvent e) {
                    handleAnyComboBoxValueChanged(comboBox);
                }
            };
            document.addDocumentListener(documentAdapter);
            Disposer.register(myDisposable, new Disposable() {

                @Override
                public void dispose() {
                    document.removeDocumentListener(documentAdapter);
                }
            });
        } else {
            assert false;
        }
    }
    if (!myHelper.getModel().isReplaceState()) {
        makeResultsPreviewActionOverride(comboBox, KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), "choosePrevious", () -> {
            int row = myResultsPreviewTable.getSelectedRow();
            if (row > 0)
                myResultsPreviewTable.setRowSelectionInterval(row - 1, row - 1);
            TableUtil.scrollSelectionToVisible(myResultsPreviewTable);
        });
        makeResultsPreviewActionOverride(comboBox, KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), "chooseNext", () -> {
            int row = myResultsPreviewTable.getSelectedRow();
            if (row >= -1 && row + 1 < myResultsPreviewTable.getRowCount()) {
                myResultsPreviewTable.setRowSelectionInterval(row + 1, row + 1);
                TableUtil.scrollSelectionToVisible(myResultsPreviewTable);
            }
        });
        makeResultsPreviewActionOverride(comboBox, KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, 0), "scrollUp", () -> {
            ScrollingUtil.movePageUp(myResultsPreviewTable);
        });
        makeResultsPreviewActionOverride(comboBox, KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0), "scrollDown", () -> {
            ScrollingUtil.movePageDown(myResultsPreviewTable);
        });
        AnAction action = new AnAction() {

            @Override
            public void actionPerformed(AnActionEvent e) {
                if (isResultsPreviewTabActive()) {
                    navigateToSelectedUsage(myResultsPreviewTable);
                }
            }
        };
        action.registerCustomShortcutSet(CommonShortcuts.getEditSource(), comboBox, myDisposable);
        new AnAction() {

            @Override
            public void actionPerformed(AnActionEvent e) {
                if (!isResultsPreviewTabActive() || myResultsPreviewTable.getSelectedRowCount() == 0)
                    doOKAction();
                else
                    action.actionPerformed(e);
            }
        }.registerCustomShortcutSet(CommonShortcuts.ENTER, comboBox, myDisposable);
    }
}
Also used : Disposable(com.intellij.openapi.Disposable) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) JTextComponent(javax.swing.text.JTextComponent) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) javax.swing(javax.swing) com.intellij.ui(com.intellij.ui) com.intellij.openapi.ui(com.intellij.openapi.ui) JTextComponent(javax.swing.text.JTextComponent)

Example 13 with DocumentEvent

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

the class FileTemplateConfigurable method createEditor.

private Editor createEditor() {
    EditorFactory editorFactory = EditorFactory.getInstance();
    Document doc = myFile == null ? editorFactory.createDocument(myTemplate == null ? "" : myTemplate.getText()) : PsiDocumentManager.getInstance(myFile.getProject()).getDocument(myFile);
    assert doc != null;
    Editor editor = editorFactory.createEditor(doc, myProject);
    EditorSettings editorSettings = editor.getSettings();
    editorSettings.setVirtualSpace(false);
    editorSettings.setLineMarkerAreaShown(false);
    editorSettings.setIndentGuidesShown(false);
    editorSettings.setLineNumbersShown(false);
    editorSettings.setFoldingOutlineShown(false);
    editorSettings.setAdditionalColumnsCount(3);
    editorSettings.setAdditionalLinesCount(3);
    editorSettings.setCaretRowShown(false);
    editor.getDocument().addDocumentListener(new DocumentAdapter() {

        @Override
        public void documentChanged(DocumentEvent e) {
            onTextChanged();
        }
    });
    ((EditorEx) editor).setHighlighter(createHighlighter());
    JPanel topPanel = new JPanel(new BorderLayout());
    JPanel southPanel = new JPanel(new HorizontalLayout(40));
    southPanel.add(myAdjustBox);
    southPanel.add(myLiveTemplateBox);
    topPanel.add(southPanel, BorderLayout.SOUTH);
    topPanel.add(editor.getComponent(), BorderLayout.CENTER);
    mySplitter.setFirstComponent(topPanel);
    return editor;
}
Also used : EditorFactory(com.intellij.openapi.editor.EditorFactory) EditorSettings(com.intellij.openapi.editor.EditorSettings) EditorEx(com.intellij.openapi.editor.ex.EditorEx) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) Document(com.intellij.openapi.editor.Document) Editor(com.intellij.openapi.editor.Editor) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) HorizontalLayout(com.intellij.ui.components.panels.HorizontalLayout)

Example 14 with DocumentEvent

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

the class ChangeSignatureDialogBase method createParametersPanel.

protected JPanel createParametersPanel(boolean hasTabsInDialog) {
    myParametersTable = new TableView<ParameterTableModelItem>(myParametersTableModel) {

        @Override
        public void removeEditor() {
            clearEditorListeners();
            super.removeEditor();
        }

        @Override
        public void editingStopped(ChangeEvent e) {
            super.editingStopped(e);
            // to update disabled cells background
            repaint();
        }

        private void clearEditorListeners() {
            final TableCellEditor editor = getCellEditor();
            if (editor instanceof StringTableCellEditor) {
                final StringTableCellEditor ed = (StringTableCellEditor) editor;
                ed.clearListeners();
            } else if (editor instanceof CodeFragmentTableCellEditorBase) {
                ((CodeFragmentTableCellEditorBase) editor).clearListeners();
            }
        }

        @Override
        public Component prepareEditor(final TableCellEditor editor, final int row, final int column) {
            final DocumentAdapter listener = new DocumentAdapter() {

                @Override
                public void documentChanged(DocumentEvent e) {
                    final TableCellEditor ed = myParametersTable.getCellEditor();
                    if (ed != null) {
                        Object editorValue = ed.getCellEditorValue();
                        myParametersTableModel.setValueAtWithoutUpdate(editorValue, row, column);
                        updateSignature();
                    }
                }
            };
            if (editor instanceof StringTableCellEditor) {
                final StringTableCellEditor ed = (StringTableCellEditor) editor;
                ed.addDocumentListener(listener);
            } else if (editor instanceof CodeFragmentTableCellEditorBase) {
                ((CodeFragmentTableCellEditorBase) editor).addDocumentListener(listener);
            }
            return super.prepareEditor(editor, row, column);
        }

        @Override
        public void editingCanceled(ChangeEvent e) {
            super.editingCanceled(e);
        }
    };
    myParametersTable.setCellSelectionEnabled(true);
    myParametersTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    myParametersTable.getSelectionModel().setSelectionInterval(0, 0);
    myParametersTable.setSurrendersFocusOnKeystroke(true);
    myPropagateParamChangesButton.setShortcut(CustomShortcutSet.fromString("alt G"));
    if (isListTableViewSupported()) {
        myParametersList = createParametersListTable();
        final JPanel buttonsPanel = ToolbarDecorator.createDecorator(myParametersList.getTable()).addExtraAction(myPropagateParamChangesButton).createPanel();
        myParametersList.getTable().getModel().addTableModelListener(mySignatureUpdater);
        return buttonsPanel;
    } else {
        final JPanel buttonsPanel = ToolbarDecorator.createDecorator(getTableComponent()).addExtraAction(myPropagateParamChangesButton).createPanel();
        myPropagateParamChangesButton.setEnabled(false);
        myPropagateParamChangesButton.setVisible(false);
        myParametersTable.setStriped(true);
        myParametersTableModel.addTableModelListener(mySignatureUpdater);
        customizeParametersTable(myParametersTable);
        return buttonsPanel;
    }
}
Also used : DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) ChangeEvent(javax.swing.event.ChangeEvent) TableCellEditor(javax.swing.table.TableCellEditor)

Example 15 with DocumentEvent

use of com.intellij.openapi.editor.event.DocumentEvent 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)

Aggregations

DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)54 DocumentAdapter (com.intellij.openapi.editor.event.DocumentAdapter)40 Document (com.intellij.openapi.editor.Document)14 DocumentListener (com.intellij.openapi.editor.event.DocumentListener)12 EditorTextField (com.intellij.ui.EditorTextField)8 ActionEvent (java.awt.event.ActionEvent)8 ActionListener (java.awt.event.ActionListener)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 Nullable (org.jetbrains.annotations.Nullable)5 Disposable (com.intellij.openapi.Disposable)4 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)4 Editor (com.intellij.openapi.editor.Editor)4 ReferenceEditorComboWithBrowseButton (com.intellij.ui.ReferenceEditorComboWithBrowseButton)4 NotNull (org.jetbrains.annotations.NotNull)4 Language (com.intellij.lang.Language)3 AnAction (com.intellij.openapi.actionSystem.AnAction)3 Module (com.intellij.openapi.module.Module)3 TemplateState (com.intellij.codeInsight.template.impl.TemplateState)2 FrozenDocument (com.intellij.openapi.editor.impl.FrozenDocument)2 LanguageFileType (com.intellij.openapi.fileTypes.LanguageFileType)2