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;
}
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
}
});
}
}
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)));
}
}
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);
}
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);
}
Aggregations