1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 00:45:28 +02:00

Fix for 58477 - Search UI does not work

Fix for 59077 - Selection Search does not work
This commit is contained in:
Bogdan Gheorghe 2004-04-20 03:53:00 +00:00
parent 97a3c316c8
commit 977904112c
12 changed files with 573 additions and 56 deletions

View file

@ -1,3 +1,18 @@
2004-04-19 Bogdan Gheorghe
Fix for 58477 - Search UI does not work
Fix for 59077 - Selection Search does not work
* src/org/eclipse/cdt/internal/ui/search/CSearchContentProvider.java
* src/org/eclipse/cdt/internal/ui/search/CSearchPage.java
* src/org/eclipse/cdt/internal/ui/search/CSearchQuery.java
* src/org/eclipse/cdt/internal/ui/search/CSearchResultCollector.java
* src/org/eclipse/cdt/internal/ui/search/CSearchResultPage.java
* src/org/eclipse/cdt/internal/ui/search/CSearchTableContentProvider.java
* src/org/eclipse/cdt/internal/ui/search/LevelTreeContentProvider.java
* src/org/eclipse/cdt/internal/ui/search/NewSearchResultCollector.java
* src/org/eclipse/cdt/internal/ui/search/FindAction.java
* src/org/eclipse/cdt/internal/ui/search/CSearchResultLabelProvider.java
2004-04-19 Alain Magloire
The Core Model interfaces now is throwing CModelException

View file

@ -615,6 +615,14 @@
id="org.eclipse.cdt.ui.preferneces.WorkInProgressPreferencePage">
</page>
</extension>
<extension
point="org.eclipse.search.searchResultViewPages">
<viewPage
targetClass="org.eclipse.cdt.internal.ui.search.CSearchResult"
class="org.eclipse.cdt.internal.ui.search.CSearchResultPage"
id="org.eclipse.cdt.ui.CSearchResultPage">
</viewPage>
</extension>
<!--
<extension
point="org.eclipse.ui.propertyPages">

View file

@ -0,0 +1,40 @@
/*******************************************************************************
* Copyright (c) 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* IBM Corp. - Rational Software - initial implementation
******************************************************************************/
package org.eclipse.cdt.internal.ui.search;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.Viewer;
public abstract class CSearchContentProvider implements IStructuredContentProvider {
protected CSearchResult _result;
protected final Object[] EMPTY_ARR= new Object[0];
public Object[] getElements(Object inputElement) {
// TODO Auto-generated method stub
return null;
}
public void dispose() {
// TODO Auto-generated method stub
}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
initialize((CSearchResult) newInput);
}
protected void initialize(CSearchResult result) {
_result= result;
}
public abstract void elementsChanged(Object[] updatedElements);
public abstract void clear();
}

View file

