Search in sources :

Example 1 with AbstractTextSearchResult

use of org.eclipse.search.ui.text.AbstractTextSearchResult in project eclipse.platform.text by eclipse.

the class RemoveMatchAction method run.

@Override
public void run() {
    Match match = fPage.getCurrentMatch();
    AbstractTextSearchResult result = fPage.getInput();
    if (match != null && result != null)
        result.removeMatch(match);
}
Also used : AbstractTextSearchResult(org.eclipse.search.ui.text.AbstractTextSearchResult) Match(org.eclipse.search.ui.text.Match)

Example 2 with AbstractTextSearchResult

use of org.eclipse.search.ui.text.AbstractTextSearchResult in project eclipse.platform.text by eclipse.

the class PositionTracker method queryRemoved.

@Override
public void queryRemoved(ISearchQuery query) {
    ISearchResult result = query.getSearchResult();
    if (result instanceof AbstractTextSearchResult) {
        untrackAll((AbstractTextSearchResult) result);
        result.removeListener(this);
    }
}
Also used : ISearchResult(org.eclipse.search.ui.ISearchResult) AbstractTextSearchResult(org.eclipse.search.ui.text.AbstractTextSearchResult)

Example 3 with AbstractTextSearchResult

use of org.eclipse.search.ui.text.AbstractTextSearchResult 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 4 with AbstractTextSearchResult

use of org.eclipse.search.ui.text.AbstractTextSearchResult 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 5 with AbstractTextSearchResult

use of org.eclipse.search.ui.text.AbstractTextSearchResult 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)

Aggregations

AbstractTextSearchResult (org.eclipse.search.ui.text.AbstractTextSearchResult)37 Test (org.junit.Test)20 Match (org.eclipse.search.ui.text.Match)19 ISearchQuery (org.eclipse.search.ui.ISearchQuery)11 IFile (org.eclipse.core.resources.IFile)6 Position (org.eclipse.jface.text.Position)6 Annotation (org.eclipse.jface.text.source.Annotation)5 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)5 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)5 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)4 IDocument (org.eclipse.jface.text.IDocument)4 ISearchResult (org.eclipse.search.ui.ISearchResult)4 MatchEvent (org.eclipse.search.ui.text.MatchEvent)4 ArrayList (java.util.ArrayList)3 StructuredViewer (org.eclipse.jface.viewers.StructuredViewer)3 Pattern (java.util.regex.Pattern)2 BadLocationException (org.eclipse.jface.text.BadLocationException)2 AbstractTreeViewer (org.eclipse.jface.viewers.AbstractTreeViewer)2 StyledString (org.eclipse.jface.viewers.StyledString)2 TableViewer (org.eclipse.jface.viewers.TableViewer)2