use of com.intellij.openapi.editor.event.DocumentAdapter in project intellij-community by JetBrains.
the class JavaChangeSignatureDialog method createAdditionalPanels.
@NotNull
protected List<Pair<String, JPanel>> createAdditionalPanels() {
// this method is invoked before constructor body
myExceptionsModel = new ExceptionsTableModel(myMethod.getMethod().getThrowsList());
myExceptionsModel.setTypeInfos(myMethod.getMethod());
final JBTable table = new JBTable(myExceptionsModel);
table.setStriped(true);
table.setRowHeight(20);
table.getColumnModel().getColumn(0).setCellRenderer(new CodeFragmentTableCellRenderer(myProject));
final JavaCodeFragmentTableCellEditor cellEditor = new JavaCodeFragmentTableCellEditor(myProject);
cellEditor.addDocumentListener(new DocumentAdapter() {
@Override
public void documentChanged(DocumentEvent e) {
final int row = table.getSelectedRow();
final int col = table.getSelectedColumn();
myExceptionsModel.setValueAt(cellEditor.getCellEditorValue(), row, col);
updateSignature();
}
});
table.getColumnModel().getColumn(0).setCellEditor(cellEditor);
table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.getSelectionModel().setSelectionInterval(0, 0);
table.setSurrendersFocusOnKeystroke(true);
myPropExceptionsButton = new AnActionButton(RefactoringBundle.message("changeSignature.propagate.exceptions.title"), null, AllIcons.Hierarchy.Caller) {
@Override
public void actionPerformed(AnActionEvent e) {
final Ref<JavaCallerChooser> chooser = new Ref<>();
Consumer<Set<PsiMethod>> callback = psiMethods -> {
myMethodsToPropagateExceptions = psiMethods;
myExceptionPropagationTree = chooser.get().getTree();
};
chooser.set(new JavaCallerChooser(myMethod.getMethod(), myProject, RefactoringBundle.message("changeSignature.exception.caller.chooser"), myExceptionPropagationTree, callback));
chooser.get().show();
}
};
myPropExceptionsButton.setShortcut(CustomShortcutSet.fromString("alt X"));
final JPanel panel = ToolbarDecorator.createDecorator(table).addExtraAction(myPropExceptionsButton).createPanel();
panel.setBorder(IdeBorderFactory.createEmptyBorder());
myExceptionsModel.addTableModelListener(mySignatureUpdater);
final ArrayList<Pair<String, JPanel>> result = new ArrayList<>();
final String message = RefactoringBundle.message("changeSignature.exceptions.panel.border.title");
result.add(Pair.create(message, panel));
return result;
}
use of com.intellij.openapi.editor.event.DocumentAdapter in project kotlin by JetBrains.
the class PluginStartupComponent method initComponent.
@Override
public void initComponent() {
registerPathVariable();
if (ApplicationManager.getApplication().isUnitTestMode()) {
ThreadTrackerPatcherForTeamCityTesting.INSTANCE.patchThreadTracker();
}
JarUserDataManager.INSTANCE.register(KotlinJavaScriptLibraryDetectionUtil.HasKotlinJSMetadataInJar.INSTANCE);
DebuggerFiltersUtilKt.addKotlinStdlibDebugFilterIfNeeded();
try {
// API added in 15.0.2
UpdateChecker.INSTANCE.getExcludedFromUpdateCheckPlugins().add("org.jetbrains.kotlin");
} catch (Throwable throwable) {
LOG.debug("Excluding Kotlin plugin updates using old API", throwable);
UpdateChecker.getDisabledToUpdatePlugins().add("org.jetbrains.kotlin");
}
EditorFactory.getInstance().getEventMulticaster().addDocumentListener(new DocumentAdapter() {
@Override
public void documentChanged(DocumentEvent e) {
VirtualFile virtualFile = FileDocumentManager.getInstance().getFile(e.getDocument());
if (virtualFile != null && virtualFile.getFileType() == KotlinFileType.INSTANCE) {
KotlinPluginUpdater.Companion.getInstance().kotlinFileEdited();
}
}
});
}
use of com.intellij.openapi.editor.event.DocumentAdapter in project intellij-community by JetBrains.
the class CheckRegExpForm method createUIComponents.
private void createUIComponents() {
myProject = myRegexpFile.getProject();
Document document = PsiDocumentManager.getInstance(myProject).getDocument(myRegexpFile);
final Language language = myRegexpFile.getLanguage();
final LanguageFileType fileType;
if (language instanceof RegExpLanguage) {
fileType = RegExpLanguage.INSTANCE.getAssociatedFileType();
} else {
// for correct syntax highlighting
fileType = new RegExpFileType(language);
}
myRegExp = new EditorTextField(document, myProject, fileType);
final String sampleText = PropertiesComponent.getInstance(myProject).getValue(LAST_EDITED_REGEXP, "Sample Text");
mySampleText = new EditorTextField(sampleText, myProject, PlainTextFileType.INSTANCE) {
@Override
protected void updateBorder(@NotNull EditorEx editor) {
setupBorder(editor);
}
};
mySampleText.setOneLineMode(false);
int preferredWidth = Math.max(JBUI.scale(250), myRegExp.getPreferredSize().width);
myRegExp.setPreferredWidth(preferredWidth);
mySampleText.setPreferredWidth(preferredWidth);
myRootPanel = new JPanel(new BorderLayout()) {
Disposable disposable;
Alarm updater;
@Override
public void addNotify() {
super.addNotify();
disposable = Disposer.newDisposable();
IdeFocusManager.getGlobalInstance().requestFocus(mySampleText, true);
new AnAction() {
@Override
public void actionPerformed(AnActionEvent e) {
IdeFocusManager.findInstance().requestFocus(myRegExp.getFocusTarget(), true);
}
}.registerCustomShortcutSet(CustomShortcutSet.fromString("shift TAB"), mySampleText);
updater = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, disposable);
DocumentAdapter documentListener = new DocumentAdapter() {
@Override
public void documentChanged(DocumentEvent e) {
update();
}
};
myRegExp.addDocumentListener(documentListener);
mySampleText.addDocumentListener(documentListener);
update();
mySampleText.selectAll();
}
public void update() {
final TransactionId transactionId = TransactionGuard.getInstance().getContextTransaction();
updater.cancelAllRequests();
if (!updater.isDisposed()) {
updater.addRequest(() -> {
final RegExpMatchResult result = isMatchingText(myRegexpFile, mySampleText.getText());
TransactionGuard.getInstance().submitTransaction(myProject, transactionId, () -> setBalloonState(result));
}, 200);
}
}
@Override
public void removeNotify() {
super.removeNotify();
Disposer.dispose(disposable);
PropertiesComponent.getInstance(myProject).setValue(LAST_EDITED_REGEXP, mySampleText.getText());
}
};
myRootPanel.setBorder(JBUI.Borders.empty(UIUtil.DEFAULT_VGAP, UIUtil.DEFAULT_HGAP));
}
use of com.intellij.openapi.editor.event.DocumentAdapter in project intellij-community by JetBrains.
the class FileEncodingTest method testSettingEncodingManually.
public void testSettingEncodingManually() throws IOException {
final StringBuilder text = new StringBuilder(THREE_RUSSIAN_LETTERS);
VirtualFile file = createTempFile("txt", NO_BOM, text.toString(), WINDOWS_1251);
File ioFile = new File(file.getPath());
EncodingManager.getInstance().setEncoding(file, WINDOWS_1251);
final Document document = getDocument(file);
final boolean[] changed = { false };
document.addDocumentListener(new DocumentAdapter() {
@Override
public void documentChanged(final DocumentEvent event) {
changed[0] = true;
}
});
EncodingManager.getInstance().setEncoding(file, CharsetToolkit.UTF8_CHARSET);
//text in editor changed
assertEquals(CharsetToolkit.UTF8_CHARSET, file.getCharset());
UIUtil.dispatchAllInvocationEvents();
assertTrue(changed[0]);
changed[0] = false;
FileDocumentManager.getInstance().saveAllDocuments();
byte[] bytes = FileUtil.loadFileBytes(ioFile);
//file on disk is still windows
assertTrue(Arrays.equals(text.toString().getBytes(WINDOWS_1251.name()), bytes));
ApplicationManager.getApplication().runWriteAction(() -> CommandProcessor.getInstance().executeCommand(getProject(), () -> {
document.insertString(0, "x");
text.insert(0, "x");
}, null, null));
assertTrue(changed[0]);
changed[0] = false;
EncodingManager.getInstance().setEncoding(file, US_ASCII);
assertEquals(US_ASCII, file.getCharset());
UIUtil.dispatchAllInvocationEvents();
//reloaded again
assertTrue(changed[0]);
//after 'save as us' file on disk changed
bytes = FileUtil.loadFileBytes(ioFile);
assertTrue(Arrays.equals(text.toString().getBytes(US_ASCII.name()), bytes));
}
use of com.intellij.openapi.editor.event.DocumentAdapter in project intellij-community by JetBrains.
the class RangeMarkerTest method testDocSynchronizerPrefersLineBoundaryChanges.
public void testDocSynchronizerPrefersLineBoundaryChanges() throws Exception {
String text = "import java.awt.List;\n" + "[import java.util.ArrayList;\n]" + "import java.util.HashMap;\n" + "import java.util.Map;";
RangeMarker marker = createMarker(text);
synchronizer.startTransaction(getProject(), document, psiFile);
String newText = StringUtil.replaceSubstring(document.getText(), TextRange.create(marker), "");
synchronizer.replaceString(document, 0, document.getTextLength(), newText);
final List<DocumentEvent> events = new ArrayList<>();
document.addDocumentListener(new DocumentAdapter() {
@Override
public void documentChanged(DocumentEvent e) {
events.add(e);
}
});
synchronizer.commitTransaction(document);
assertEquals(newText, document.getText());
DocumentEvent event = assertOneElement(events);
assertEquals("DocumentEventImpl[myOffset=22, myOldLength=28, myNewLength=0, myOldString='import java.util.ArrayList;\n', myNewString=''].", event.toString());
}
Aggregations