@ -16,13 +16,11 @@ package org.eclipse.cdt.internal.ui.search;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.search.ICSearchConstants;
import org.eclipse.cdt.core.search.ICSearchScope;
@ -44,7 +42,6 @@ import org.eclipse.search.ui.ISearchPage;
import org.eclipse.search.ui.ISearchPageContainer;
import org.eclipse.search.ui.ISearchResultViewEntry;
import org.eclipse.search.ui.NewSearchUI;
import org.eclipse.search.ui.SearchUI;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
@ -77,8 +74,7 @@ public class CSearchPage extends DialogPage implements ISearchPage, ICSearchCons
public static final String EXTENSION_POINT_ID= "org.eclipse.cdt.ui.CSearchPage"; //$NON-NLS-1$
public boolean performAction() {
SearchUI.activateSearchResultView();
SearchPatternData data = getPatternData();
IWorkspace workspace = CUIPlugin.getWorkspace();
@ -109,8 +105,6 @@ public class CSearchPage extends DialogPage implements ISearchPage, ICSearchCons
data.cElement= null;
CSearchResultCollector collector= new CSearchResultCollector();
List searching = null;
if( data.searchFor.contains( UNKNOWN_SEARCH_FOR ) ){
@ -126,25 +120,10 @@ public class CSearchPage extends DialogPage implements ISearchPage, ICSearchCons
} else {
searching = data.searchFor;
}
//TODO: Remove
/*
CSearchOperation op = new CSearchOperation(workspace, data.pattern, data.isCaseSensitive, searching, data.limitTo, scope, scopeDescription, collector);
CSearchQuery job = new CSearchQuery(workspace, data.pattern, data.isCaseSensitive, searching, data.limitTo, scope, scopeDescription, null);
NewSearchUI.activateSearchResultView();
try {
getContainer().getRunnableContext().run(true, true, op);
} catch (InvocationTargetException ex) {
Shell shell = getControl().getShell();
//ExceptionHandler.handle(ex, shell, CSearchMessages.getString("Search.Error.search.title"), CSearchMessages.getString("Search.Error.search.message")); //$NON-NLS-2$ //$NON-NLS-1$
return false;
} catch (InterruptedException ex) {
return false;
}
*/
CSearchQuery job = new CSearchQuery(workspace, data.pattern, data.isCaseSensitive, searching, data.limitTo, scope, scopeDescription, collector);
//NewSearchUI.activateSearchResultView();
CSearchResult result = new CSearchResult(job);
NewSearchUI.runQuery(job);
return true;

View file

@ -1,3 +1,13 @@
/*******************************************************************************
* Copyright (c) 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* IBM Corp. - Rational Software - initial implementation
******************************************************************************/
/*
* Created on Mar 26, 2004
*
@ -8,7 +18,6 @@ package org.eclipse.cdt.internal.ui.search;
import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.core.search.ICSearchConstants;
import org.eclipse.cdt.core.search.ICSearchPattern;
import org.eclipse.cdt.core.search.ICSearchScope;
@ -20,6 +29,7 @@ import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.search.ui.ISearchQuery;
import org.eclipse.search.ui.ISearchResult;
@ -39,7 +49,8 @@ public class CSearchQuery implements ISearchQuery, ICSearchConstants {
private boolean _caseSensitive;
private LimitTo _limitTo;
private List _searchFor;
private CSearchResult _result;
public CSearchQuery(IWorkspace workspace, String pattern, boolean caseSensitive, List searchFor, LimitTo limitTo, ICSearchScope scope, String scopeDescription, CSearchResultCollector collector) {
this( workspace, limitTo, scope, scopeDescription, collector );
_stringPattern = pattern;
@ -53,7 +64,8 @@ public class CSearchQuery implements ISearchQuery, ICSearchConstants {
_scope = scope;
_scopeDescription = scopeDescription;
_collector = collector;
_collector.setOperation( this );
if (_collector != null)
_collector.setOperation( this );
}
/**
@ -116,9 +128,20 @@ public class CSearchQuery implements ISearchQuery, ICSearchConstants {
* @see org.eclipse.search.ui.ISearchQuery#run(org.eclipse.core.runtime.IProgressMonitor)
*/
public IStatus run(IProgressMonitor monitor) {
_collector.setProgressMonitor( monitor );
final CSearchResult textResult= (CSearchResult) getSearchResult();
textResult.removeAll();
SearchEngine engine = new SearchEngine( CUIPlugin.getSharedWorkingCopies() );
int matchCount= 0;
int totalTicks= 1000;
monitor.beginTask("", totalTicks); //$NON-NLS-1$
IProgressMonitor mainSearchPM= new SubProgressMonitor(monitor, 1000);
NewSearchResultCollector finalCollector= new NewSearchResultCollector(textResult, mainSearchPM);
ICSearchPattern pattern = null;
if( _searchFor.size() > 1 ){
@ -136,11 +159,13 @@ public class CSearchQuery implements ISearchQuery, ICSearchConstants {
}
try {
engine.search( _workspace, pattern, _scope, _collector, false );
engine.search( _workspace, pattern, _scope, finalCollector, false );
} catch (InterruptedException e) {
}
return new Status(IStatus.OK, CUIPlugin.getPluginId(),0,"",null); //$NON-NLS-1$
matchCount = finalCollector.getMatchCount();
return new Status(IStatus.OK, CUIPlugin.getPluginId(), 0,"", null); //$NON-NLS-1$
}
/* (non-Javadoc)
@ -163,7 +188,7 @@ public class CSearchQuery implements ISearchQuery, ICSearchConstants {
* @see org.eclipse.search.ui.ISearchQuery#canRerun()
*/
public boolean canRerun() {
return false;
return true;
}
/* (non-Javadoc)
@ -177,7 +202,10 @@ public class CSearchQuery implements ISearchQuery, ICSearchConstants {
* @see org.eclipse.search.ui.ISearchQuery#getSearchResult()
*/
public ISearchResult getSearchResult() {
// TODO Auto-generated method stub
return null;
if (_result == null)
_result= new CSearchResult(this);
return _result;
}
}

View file

@ -60,7 +60,7 @@ public class CSearchResultCollector extends BasicSearchResultCollector{
_matchCount = 0;
_view = SearchUI.getSearchResultView();
//_view = NewSearchUI.getSearchResultView();
CSearchResultLabelProvider labelProvider = new CSearchResultLabelProvider();
@ -180,7 +180,7 @@ public class CSearchResultCollector extends BasicSearchResultCollector{
* @see org.eclipse.cdt.core.search.ICSearchResultCollector#done()
*/
public void done() {
if( !getProgressMonitor().isCanceled() ){
/* if( !getProgressMonitor().isCanceled() ){
String matchesString;
if( _matchCount == 1 ){
matchesString = MATCH;
@ -196,7 +196,7 @@ public class CSearchResultCollector extends BasicSearchResultCollector{
}
_view = null;
_monitor = null;
_monitor = null;*/
}
/* (non-Javadoc)

View file

@ -0,0 +1,121 @@
/*******************************************************************************
* Copyright (c) 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* IBM Corp. - Rational Software - initial implementation
******************************************************************************/
package org.eclipse.cdt.internal.ui.search;
import java.util.HashMap;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.search.BasicSearchMatch;
import org.eclipse.cdt.internal.ui.util.EditorUtility;
import org.eclipse.cdt.ui.CSearchResultLabelProvider;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.search.internal.ui.text.DelegatingLabelProvider;
import org.eclipse.search.ui.SearchUI;
import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
import org.eclipse.search.ui.text.Match;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.texteditor.ITextEditor;
public class CSearchResultPage extends AbstractTextSearchViewPage {
private CSearchContentProvider _contentProvider;
private int _currentSortOrder;
private int _currentGrouping;
/* (non-Javadoc)
* @see org.eclipse.search.ui.text.AbstractTextSearchViewPage#showMatch(org.eclipse.search.ui.text.Match, int, int)
*/
protected void showMatch(Match match, int currentOffset, int currentLength)
throws PartInitException {
// TODO Auto-generated method stub
IEditorPart editor= null;
Object element= match.getElement();
if (element instanceof ICElement) {
ICElement cElement= (ICElement) element;
try {
editor= EditorUtility.openInEditor(cElement, false);
} catch (PartInitException e1) {
return;
} catch (CModelException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (element instanceof IFile) {
editor= IDE.openEditor(CUIPlugin.getActivePage(), (IFile) element, false);
} else if (element instanceof BasicSearchMatch){
BasicSearchMatch x = (BasicSearchMatch) element;
editor = IDE.openEditor(CUIPlugin.getActivePage(), (IFile) x.resource, false);
showWithMarker(editor, (IFile) x.resource, currentOffset, currentLength);
}
if (editor instanceof ITextEditor) {
ITextEditor textEditor= (ITextEditor) editor;
textEditor.selectAndReveal(currentOffset, currentLength);
} else if (editor != null){
if (element instanceof IFile) {
IFile file= (IFile) element;
showWithMarker(editor, file, currentOffset, currentLength);
}
}
}
/* (non-Javadoc)
* @see org.eclipse.search.ui.text.AbstractTextSearchViewPage#elementsChanged(java.lang.Object[])
*/
protected void elementsChanged(Object[] objects) {
// TODO Auto-generated method stub
if (_contentProvider != null)
_contentProvider.elementsChanged(objects);
}
/* (non-Javadoc)
* @see org.eclipse.search.ui.text.AbstractTextSearchViewPage#clear()
*/
protected void clear() {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see org.eclipse.search.ui.text.AbstractTextSearchViewPage#configureTreeViewer(org.eclipse.jface.viewers.TreeViewer)
*/
protected void configureTreeViewer(TreeViewer viewer) {
//viewer.setSorter(new ViewerSorter());
viewer.setLabelProvider(new CSearchResultLabelProvider());
_contentProvider= new LevelTreeContentProvider(viewer, _currentGrouping);
viewer.setContentProvider(_contentProvider);
}
/* (non-Javadoc)
* @see org.eclipse.search.ui.text.AbstractTextSearchViewPage#configureTableViewer(org.eclipse.jface.viewers.TableViewer)
*/
protected void configureTableViewer(TableViewer viewer) {
viewer.setLabelProvider(new DelegatingLabelProvider(this, new CSearchResultLabelProvider()));
_contentProvider=new CSearchTableContentProvider(viewer);
viewer.setContentProvider(_contentProvider);
//setSortOrder(_currentSortOrder);
}
private void showWithMarker(IEditorPart editor, IFile file, int offset, int length) throws PartInitException {
try {
IMarker marker= file.createMarker(SearchUI.SEARCH_MARKER);
HashMap attributes= new HashMap(4);
attributes.put(IMarker.CHAR_START, new Integer(offset));
attributes.put(IMarker.CHAR_END, new Integer(offset + length));
marker.setAttributes(attributes);
IDE.gotoMarker(editor, marker);
marker.delete();
} catch (CoreException e) {
throw new PartInitException("Search Result Error", e); //$NON-NLS-1$
}
}
}

View file

@ -0,0 +1,50 @@
/*******************************************************************************
* Copyright (c) 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* IBM Corp. - Rational Software - initial implementation
******************************************************************************/
package org.eclipse.cdt.internal.ui.search;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.TableViewer;
public class CSearchTableContentProvider extends CSearchContentProvider implements IStructuredContentProvider {
private TableViewer _tableViewer;
public CSearchTableContentProvider(TableViewer viewer) {
_tableViewer= viewer;
}
public Object[] getElements(Object inputElement) {
if (inputElement instanceof CSearchResult)
return ((CSearchResult)inputElement).getElements();
return EMPTY_ARR;
}
public void elementsChanged(Object[] updatedElements) {
int addCount= 0;
int removeCount= 0;
for (int i= 0; i < updatedElements.length; i++) {
if (_result.getMatchCount(updatedElements[i]) > 0) {
if (_tableViewer.testFindItem(updatedElements[i]) != null)
_tableViewer.refresh(updatedElements[i]);
else
_tableViewer.add(updatedElements[i]);
addCount++;
} else {
_tableViewer.remove(updatedElements[i]);
removeCount++;
}
}
}
public void clear() {
_tableViewer.refresh();
}
}

View file

@ -0,0 +1,206 @@
/*******************************************************************************
* Copyright (c) 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* IBM Corp. - Rational Software - initial implementation
******************************************************************************/
package org.eclipse.cdt.internal.ui.search;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.search.BasicSearchMatch;
import org.eclipse.cdt.ui.CElementContentProvider;
import org.eclipse.core.resources.IResource;
import org.eclipse.jface.viewers.AbstractTreeViewer;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.swt.widgets.Control;
public class LevelTreeContentProvider extends CSearchContentProvider implements ITreeContentProvider {
private AbstractTreeViewer fTreeViewer;
private Map fChildrenMap;
private CElementContentProvider fContentProvider;
private static int[][] C_ELEMENT_TYPES= {{ICElement.C_ENUMERATION},
{ICElement.C_STRUCT, ICElement.C_CLASS},{ICElement.C_UNIT},{ICElement.C_PROJECT}};
private static int[][] RESOURCE_TYPES= {
{},
{IResource.FILE},
{IResource.FOLDER},
{IResource.PROJECT},
{IResource.ROOT}};
private static final int MAX_LEVEL= C_ELEMENT_TYPES.length - 1;
private int fCurrentLevel;
static class FastCElementProvider extends CElementContentProvider {
public Object getParent(Object element) {
return internalGetParent(element);
}
}
public LevelTreeContentProvider(AbstractTreeViewer viewer, int level) {
fTreeViewer= viewer;
fCurrentLevel= level;
fContentProvider= new FastCElementProvider();
}
public Object getParent(Object child) {
BasicSearchMatch tempMatch = (BasicSearchMatch)child;
child = CCorePlugin.getDefault().getCoreModel().create(tempMatch.getResource());
Object possibleParent= internalGetParent(child);
if (possibleParent instanceof ICElement) {
ICElement javaElement= (ICElement) possibleParent;
for (int j= fCurrentLevel; j < MAX_LEVEL + 1; j++) {
for (int i= 0; i < C_ELEMENT_TYPES[j].length; i++) {
if (javaElement.getElementType() == C_ELEMENT_TYPES[j][i]) {
return null;
}
}
}
} else if (possibleParent instanceof IResource) {
IResource resource= (IResource) possibleParent;
for (int j= fCurrentLevel; j < MAX_LEVEL + 1; j++) {
for (int i= 0; i < RESOURCE_TYPES[j].length; i++) {
if (resource.getType() == RESOURCE_TYPES[j][i]) {
return null;
}
}
}
}
return possibleParent;
}
private Object internalGetParent(Object child) {
return fContentProvider.getParent(child);
}
public Object[] getElements(Object inputElement) {
return getChildren(inputElement);
}
protected synchronized void initialize(CSearchResult result) {
super.initialize(result);
fChildrenMap= new HashMap();
if (result != null) {
Object[] elements= result.getElements();
for (int i= 0; i < elements.length; i++) {
insert(elements[i], false);
}
}
}
protected void insert(Object child, boolean refreshViewer) {
Object parent= getParent(child);
while (parent != null) {
if (insertChild(parent, child)) {
if (refreshViewer)
fTreeViewer.add(parent, child);
} else {
if (refreshViewer)
fTreeViewer.refresh(parent);
return;
}
child= parent;
parent= getParent(child);
}
if (insertChild(_result, child)) {
if (refreshViewer)
fTreeViewer.add(_result, child);
}
}
/**
* returns true if the child already was a child of parent.
*
* @param parent
* @param child
* @return
*/
private boolean insertChild(Object parent, Object child) {
Set children= (Set) fChildrenMap.get(parent);
if (children == null) {
children= new HashSet();
fChildrenMap.put(parent, children);
}
return children.add(child);
}
protected void remove(Object element, boolean refreshViewer) {
// precondition here: _result.getMatchCount(child) <= 0
if (hasChildren(element)) {
if (refreshViewer)
fTreeViewer.refresh(element);
} else {
if (_result.getMatchCount(element) == 0) {
fChildrenMap.remove(element);
Object parent= getParent(element);
if (parent != null) {
removeFromSiblings(element, parent);
remove(parent, refreshViewer);
} else {
removeFromSiblings(element, _result);
if (refreshViewer)
fTreeViewer.refresh();
}
} else {
if (refreshViewer) {
fTreeViewer.refresh(element);
}
}
}
}
private void removeFromSiblings(Object element, Object parent) {
Set siblings= (Set) fChildrenMap.get(parent);
if (siblings != null) {
siblings.remove(element);
}
}
public Object[] getChildren(Object parentElement) {
Set children= (Set) fChildrenMap.get(parentElement);
if (children == null)
return EMPTY_ARR;
return children.toArray();
}
public boolean hasChildren(Object element) {
return getChildren(element).length > 0;
}
public synchronized void elementsChanged(Object[] updatedElements) {
if (_result == null)
return;
for (int i= 0; i < updatedElements.length; i++) {
if (_result.getMatchCount(updatedElements[i]) > 0)
insert(updatedElements[i], true);
else
remove(updatedElements[i], true);
}
}
public void clear() {
initialize(_result);
fTreeViewer.refresh();
}
public void setLevel(int level) {
fCurrentLevel= level;
Control control= fTreeViewer.getControl();
if (control != null)
control.setRedraw(false);
initialize(_result);
fTreeViewer.refresh();
if (control != null)
control.setRedraw(true);
}
}

View file

@ -0,0 +1,72 @@
/*******************************************************************************
* Copyright (c) 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* IBM Corp. - Rational Software - initial implementation
******************************************************************************/
package org.eclipse.cdt.internal.ui.search;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
import org.eclipse.cdt.core.search.BasicSearchResultCollector;
import org.eclipse.cdt.core.search.IMatch;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.search.ui.text.Match;
public class NewSearchResultCollector extends BasicSearchResultCollector {
private CSearchResult fSearch;
private IProgressMonitor fProgressMonitor;
private int fMatchCount;
public NewSearchResultCollector(CSearchResult search, IProgressMonitor monitor) {
super();
fSearch= search;
fProgressMonitor= monitor;
fMatchCount = 0;
}
public void accept(IResource resource, int start, int end, ICElement enclosingElement, int accuracy) {
fMatchCount++;
fSearch.addMatch(new Match(enclosingElement, start, end-start));
}
public void done() {
}
public IProgressMonitor getProgressMonitor() {
return fProgressMonitor;
}
public int getMatchCount() {
return fMatchCount;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.search.ICSearchResultCollector#acceptMatch(org.eclipse.cdt.core.search.IMatch)
*/
public boolean acceptMatch(IMatch match) throws CoreException {
if (super.acceptMatch(match)){
fMatchCount++;
int start = match.getStartOffset();
int end = match.getEndOffset();
fSearch.addMatch(new Match(match,start,end-start));
return true;
}
return false;
}
}

View file

@ -15,7 +15,6 @@ import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.ICLogConstants;
import org.eclipse.cdt.core.model.CoreModel;
@ -48,6 +47,7 @@ import org.eclipse.cdt.core.search.ICSearchConstants.SearchFor;
import org.eclipse.cdt.internal.ui.editor.CEditor;
import org.eclipse.cdt.internal.ui.search.CSearchMessages;
import org.eclipse.cdt.internal.ui.search.CSearchOperation;
import org.eclipse.cdt.internal.ui.search.CSearchQuery;
import org.eclipse.cdt.internal.ui.search.CSearchResultCollector;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.resources.IFile;
@ -58,6 +58,7 @@ import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.search.ui.NewSearchUI;
import org.eclipse.search.ui.SearchUI;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchSite;
@ -113,8 +114,8 @@ public abstract class FindAction extends Action {
/**
* @param node
*/
protected CSearchOperation createSearchOperation(String pattern, SearchFor searchFor) {
CSearchOperation op = null;
protected CSearchQuery createSearchQuery(String pattern, SearchFor searchFor) {
CSearchQuery op = null;
ICSearchScope scope = getScope();
String scopeDescription = getScopeDescription();
@ -126,7 +127,7 @@ public abstract class FindAction extends Action {
LimitTo limitTo = getLimitTo();
op = new CSearchOperation(CCorePlugin.getWorkspace(), pattern,true,search,limitTo,scope,scopeDescription,collector);
op = new CSearchQuery(CCorePlugin.getWorkspace(), pattern,true,search,limitTo,scope,scopeDescription,collector);
return op;
}
@ -199,10 +200,11 @@ public abstract class FindAction extends Action {
operationNotAvailableDialog();
return;
}
CSearchQuery job = createSearchQuery(selectedText.getText(),getSearchForFromNode(node));
NewSearchUI.activateSearchResultView();
CSearchOperation op = createSearchOperation(selectedText.getText(),getSearchForFromNode(node));
performSearch(op);
NewSearchUI.runQuery(job);
}
private SearchFor getSearchForFromNode(IASTNode node){
@ -246,18 +248,6 @@ public abstract class FindAction extends Action {
return searchFor;
}
protected void performSearch(CSearchOperation op){
try {
SearchUI.activateSearchResultView();
ProgressMonitorDialog progressMonitor = new ProgressMonitorDialog(fSite.getShell());
progressMonitor.run(true, true, op);
} catch(Exception x) {
CUIPlugin.getDefault().log(x);
}
}
private void operationNotAvailableDialog(){
MessageDialog.openInformation(fEditor.getSite().getShell(),CSearchMessages.getString("CSearchOperation.operationUnavailable.title"), CSearchMessages.getString("CSearchOperation.operationUnavailable.message")); //$NON-NLS-1$ //$NON-NLS-2$
}

View file

@ -18,6 +18,7 @@ import org.eclipse.cdt.core.search.IMatch;
import org.eclipse.cdt.internal.ui.CPluginImages;
import org.eclipse.cdt.internal.ui.search.CSearchMessages;
import org.eclipse.cdt.internal.ui.search.CSearchResultCollector;
import org.eclipse.cdt.internal.ui.search.CSearchResultPage;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
@ -46,6 +47,14 @@ public class CSearchResultLabelProvider extends LabelProvider {
_sortOrder = SHOW_PATH;
}
/**
* @param page
*/
public CSearchResultLabelProvider(CSearchResultPage page) {
// TODO Auto-generated constructor stub
}
public Image getImage( Object element ) {
IMatch match = null;
@ -167,5 +176,4 @@ public class CSearchResultLabelProvider extends LabelProvider {
private int _imageFlags;
private static final Point SMALL_SIZE= new Point(16, 16);
}