Search in sources :

Example 1 with FocusChangeListener

use of com.intellij.openapi.editor.ex.FocusChangeListener in project intellij-community by JetBrains.

the class ComboboxEditorTextField method createEditor.

@Override
protected EditorEx createEditor() {
    final EditorEx result = super.createEditor();
    result.addFocusListener(new FocusChangeListener() {

        @Override
        public void focusGained(Editor editor) {
            repaintComboBox();
        }

        @Override
        public void focusLost(Editor editor) {
            repaintComboBox();
        }
    });
    return result;
}
Also used : EditorEx(com.intellij.openapi.editor.ex.EditorEx) Editor(com.intellij.openapi.editor.Editor) FixedComboBoxEditor(com.intellij.openapi.ui.FixedComboBoxEditor) FocusChangeListener(com.intellij.openapi.editor.ex.FocusChangeListener)

Example 2 with FocusChangeListener

use of com.intellij.openapi.editor.ex.FocusChangeListener 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 3 with FocusChangeListener

use of com.intellij.openapi.editor.ex.FocusChangeListener in project intellij-community by JetBrains.

the class EditorTextField method setupBorder.

protected void setupBorder(@NotNull EditorEx editor) {
    if (UIUtil.isUnderAquaLookAndFeel() || UIUtil.isUnderDarcula() || UIUtil.isUnderIntelliJLaF()) {
        editor.setBorder(UIUtil.isUnderDarcula() || UIUtil.isUnderIntelliJLaF() ? new DarculaEditorTextFieldBorder() : new MacUIUtil.EditorTextFieldBorder(this));
        editor.addFocusListener(new FocusChangeListener() {

            @Override
            public void focusGained(Editor editor) {
                repaint();
            }

            @Override
            public void focusLost(Editor editor) {
                repaint();
            }
        });
    } else if (UIUtil.isUnderAlloyLookAndFeel() || UIUtil.isUnderJGoodiesLookAndFeel()) {
        editor.setBorder(BorderFactory.createCompoundBorder(UIUtil.getTextFieldBorder(), BorderFactory.createEmptyBorder(1, 1, 1, 1)));
    } else {
        editor.setBorder(BorderFactory.createCompoundBorder(UIUtil.getTextFieldBorder(), BorderFactory.createEmptyBorder(2, 2, 2, 2)));
    }
}
Also used : DarculaEditorTextFieldBorder(com.intellij.ide.ui.laf.darcula.ui.DarculaEditorTextFieldBorder) DarculaEditorTextFieldBorder(com.intellij.ide.ui.laf.darcula.ui.DarculaEditorTextFieldBorder) FocusChangeListener(com.intellij.openapi.editor.ex.FocusChangeListener)

Example 4 with FocusChangeListener

use of com.intellij.openapi.editor.ex.FocusChangeListener in project intellij-community by JetBrains.

the class ResourceBundleEditor method recreateEditorsPanel.

