Search in sources :

Example 51 with ITextFileBuffer

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);
    }
}
Also used : ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IDocument(org.eclipse.jface.text.IDocument) Match(org.eclipse.search.ui.text.Match)

Example 52 with ITextFileBuffer

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());
                }
            }
        }
    });
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) Position(org.eclipse.jface.text.Position) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) AbstractTextSearchResult(org.eclipse.search.ui.text.AbstractTextSearchResult) BadLocationException(org.eclipse.jface.text.BadLocationException) Match(org.eclipse.search.ui.text.Match)

Example 53 with ITextFileBuffer

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;
}
Also used : Position(org.eclipse.jface.text.Position) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) AbstractTextSearchResult(org.eclipse.search.ui.text.AbstractTextSearchResult) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 54 with ITextFileBuffer

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);
                }
            }
        }
    }
}
Also used : ISearchResult(org.eclipse.search.ui.ISearchResult) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) IFileMatchAdapter(org.eclipse.search.ui.text.IFileMatchAdapter) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) AbstractTextSearchResult(org.eclipse.search.ui.text.AbstractTextSearchResult) ISearchQuery(org.eclipse.search.ui.ISearchQuery) Match(org.eclipse.search.ui.text.Match)

Example 55 with ITextFileBuffer

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;
}
Also used : ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IDocument(org.eclipse.jface.text.IDocument)

Aggregations

ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)133 Test (org.junit.Test)85 IDocument (org.eclipse.jface.text.IDocument)54 IFileBuffer (org.eclipse.core.filebuffers.IFileBuffer)37 ITextFileBufferManager (org.eclipse.core.filebuffers.ITextFileBufferManager)35 IPath (org.eclipse.core.runtime.IPath)31 IFile (org.eclipse.core.resources.IFile)18 BadLocationException (org.eclipse.jface.text.BadLocationException)15 IFileStore (org.eclipse.core.filesystem.IFileStore)9 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)9 CoreException (org.eclipse.core.runtime.CoreException)8 Position (org.eclipse.jface.text.Position)8 IFileInfo (org.eclipse.core.filesystem.IFileInfo)7 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)7 Match (org.eclipse.search.ui.text.Match)7 IFolder (org.eclipse.core.resources.IFolder)5 IStatus (org.eclipse.core.runtime.IStatus)5 Path (org.eclipse.core.runtime.Path)5 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)5 Status (org.eclipse.core.runtime.Status)4