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