本文整理汇总了Java中com.intellij.openapi.editor.event.DocumentEvent类的典型用法代码示例。如果您正苦于以下问题:Java DocumentEvent类的具体用法?Java DocumentEvent怎么用?Java DocumentEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DocumentEvent类属于com.intellij.openapi.editor.event包,在下文中一共展示了DocumentEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: GCMStructureViewModel
import com.intellij.openapi.editor.event.DocumentEvent; //导入依赖的package包/类
public GCMStructureViewModel(@NotNull PsiFile psiFile, @NotNull final GCMStructureViewRootElement root, Editor editor) {
super(psiFile, root);
withSorters(typeSorter, Sorter.ALPHA_SORTER);
editor.getDocument().addDocumentListener(new DocumentAdapter() {
@Override
public void documentChanged(DocumentEvent event) {
synchronized (needRefresh) {
needRefresh = true;
}
}
});
executor.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
GCMStructureViewModel.this.refreshView();
}
}, 15, 5, TimeUnit.SECONDS);
}
示例2: generatePatchDescription
import com.intellij.openapi.editor.event.DocumentEvent; //导入依赖的package包/类
private String generatePatchDescription(
DocumentEvent documentEvent, List<DiffMatchPatch.Patch> patches) {
logger.info("Creating JSON from patches.");
String source = documentEvent.getSource().toString();
if (documentEvent.getSource().toString().length() <= 20) {
return null;
}
source = source.substring(20, source.length() - 1);
return JsonMaker.create()
.add("file", new PathResolver().getPathRelativeToProject(source))
.add("patches", diff.patch_toText(patches))
.add(
"full_document",
documentEvent.getNewLength() == documentEvent.getDocument().getTextLength())
.toString();
}
示例3: createEditor
import com.intellij.openapi.editor.event.DocumentEvent; //导入依赖的package包/类
private Editor createEditor() {
PsiFile myFile = null;
EditorFactory editorFactory = EditorFactory.getInstance();
Document doc = myFile == null
? editorFactory.createDocument("")
: PsiDocumentManager.getInstance(mProject).getDocument(myFile);
Editor editor = editorFactory.createEditor(doc, mProject);
EditorSettings editorSettings = editor.getSettings();
editorSettings.setVirtualSpace(false);
editorSettings.setLineMarkerAreaShown(false);
editorSettings.setIndentGuidesShown(false);
editorSettings.setFoldingOutlineShown(true);
editorSettings.setAdditionalColumnsCount(3);
editorSettings.setAdditionalLinesCount(3);
editorSettings.setLineNumbersShown(true);
editorSettings.setCaretRowShown(true);
editor.getDocument().addDocumentListener(new DocumentAdapter() {
@Override
public void documentChanged(DocumentEvent e) {
}
});
((EditorEx) editor).setHighlighter(createHighlighter(FileTypes.PLAIN_TEXT));
return editor;
}
示例4: processIfOnePoint
import com.intellij.openapi.editor.event.DocumentEvent; //导入依赖的package包/类
@Nullable
private static ProperTextRange processIfOnePoint(@NotNull DocumentEvent e, int intervalStart, int intervalEnd, boolean greedyRight) {
int offset = e.getOffset();
int oldLength = e.getOldLength();
int oldEnd = offset + oldLength;
if (offset < intervalStart && intervalStart < oldEnd) {
return null;
}
if (offset == intervalStart && oldLength == 0 && greedyRight) {
return new ProperTextRange(intervalStart, intervalEnd + e.getNewLength());
}
if (intervalStart > oldEnd || intervalStart == oldEnd && oldLength > 0) {
return new ProperTextRange(intervalStart + e.getNewLength() - oldLength, intervalEnd + e.getNewLength() - oldLength);
}
return new ProperTextRange(intervalStart, intervalEnd);
}
示例5: setupAutoStartDocumentListener
import com.intellij.openapi.editor.event.DocumentEvent; //导入依赖的package包/类
private void setupAutoStartDocumentListener(boolean enabled) {
final EditorEventMulticaster editorEventMulticaster = EditorFactory.getInstance().getEventMulticaster();
if (autoStartDocumentListener != null) {
editorEventMulticaster.removeDocumentListener(autoStartDocumentListener);
autoStartDocumentListener = null;
}
if (enabled) {
editorEventMulticaster.addDocumentListener(autoStartDocumentListener = new DocumentListener() {
@Override
public void documentChanged(DocumentEvent e) {
if (running) return;
//getSelectedTextEditor() must be run from event dispatch thread
EventQueue.invokeLater(() -> {
final Editor selectedTextEditor = FileEditorManager.getInstance(project).getSelectedTextEditor();
if (selectedTextEditor == null) return;
if(e.getDocument().equals(selectedTextEditor.getDocument())) {
setRunning(true);
}
});
}
});
}
}
示例6: setupPathComponent
import com.intellij.openapi.editor.event.DocumentEvent; //导入依赖的package包/类
private void setupPathComponent(final JPanel northPanel) {
northPanel.add(new TextFieldAction() {
@Override
public void linkSelected(LinkLabel aSource, Object aLinkData) {
toggleShowPathComponent(northPanel, this);
}
}, BorderLayout.EAST);
myPathEditor = new EditorTextField(JavaReferenceEditorUtil.createDocument("", myProject, false), myProject, StdFileTypes.JAVA);
myPathEditor.addDocumentListener(new DocumentAdapter() {
@Override
public void documentChanged(DocumentEvent e) {
myAlarm.cancelAllRequests();
myAlarm.addRequest(new Runnable() {
@Override
public void run() {
updateTreeFromPath();
}
}, 300);
}
});
myPathEditor.setBorder(BorderFactory.createEmptyBorder(0, 0, 2, 0));
northPanel.add(myPathEditor, BorderLayout.SOUTH);
}
示例7: SearchSupport
import com.intellij.openapi.editor.event.DocumentEvent; //导入依赖的package包/类
public SearchSupport(EditorTextField textField) {
myTextField = textField;
myTextField.getDocument().addDocumentListener(new DocumentAdapter() {
@Override
public void documentChanged(DocumentEvent event) {
onTextChanged();
}
});
//noinspection SSBasedInspection
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
myTextField.addKeyListener(new KeyAdapter() {
public void keyPressed(final KeyEvent e) {
processListSelection(e);
}
});
}
});
myList.setVisibleRowCount(10);
myListModel = new SortedListModel<T>(null);
myList.setModel(myListModel);
}
示例8: changedUpdateImpl
import com.intellij.openapi.editor.event.DocumentEvent; //导入依赖的package包/类
@Override
protected void changedUpdateImpl(@NotNull DocumentEvent e) {
// todo Denis Zhdanov
DocumentEventImpl event = (DocumentEventImpl)e;
final boolean shouldTranslateViaDiff = isValid() && PersistentRangeMarkerUtil.shouldTranslateViaDiff(event, this);
boolean wasTranslatedViaDiff = shouldTranslateViaDiff;
if (shouldTranslateViaDiff) {
wasTranslatedViaDiff = translatedViaDiff(e, event);
}
if (!wasTranslatedViaDiff) {
super.changedUpdateImpl(e);
if (isValid()) {
myLine = getDocument().getLineNumber(getStartOffset());
int endLine = getDocument().getLineNumber(getEndOffset());
if (endLine != myLine) {
setIntervalEnd(getDocument().getLineEndOffset(myLine));
}
}
}
if (isValid() && getTargetArea() == HighlighterTargetArea.LINES_IN_RANGE) {
setIntervalStart(DocumentUtil.getFirstNonSpaceCharOffset(getDocument(), myLine));
setIntervalEnd(getDocument().getLineEndOffset(myLine));
}
}
示例9: documentChanged
import com.intellij.openapi.editor.event.DocumentEvent; //导入依赖的package包/类
@Override
public void documentChanged(DocumentEvent event) {
Document document = event.getDocument();
FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
VirtualFile file = fileDocumentManager.getFile(document);
if (file == null) {
return;
}
String path = ExternalSystemApiUtil.getLocalFileSystemPath(file);
for (MyEntry entry : myAutoImportAware) {
if (entry.aware.getAffectedExternalProjectPath(path, myProject) != null) {
// Document save triggers VFS event but FileDocumentManager might be registered after the current listener, that's why
// call to 'saveDocument()' might not produce the desired effect. That's why we reschedule document save if necessary.
scheduleDocumentSave(document);
return;
}
}
}
示例10: applyChange
import com.intellij.openapi.editor.event.DocumentEvent; //导入依赖的package包/类
@Nullable
static Pair<ProperTextRange, LinesCols> applyChange(DocumentEvent event, Segment range, int intervalStart, int intervalEnd, boolean greedyLeft, boolean greedyRight, LinesCols linesCols) {
final boolean shouldTranslateViaDiff = PersistentRangeMarkerUtil.shouldTranslateViaDiff(event, range);
Pair<ProperTextRange, LinesCols> translated = null;
if (shouldTranslateViaDiff) {
translated = translateViaDiff((DocumentEventImpl)event, linesCols);
}
if (translated == null) {
ProperTextRange fallback = applyChange(event, intervalStart, intervalEnd, greedyLeft, greedyRight);
if (fallback == null) return null;
LinesCols lc = storeLinesAndCols(fallback, event.getDocument());
if (lc == null) return null;
translated = Pair.create(fallback, lc);
}
if (translated.first.getEndOffset() > event.getDocument().getTextLength() ||
translated.second.myEndLine < translated.second.myStartLine ||
translated.second.myStartLine == translated.second.myEndLine && translated.second.myEndColumn < translated.second.myStartColumn ||
event.getDocument().getLineCount() < translated.second.myEndLine) {
return null;
}
return translated;
}
示例11: documentChanged
import com.intellij.openapi.editor.event.DocumentEvent; //导入依赖的package包/类
@Override
public void documentChanged(DocumentEvent event) {
super.documentChanged(event);
// optimisation: avoid documents piling up during batch processing
if (FileDocumentManagerImpl.areTooManyDocumentsInTheQueue(myUncommittedDocuments)) {
if (myUnitTestMode) {
myStopTrackingDocuments = true;
try {
LOG.error("Too many uncommitted documents for " + myProject + ":\n" + StringUtil.join(myUncommittedDocuments, "\n") +
"\n\n Project creation trace: " + myProject.getUserData(ProjectImpl.CREATION_TRACE));
}
finally {
//noinspection TestOnlyProblems
clearUncommittedDocuments();
}
}
// must not commit during document save
if (PomModelImpl.isAllowPsiModification()) {
commitAllDocuments();
}
}
}
示例12: watchTail
import com.intellij.openapi.editor.event.DocumentEvent; //导入依赖的package包/类
private void watchTail(int offset) {
stopWatching();
tailWatcher = (RangeMarkerEx)getDocument().createRangeMarker(offset, offset);
if (!tailWatcher.isValid()) {
throw new AssertionError(getDocument() + "; offset=" + offset);
}
tailWatcher.setGreedyToRight(true);
spy = new RangeMarkerSpy(tailWatcher) {
@Override
protected void invalidated(DocumentEvent e) {
if (ApplicationManager.getApplication().isUnitTestMode()) {
LOG.error("Tail offset invalidated, say thanks to the "+ e);
}
if (invalidateTrace == null) {
invalidateTrace = DebugUtil.currentStackTrace();
killer = e;
}
}
};
getDocument().addDocumentListener(spy);
}
示例13: fixRanges
import com.intellij.openapi.editor.event.DocumentEvent; //导入依赖的package包/类
@NotNull
private int[] fixRanges(@NotNull DocumentEvent e, int line1, int line2) {
CharSequence document = myDocument.getCharsSequence();
int offset = e.getOffset();
if (e.getOldLength() == 0 && e.getNewLength() != 0) {
if (StringUtil.endsWithChar(e.getNewFragment(), '\n') && isNewline(offset - 1, document)) {
return new int[]{line1, line2 - 1};
}
if (StringUtil.startsWithChar(e.getNewFragment(), '\n') && isNewline(offset + e.getNewLength(), document)) {
return new int[]{line1 + 1, line2};
}
}
if (e.getOldLength() != 0 && e.getNewLength() == 0) {
if (StringUtil.endsWithChar(e.getOldFragment(), '\n') && isNewline(offset - 1, document)) {
return new int[]{line1, line2 - 1};
}
if (StringUtil.startsWithChar(e.getOldFragment(), '\n') && isNewline(offset + e.getNewLength(), document)) {
return new int[]{line1 + 1, line2};
}
}
return new int[]{line1, line2};
}
示例14: mergeChangesIfNecessary
import com.intellij.openapi.editor.event.DocumentEvent; //导入依赖的package包/类
private void mergeChangesIfNecessary(DocumentEvent event) {
// There is a possible case that we had more than one scattered change (e.g. (3; 5) and (8; 10)) and current document change affects
// both of them (e.g. remove all symbols from offset (4; 9)). We have two changes then: (3; 4) and (4; 5) and want to merge them
// into a single one.
if (myChanges.size() < 2) {
return;
}
TextChangeImpl next = myChanges.get(myChanges.size() - 1);
for (int i = myChanges.size() - 2; i >= 0; i--) {
TextChangeImpl current = myChanges.get(i);
if (current.getEnd() < event.getOffset()) {
// Assuming that change ranges are always kept at normalized form.
break;
}
if (current.getEnd() == next.getStart()) {
myChanges.set(i, next = new TextChangeImpl(current.getText().toString() + next.getText(), current.getStart(), next.getEnd()));
myChanges.remove(i + 1);
}
else {
next = current;
}
}
}
示例15: documentChanged
import com.intellij.openapi.editor.event.DocumentEvent; //导入依赖的package包/类
@Override
public void documentChanged(DocumentEvent event) {
final VirtualFile vf = myFileDocumentManager.getFile(event.getDocument());
if (vf != null) {
final FilePath filePath = myDiffDetails.getCurrentFilePath();
if (filePath != null && filePath.getVirtualFile() != null && filePath.getVirtualFile().equals(vf)) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
if (! updateSynchronously()) {
impl(vf);
}
}
});
} else {
impl(vf);
}
}
}