use of com.intellij.openapi.editor.event.DocumentListener in project intellij-community by JetBrains.
the class DocumentImpl method beforeChangedUpdate.
private void beforeChangedUpdate(DocumentEvent event) {
Application app = ApplicationManager.getApplication();
if (app != null) {
FileDocumentManager manager = FileDocumentManager.getInstance();
VirtualFile file = manager.getFile(this);
if (file != null && !file.isValid()) {
LOG.error("File of this document has been deleted.");
}
}
assertInsideCommand();
// initialize line set to track changed lines
getLineSet();
if (!ShutDownTracker.isShutdownHookRunning()) {
DocumentListener[] listeners = getListeners();
for (int i = listeners.length - 1; i >= 0; i--) {
try {
listeners[i].beforeDocumentChange(event);
} catch (Throwable e) {
LOG.error(e);
}
}
}
myEventsHandling = true;
}
use of com.intellij.openapi.editor.event.DocumentListener in project intellij-community by JetBrains.
the class DocumentImpl method changedUpdate.
private void changedUpdate(@NotNull DocumentEvent event, long newModificationStamp, @NotNull CharSequence prevText) {
try {
if (LOG.isDebugEnabled())
LOG.debug(event.toString());
assert event.getOldFragment().length() == event.getOldLength() : "event.getOldFragment().length() = " + event.getOldFragment().length() + "; event.getOldLength() = " + event.getOldLength();
assert event.getNewFragment().length() == event.getNewLength() : "event.getNewFragment().length() = " + event.getNewFragment().length() + "; event.getNewLength() = " + event.getNewLength();
assert prevText.length() + event.getNewLength() - event.getOldLength() == getTextLength() : "prevText.length() = " + prevText.length() + "; event.getNewLength() = " + event.getNewLength() + "; event.getOldLength() = " + event.getOldLength() + "; getTextLength() = " + getTextLength();
myLineSet = getLineSet().update(prevText, event.getOffset(), event.getOffset() + event.getOldLength(), event.getNewFragment(), event.isWholeTextReplaced());
assert getTextLength() == myLineSet.getLength() : "getTextLength() = " + getTextLength() + "; myLineSet.getLength() = " + myLineSet.getLength();
myFrozen = null;
setModificationStamp(newModificationStamp);
if (!ShutDownTracker.isShutdownHookRunning()) {
DocumentListener[] listeners = getListeners();
for (DocumentListener listener : listeners) {
try {
listener.documentChanged(event);
} catch (ProcessCanceledException e) {
if (!myAssertThreading) {
throw e;
} else {
LOG.error("ProcessCanceledException must not be thrown from document listeners for real document", new Throwable(e));
}
} catch (Throwable e) {
LOG.error(e);
}
}
}
} finally {
myEventsHandling = false;
}
}
use of com.intellij.openapi.editor.event.DocumentListener in project intellij-plugins by JetBrains.
the class FlashRunConfigurationForm method initMainClassRelatedControls.
private void initMainClassRelatedControls() {
myOverrideMainClassCheckBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
if (myOverrideMainClassCheckBox.isSelected()) {
updateOutputFileName(myOutputFileNameTextField, false);
}
updateControls();
if (myMainClassComponent.isEnabled()) {
IdeFocusManager.getInstance(myProject).requestFocus(myMainClassComponent.getChildComponent(), true);
}
}
});
myMainClassComponent.addDocumentListener(new DocumentListener() {
@Override
public void documentChanged(final DocumentEvent e) {
final String shortName = StringUtil.getShortName(myMainClassComponent.getText().trim());
if (!shortName.isEmpty()) {
myOutputFileNameTextField.setText(shortName + ".swf");
}
}
});
myOutputFileNameTextField.getDocument().addDocumentListener(new com.intellij.ui.DocumentAdapter() {
@Override
protected void textChanged(final javax.swing.event.DocumentEvent e) {
final FlexBuildConfiguration bc = myBCCombo.getBC();
if (bc != null && bc.getTargetPlatform() == TargetPlatform.Web) {
updateBCOutputLabel(bc);
}
}
});
}
use of com.intellij.openapi.editor.event.DocumentListener in project android by JetBrains.
the class EditLogFilterDialog method createEditorFields.
private void createEditorFields() {
myNameFieldLabel.setLabelFor(myFilterNameField);
myLogMessageField = new RegexFilterComponent(LOG_FILTER_MESSAGE_HISTORY, FILTER_HISTORY_SIZE);
myLogMessageFieldWrapper.add(myLogMessageField);
myLogMessageLabel.setLabelFor(myLogMessageField);
myTagField = new RegexFilterComponent(LOG_FILTER_TAG_HISTORY, FILTER_HISTORY_SIZE);
myTagFieldWrapper.add(myTagField);
myLogTagLabel.setLabelFor(myTagField);
myPidField = new TextFieldWithAutoCompletion<>(myProject, new TextFieldWithAutoCompletion.StringsCompletionProvider(null, null) {
@NotNull
@Override
public Collection<String> getItems(String prefix, boolean cached, CompletionParameters parameters) {
parseExistingMessagesIfNecessary();
setItems(myUsedPids);
return super.getItems(prefix, cached, parameters);
}
@Override
public int compare(String item1, String item2) {
final int pid1 = Integer.parseInt(item1);
final int pid2 = Integer.parseInt(item2);
return Comparing.compare(pid1, pid2);
}
}, true, null);
myPidFieldWrapper.add(myPidField);
myPidLabel.setLabelFor(myPidField);
myPackageNameField = new RegexFilterComponent(LOG_FILTER_PACKAGE_NAME_HISTORY, FILTER_HISTORY_SIZE);
myPackageNameFieldWrapper.add(myPackageNameField);
myPackageNameLabel.setLabelFor(myPackageNameField);
myLogLevelCombo.setModel(new EnumComboBoxModel<>(Log.LogLevel.class));
myLogLevelCombo.setRenderer(new ListCellRendererWrapper() {
@Override
public void customize(JList list, Object value, int index, boolean selected, boolean hasFocus) {
if (value != null) {
setText(StringUtil.capitalize(((Log.LogLevel) value).getStringValue().toLowerCase()));
}
}
});
myLogLevelCombo.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (myActiveFilter == null) {
return;
}
Log.LogLevel selectedItem = (Log.LogLevel) myLogLevelCombo.getSelectedItem();
myActiveFilter.setLogLevel(selectedItem.getStringValue());
}
});
final Key<JComponent> componentKey = new Key<>("myComponent");
myFilterNameField.getDocument().putUserData(componentKey, myFilterNameField);
myPidField.getDocument().putUserData(componentKey, myPidField);
DocumentListener l = new DocumentListener() {
@Override
public void documentChanged(DocumentEvent e) {
if (myActiveFilter == null) {
return;
}
String text = e.getDocument().getText().trim();
JComponent src = e.getDocument().getUserData(componentKey);
if (src == myPidField) {
myActiveFilter.setPid(text);
} else if (src == myFilterNameField) {
int index = myFiltersList.getSelectedIndex();
if (index != -1) {
myFiltersListModel.setElementAt(text, index);
}
myActiveFilter.setName(text);
}
}
};
myFilterNameField.getDocument().addDocumentListener(l);
myPidField.getDocument().addDocumentListener(l);
RegexFilterComponent.Listener rl = new RegexFilterComponent.Listener() {
@Override
public void filterChanged(RegexFilterComponent filter) {
if (myActiveFilter == null) {
return;
}
if (filter == myTagField) {
myActiveFilter.setLogTagPattern(filter.getFilter());
myActiveFilter.setLogTagIsRegex(filter.isRegex());
} else if (filter == myLogMessageField) {
myActiveFilter.setLogMessagePattern(filter.getFilter());
myActiveFilter.setLogMessageIsRegex(filter.isRegex());
} else if (filter == myPackageNameField) {
myActiveFilter.setPackageNamePattern(filter.getFilter());
myActiveFilter.setPackageNameIsRegex(filter.isRegex());
}
}
};
myTagField.addRegexListener(rl);
myLogMessageField.addRegexListener(rl);
myPackageNameField.addRegexListener(rl);
}
use of com.intellij.openapi.editor.event.DocumentListener in project android by JetBrains.
the class TemplateParameterStep2 method addJBDocumentListener.
private void addJBDocumentListener(com.intellij.openapi.editor.Document doc, final JComponent textField) {
DocumentListener listener = new DocumentListener() {
@Override
public void documentChanged(DocumentEvent event) {
saveState(textField);
}
};
Disposable disposable = getDisposable();
if (disposable != null) {
doc.addDocumentListener(listener, disposable);
} else {
doc.addDocumentListener(listener);
}
}
Aggregations