use of org.eclipse.core.filebuffers.ITextFileBuffer in project eclipse.platform.text by eclipse.
the class EditorAccessHighlighter method handleContentReplaced.
@Override
protected void handleContentReplaced(IFileBuffer buffer) {
if (!(buffer instanceof ITextFileBuffer))
return;
IDocument document = null;
ITextFileBuffer textBuffer = (ITextFileBuffer) buffer;
for (Match match : fMatchesToAnnotations.keySet()) {
document = fEditorAcess.getDocument(match);
if (document != null)
break;
}
if (document != null && document.equals(textBuffer.getDocument())) {
Match[] matches = new Match[fMatchesToAnnotations.keySet().size()];
fMatchesToAnnotations.keySet().toArray(matches);
removeAll();
addHighlights(matches);
}
}
use of org.eclipse.core.filebuffers.ITextFileBuffer in project eclipse.platform.text by eclipse.
the class PositionTracker method dirtyStateChanged.
@Override
public void dirtyStateChanged(IFileBuffer buffer, boolean isDirty) {
if (isDirty)
return;
final int[] trackCount = new int[1];
doForExistingMatchesIn(buffer, new IFileBufferMatchOperation() {
@Override
public void run(ITextFileBuffer textBuffer, Match match) {
trackCount[0]++;
Position pos = fMatchesToPositions.get(match);
if (pos != null) {
if (pos.isDeleted()) {
AbstractTextSearchResult result = fMatchesToSearchResults.get(match);
// might be that the containing element has been removed.
if (result != null) {
result.removeMatch(match);
}
untrackPosition(textBuffer, match);
} else {
if (match.getBaseUnit() == Match.UNIT_LINE) {
try {
pos = convertToLinePosition(pos, textBuffer.getDocument());
} catch (BadLocationException e) {
SearchPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, SearchPlugin.getID(), 0, e.getLocalizedMessage(), e));
}
}
match.setOffset(pos.getOffset());
match.setLength(pos.getLength());
}
}
}
});
}
use of org.eclipse.core.filebuffers.ITextFileBuffer in project eclipse.platform.text by eclipse.
the class PositionTracker method getCurrentPosition.
public Position getCurrentPosition(Match match) {
Position pos = fMatchesToPositions.get(match);
if (pos == null)
return pos;
AbstractTextSearchResult result = fMatchesToSearchResults.get(match);
if (match.getBaseUnit() == Match.UNIT_LINE && result != null) {
ITextFileBuffer fb = getTrackedFileBuffer(result, match.getElement());
if (fb != null) {
IDocument doc = fb.getDocument();
try {
pos = convertToLinePosition(pos, doc);
} catch (BadLocationException e) {
}
}
}
return pos;
}
use of org.eclipse.core.filebuffers.ITextFileBuffer in project eclipse.platform.text by eclipse.
the class PositionTracker method bufferCreated.
// IFileBufferListener implementation ---------------------------------------------------------------------
@Override
public void bufferCreated(IFileBuffer buffer) {
final int[] trackCount = new int[1];
if (!(buffer instanceof ITextFileBuffer))
return;
IPath location = buffer.getLocation();
if (location == null)
return;
IFile file = FileBuffers.getWorkspaceFileAtLocation(location);
if (file == null)
return;
ISearchQuery[] queries = NewSearchUI.getQueries();
for (ISearchQuery query : queries) {
ISearchResult result = query.getSearchResult();
if (result instanceof AbstractTextSearchResult) {
AbstractTextSearchResult textResult = (AbstractTextSearchResult) result;
IFileMatchAdapter adapter = textResult.getFileMatchAdapter();
if (adapter != null) {
Match[] matches = adapter.computeContainedMatches(textResult, file);
for (Match match : matches) {
trackCount[0]++;
trackPosition((AbstractTextSearchResult) result, (ITextFileBuffer) buffer, match);
}
}
}
}
}
use of org.eclipse.core.filebuffers.ITextFileBuffer in project eclipse.platform.text by eclipse.
the class TextSearchVisitor method getOpenDocument.
private IDocument getOpenDocument(IFile file, Map<IFile, IDocument> documentsInEditors) {
IDocument document = documentsInEditors.get(file);
if (document == null) {
ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager();
ITextFileBuffer textFileBuffer = bufferManager.getTextFileBuffer(file.getFullPath(), LocationKind.IFILE);
if (textFileBuffer != null) {
document = textFileBuffer.getDocument();
}
}
return document;
}
Aggregations