void recreateEditorsPanel() {
    if (!myProject.isOpen() || myDisposed)
        return;
    myValuesPanel.removeAll();
    myValuesPanel.setLayout(new CardLayout());
    JPanel valuesPanelComponent = new MyJPanel(new GridBagLayout());
    myValuesPanel.add(new JBScrollPane(valuesPanelComponent) {

        @Override
        public void updateUI() {
            super.updateUI();
            getViewport().setBackground(UIUtil.getPanelBackground());
        }
    }, VALUES);
    myValuesPanel.add(myNoPropertySelectedPanel, NO_PROPERTY_SELECTED);
    final List<PropertiesFile> propertiesFiles = myResourceBundle.getPropertiesFiles();
    GridBagConstraints gc = new GridBagConstraints(0, 0, 0, 0, 0, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, JBUI.insets(5), 0, 0);
    releaseAllEditors();
    myTitledPanels.clear();
    int y = 0;
    Editor previousEditor = null;
    Editor firstEditor = null;
    for (final PropertiesFile propertiesFile : propertiesFiles) {
        final EditorEx editor = createEditor();
        final Editor oldEditor = myEditors.put(propertiesFile.getVirtualFile(), editor);
        if (firstEditor == null) {
            firstEditor = editor;
        }
        if (previousEditor != null) {
            editor.putUserData(ChooseSubsequentPropertyValueEditorAction.PREV_EDITOR_KEY, previousEditor);
            previousEditor.putUserData(ChooseSubsequentPropertyValueEditorAction.NEXT_EDITOR_KEY, editor);
        }
        previousEditor = editor;
        if (oldEditor != null) {
            EditorFactory.getInstance().releaseEditor(oldEditor);
        }
        editor.setViewer(!propertiesFile.getVirtualFile().isWritable());
        editor.getContentComponent().addKeyListener(new KeyAdapter() {

            @Override
            public void keyTyped(KeyEvent e) {
                if (editor.isViewer()) {
                    editor.setViewer(ReadonlyStatusHandler.getInstance(myProject).ensureFilesWritable(propertiesFile.getVirtualFile()).hasReadonlyFiles());
                }
            }
        });
        editor.addFocusListener(new FocusChangeListener() {

            @Override
            public void focusGained(final Editor editor) {
                mySelectedEditor = editor;
            }

            @Override
            public void focusLost(final Editor editor) {
                if (!editor.isViewer() && propertiesFile.getContainingFile().isValid()) {
                    writeEditorPropertyValue(null, editor, propertiesFile.getVirtualFile());
                    myVfsListener.flush();
                }
            }
        });
        gc.gridx = 0;
        gc.gridy = y++;
        gc.gridheight = 1;
        gc.gridwidth = GridBagConstraints.REMAINDER;
        gc.weightx = 1;
        gc.weighty = 1;
        gc.anchor = GridBagConstraints.CENTER;
        String title = propertiesFile.getName();
        title += PropertiesUtil.getPresentableLocale(propertiesFile.getLocale());
        JComponent comp = new JPanel(new BorderLayout()) {

            @Override
            public Dimension getPreferredSize() {
                Insets insets = getBorder().getBorderInsets(this);
                return new Dimension(100, editor.getLineHeight() * 4 + insets.top + insets.bottom);
            }
        };
        comp.add(editor.getComponent(), BorderLayout.CENTER);
        comp.setBorder(IdeBorderFactory.createTitledBorder(title, false));
        myTitledPanels.put(propertiesFile.getVirtualFile(), (JPanel) comp);
        valuesPanelComponent.add(comp, gc);
    }
    if (previousEditor != null) {
        previousEditor.putUserData(ChooseSubsequentPropertyValueEditorAction.NEXT_EDITOR_KEY, firstEditor);
        firstEditor.putUserData(ChooseSubsequentPropertyValueEditorAction.PREV_EDITOR_KEY, previousEditor);
    }
    gc.gridx = 0;
    gc.gridy = y;
    gc.gridheight = GridBagConstraints.REMAINDER;
    gc.gridwidth = GridBagConstraints.REMAINDER;
    gc.weightx = 10;
    gc.weighty = 1;
    valuesPanelComponent.add(new JPanel(), gc);
    selectionChanged();
    myValuesPanel.repaint();
    updateEditorsFromProperties(true);
}
Also used : EditorEx(com.intellij.openapi.editor.ex.EditorEx) KeyAdapter(java.awt.event.KeyAdapter) KeyEvent(java.awt.event.KeyEvent) XmlPropertiesFile(com.intellij.lang.properties.xml.XmlPropertiesFile) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) com.intellij.openapi.fileEditor(com.intellij.openapi.fileEditor) JBScrollPane(com.intellij.ui.components.JBScrollPane) FocusChangeListener(com.intellij.openapi.editor.ex.FocusChangeListener)

Example 5 with FocusChangeListener

use of com.intellij.openapi.editor.ex.FocusChangeListener in project intellij-community by JetBrains.

the class BraceHighlighter method runActivity.

@Override
public void runActivity(@NotNull final Project project) {
    // sorry, upsource
    if (ApplicationManager.getApplication().isHeadlessEnvironment())
        return;
    final EditorEventMulticaster eventMulticaster = EditorFactory.getInstance().getEventMulticaster();
    CaretListener myCaretListener = new CaretAdapter() {

        @Override
        public void caretPositionChanged(CaretEvent e) {
            myAlarm.cancelAllRequests();
            Editor editor = e.getEditor();
            final SelectionModel selectionModel = editor.getSelectionModel();
            // Don't update braces in case of the active selection.
            if (editor.getProject() != project || selectionModel.hasSelection()) {
                return;
            }
            final Document document = editor.getDocument();
            int line = e.getNewPosition().line;
            if (line < 0 || line >= document.getLineCount()) {
                return;
            }
            updateBraces(editor, myAlarm);
        }
    };
    eventMulticaster.addCaretListener(myCaretListener, project);
    final SelectionListener mySelectionListener = new SelectionListener() {

        @Override
        public void selectionChanged(SelectionEvent e) {
            myAlarm.cancelAllRequests();
            Editor editor = e.getEditor();
            if (editor.getProject() != project) {
                return;
            }
            final TextRange oldRange = e.getOldRange();
            final TextRange newRange = e.getNewRange();
            if (oldRange != null && newRange != null && !(oldRange.isEmpty() ^ newRange.isEmpty())) {
                // Don't perform braces update in case of active/absent selection.
                return;
            }
            updateBraces(editor, myAlarm);
        }
    };
    eventMulticaster.addSelectionListener(mySelectionListener, project);
    DocumentListener documentListener = new DocumentAdapter() {

        @Override
        public void documentChanged(DocumentEvent e) {
            myAlarm.cancelAllRequests();
            Editor[] editors = EditorFactory.getInstance().getEditors(e.getDocument(), project);
            for (Editor editor : editors) {
                updateBraces(editor, myAlarm);
            }
        }
    };
    eventMulticaster.addDocumentListener(documentListener, project);
    final FocusChangeListener myFocusChangeListener = new FocusChangeListener() {

        @Override
        public void focusLost(Editor editor) {
            clearBraces(editor);
        }

        @Override
        public void focusGained(Editor editor) {
            updateBraces(editor, myAlarm);
        }
    };
    ((EditorEventMulticasterEx) eventMulticaster).addFocusChangeListner(myFocusChangeListener, project);
    final FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
    fileEditorManager.addFileEditorManagerListener(new FileEditorManagerListener() {

        @Override
        public void selectionChanged(@NotNull FileEditorManagerEvent e) {
            myAlarm.cancelAllRequests();
        }
    }, project);
}
Also used : TextRange(com.intellij.openapi.util.TextRange) Document(com.intellij.openapi.editor.Document) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) EditorEventMulticasterEx(com.intellij.openapi.editor.ex.EditorEventMulticasterEx) SelectionModel(com.intellij.openapi.editor.SelectionModel) Editor(com.intellij.openapi.editor.Editor) FileEditorManagerEvent(com.intellij.openapi.fileEditor.FileEditorManagerEvent) FileEditorManagerListener(com.intellij.openapi.fileEditor.FileEditorManagerListener) FocusChangeListener(com.intellij.openapi.editor.ex.FocusChangeListener)

Aggregations

FocusChangeListener (com.intellij.openapi.editor.ex.FocusChangeListener)5 Editor (com.intellij.openapi.editor.Editor)3 EditorEx (com.intellij.openapi.editor.ex.EditorEx)2 DarculaEditorTextFieldBorder (com.intellij.ide.ui.laf.darcula.ui.DarculaEditorTextFieldBorder)1 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)1 XmlPropertiesFile (com.intellij.lang.properties.xml.XmlPropertiesFile)1 Document (com.intellij.openapi.editor.Document)1 SelectionModel (com.intellij.openapi.editor.SelectionModel)1 DocumentAdapter (com.intellij.openapi.editor.event.DocumentAdapter)1 DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)1 EditorEventMulticasterEx (com.intellij.openapi.editor.ex.EditorEventMulticasterEx)1 com.intellij.openapi.fileEditor (com.intellij.openapi.fileEditor)1 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)1 FileEditorManagerEvent (com.intellij.openapi.fileEditor.FileEditorManagerEvent)1 FileEditorManagerListener (com.intellij.openapi.fileEditor.FileEditorManagerListener)1 FixedComboBoxEditor (com.intellij.openapi.ui.FixedComboBoxEditor)1 Ref (com.intellij.openapi.util.Ref)1 TextRange (com.intellij.openapi.util.TextRange)1 JBScrollPane (com.intellij.ui.components.JBScrollPane)1 KeyAdapter (java.awt.event.KeyAdapter)1