mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Added background search from CSearchPage
This commit is contained in:
parent
58513148c2
commit
de01048e51
6 changed files with 349 additions and 14 deletions
|
@ -85,9 +85,8 @@ public class TimeOut implements Runnable {
|
||||||
|
|
||||||
|
|
||||||
public void reset() {
|
public void reset() {
|
||||||
System.out.println("TimeOut reset");
|
|
||||||
enabled=false;
|
enabled=false;
|
||||||
thread = new Thread(this, "Time Out Thread");
|
thread = new Thread(this, "Time Out Thread"); //$NON-NLS-1$
|
||||||
thread.setDaemon(true);
|
thread.setDaemon(true);
|
||||||
thread.setPriority(threadPriority);
|
thread.setPriority(threadPriority);
|
||||||
thread.start();
|
thread.start();
|
||||||
|
|
|
@ -1,3 +1,15 @@
|
||||||
|
2004-03-28 Bogdan Gheorghe
|
||||||
|
Modified CSearchPage to use new CSearchQuery (which uses the new background
|
||||||
|
jobs API)
|
||||||
|
|
||||||
|
Modified CSearchResultCollector to use CSearchQuery if present (ie. if invoked
|
||||||
|
from the CSearchPage)
|
||||||
|
|
||||||
|
* src/org/eclipse/cdt/internal/ui/search/CSearchResultCollector.java
|
||||||
|
* src/org/eclipse/cdt/internal/ui/search/CSearchPage.java
|
||||||
|
* src/org/eclipse/cdt/internal/ui/search/CSearchResult.java
|
||||||
|
* src/org/eclipse/cdt/internal/ui/search/CSearchQuery.java
|
||||||
|
|
||||||
2004-03-28 Alain Magloire
|
2004-03-28 Alain Magloire
|
||||||
|
|
||||||
Provide a global hook for the action "Show Selected element"
|
Provide a global hook for the action "Show Selected element"
|
||||||
|
|
|
@ -43,6 +43,7 @@ import org.eclipse.search.internal.ui.util.RowLayouter;
|
||||||
import org.eclipse.search.ui.ISearchPage;
|
import org.eclipse.search.ui.ISearchPage;
|
||||||
import org.eclipse.search.ui.ISearchPageContainer;
|
import org.eclipse.search.ui.ISearchPageContainer;
|
||||||
import org.eclipse.search.ui.ISearchResultViewEntry;
|
import org.eclipse.search.ui.ISearchResultViewEntry;
|
||||||
|
import org.eclipse.search.ui.NewSearchUI;
|
||||||
import org.eclipse.search.ui.SearchUI;
|
import org.eclipse.search.ui.SearchUI;
|
||||||
import org.eclipse.swt.SWT;
|
import org.eclipse.swt.SWT;
|
||||||
import org.eclipse.swt.events.ModifyEvent;
|
import org.eclipse.swt.events.ModifyEvent;
|
||||||
|
@ -126,7 +127,8 @@ public class CSearchPage extends DialogPage implements ISearchPage, ICSearchCons
|
||||||
} else {
|
} else {
|
||||||
searching = data.searchFor;
|
searching = data.searchFor;
|
||||||
}
|
}
|
||||||
|
//TODO: Remove
|
||||||
|
/*
|
||||||
CSearchOperation op = new CSearchOperation(workspace, data.pattern, data.isCaseSensitive, searching, data.limitTo, scope, scopeDescription, collector);
|
CSearchOperation op = new CSearchOperation(workspace, data.pattern, data.isCaseSensitive, searching, data.limitTo, scope, scopeDescription, collector);
|
||||||
|
|
||||||
|
|
||||||
|
@ -139,6 +141,13 @@ public class CSearchPage extends DialogPage implements ISearchPage, ICSearchCons
|
||||||
} catch (InterruptedException ex) {
|
} catch (InterruptedException ex) {
|
||||||
return false;
|
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.runSearchInBackground(job, result);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,152 @@
|
||||||
|
/*
|
||||||
|
* Created on Mar 26, 2004
|
||||||
|
*
|
||||||
|
* To change the template for this generated file go to
|
||||||
|
* Window - Preferences - Java - Code Generation - Code and Comments
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
import org.eclipse.cdt.core.search.OrPattern;
|
||||||
|
import org.eclipse.cdt.core.search.SearchEngine;
|
||||||
|
import org.eclipse.cdt.internal.ui.CPluginImages;
|
||||||
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
|
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.jface.resource.ImageDescriptor;
|
||||||
|
import org.eclipse.search.ui.ISearchQuery;
|
||||||
|
import org.eclipse.search.ui.ISearchResult;
|
||||||
|
/**
|
||||||
|
* @author bog
|
||||||
|
*
|
||||||
|
* To change the template for this generated type comment go to
|
||||||
|
* Window - Preferences - Java - Code Generation - Code and Comments
|
||||||
|
*/
|
||||||
|
public class CSearchQuery implements ISearchQuery, ICSearchConstants {
|
||||||
|
|
||||||
|
private CSearchResultCollector _collector;
|
||||||
|
private IWorkspace _workspace;
|
||||||
|
private ICSearchScope _scope;
|
||||||
|
private String _stringPattern;
|
||||||
|
private String _scopeDescription;
|
||||||
|
private boolean _caseSensitive;
|
||||||
|
private LimitTo _limitTo;
|
||||||
|
private List _searchFor;
|
||||||
|
|
||||||
|
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;
|
||||||
|
_caseSensitive = caseSensitive;
|
||||||
|
_searchFor = searchFor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CSearchQuery(IWorkspace workspace, LimitTo limitTo, ICSearchScope scope, String scopeDescription, CSearchResultCollector collector ){
|
||||||
|
_workspace = workspace;
|
||||||
|
_limitTo = limitTo;
|
||||||
|
_scope = scope;
|
||||||
|
_scopeDescription = scopeDescription;
|
||||||
|
_collector = collector;
|
||||||
|
_collector.setOperation( this );
|
||||||
|
}
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.search.ui.ISearchQuery#run(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.search.ui.ISearchResult)
|
||||||
|
*/
|
||||||
|
public IStatus run(IProgressMonitor monitor, ISearchResult result) {
|
||||||
|
_collector.setProgressMonitor( monitor );
|
||||||
|
|
||||||
|
SearchEngine engine = new SearchEngine( CUIPlugin.getSharedWorkingCopies() );
|
||||||
|
|
||||||
|
ICSearchPattern pattern = null;
|
||||||
|
if( _searchFor.size() > 1 ){
|
||||||
|
OrPattern orPattern = new OrPattern();
|
||||||
|
for (Iterator iter = _searchFor.iterator(); iter.hasNext();) {
|
||||||
|
SearchFor element = (SearchFor)iter.next();
|
||||||
|
orPattern.addPattern( SearchEngine.createSearchPattern( _stringPattern, element, _limitTo, _caseSensitive ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
pattern = orPattern;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
Iterator iter = _searchFor.iterator();
|
||||||
|
pattern = SearchEngine.createSearchPattern( _stringPattern, (SearchFor)iter.next(), _limitTo, _caseSensitive );
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
engine.search( _workspace, pattern, _scope, _collector, false );
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Status(IStatus.OK, CUIPlugin.getPluginId(),0,"",null); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.search.ui.ISearchQuery#getName()
|
||||||
|
*/
|
||||||
|
public String getName() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return "CDT Search Job"; //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getSingularLabel() {
|
||||||
|
String desc = null;
|
||||||
|
|
||||||
|
//if( _elementPattern != null ){
|
||||||
|
// desc = _elementPattern.getElementName();
|
||||||
|
//} else {
|
||||||
|
desc = _stringPattern;
|
||||||
|
//}
|
||||||
|
|
||||||
|
String [] args = new String [] { desc, _scopeDescription };
|
||||||
|
|
||||||
|
if( _limitTo == DECLARATIONS ){
|
||||||
|
return CSearchMessages.getFormattedString( "CSearchOperation.singularDeclarationsPostfix", args ); //$NON_NLS-1$ //$NON-NLS-1$
|
||||||
|
} else if( _limitTo == REFERENCES ){
|
||||||
|
return CSearchMessages.getFormattedString( "CSearchOperation.singularReferencesPostfix", args ); //$NON_NLS-1$ //$NON-NLS-1$
|
||||||
|
} else {
|
||||||
|
return CSearchMessages.getFormattedString( "CSearchOperation.singularOccurrencesPostfix", args ); //$NON_NLS-1$ //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getPluralLabelPattern() {
|
||||||
|
String desc = null;
|
||||||
|
|
||||||
|
// if( _elementPattern != null ){
|
||||||
|
// desc = _elementPattern.getElementName();
|
||||||
|
// } else {
|
||||||
|
desc = _stringPattern;
|
||||||
|
// }
|
||||||
|
|
||||||
|
String [] args = new String [] { desc, "{0}", _scopeDescription }; //$NON-NLS-1$
|
||||||
|
if( _limitTo == DECLARATIONS ){
|
||||||
|
return CSearchMessages.getFormattedString( "CSearchOperation.pluralDeclarationsPostfix", args ); //$NON_NLS-1$ //$NON-NLS-1$
|
||||||
|
} else if ( _limitTo == REFERENCES ){
|
||||||
|
return CSearchMessages.getFormattedString( "CSearchOperation.pluralReferencesPostfix", args ); //$NON_NLS-1$ //$NON-NLS-1$
|
||||||
|
} else {
|
||||||
|
return CSearchMessages.getFormattedString( "CSearchOperation.pluralOccurrencesPostfix", args ); //$NON_NLS-1$ //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public ImageDescriptor getImageDescriptor() {
|
||||||
|
if( _limitTo == ICSearchConstants.DECLARATIONS ){
|
||||||
|
return CPluginImages.DESC_OBJS_SEARCH_DECL;
|
||||||
|
} else {
|
||||||
|
return CPluginImages.DESC_OBJS_SEARCH_REF;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,140 @@
|
||||||
|
/*
|
||||||
|
* Created on Mar 26, 2004
|
||||||
|
*
|
||||||
|
* To change the template for this generated file go to
|
||||||
|
* Window - Preferences - Java - Code Generation - Code and Comments
|
||||||
|
*/
|
||||||
|
package org.eclipse.cdt.internal.ui.search;
|
||||||
|
|
||||||
|
import java.text.MessageFormat;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
|
import org.eclipse.cdt.core.model.CModelException;
|
||||||
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
|
import org.eclipse.cdt.core.model.IParent;
|
||||||
|
import org.eclipse.core.resources.IFile;
|
||||||
|
import org.eclipse.core.resources.IProject;
|
||||||
|
import org.eclipse.jface.resource.ImageDescriptor;
|
||||||
|
import org.eclipse.search.ui.ISearchQuery;
|
||||||
|
import org.eclipse.search.ui.text.AbstractTextSearchResult;
|
||||||
|
import org.eclipse.search.ui.text.Match;
|
||||||
|
import org.eclipse.ui.IEditorInput;
|
||||||
|
import org.eclipse.ui.IEditorPart;
|
||||||
|
import org.eclipse.ui.IFileEditorInput;
|
||||||
|
/**
|
||||||
|
* @author bog
|
||||||
|
*
|
||||||
|
* To change the template for this generated type comment go to
|
||||||
|
* Window - Preferences - Java - Code Generation - Code and Comments
|
||||||
|
*/
|
||||||
|
public class CSearchResult extends AbstractTextSearchResult {
|
||||||
|
CSearchQuery cQuery;
|
||||||
|
|
||||||
|
public CSearchResult(CSearchQuery query){
|
||||||
|
cQuery = query;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.search.ui.text.AbstractTextSearchResult#findContainedMatches(org.eclipse.core.resources.IFile)
|
||||||
|
*/
|
||||||
|
public Match[] findContainedMatches(IFile file) {
|
||||||
|
ICElement cElement= create(file);
|
||||||
|
Set matches= new HashSet();
|
||||||
|
collectMatches(matches, cElement);
|
||||||
|
return (Match[]) matches.toArray(new Match[matches.size()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ICElement create(IFile file){
|
||||||
|
IProject project = file.getProject();
|
||||||
|
ICProject cProject = CCorePlugin.getDefault().getCoreModel().create(project);
|
||||||
|
return cProject;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void collectMatches(Set matches, ICElement element) {
|
||||||
|
Match[] m= getMatches(element);
|
||||||
|
if (m.length != 0) {
|
||||||
|
for (int i= 0; i < m.length; i++) {
|
||||||
|
matches.add(m[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (element instanceof IParent) {
|
||||||
|
IParent parent= (IParent) element;
|
||||||
|
|
||||||
|
ICElement[] children= parent.getChildren();
|
||||||
|
for (int i= 0; i < children.length; i++) {
|
||||||
|
collectMatches(matches, children[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.search.ui.text.AbstractTextSearchResult#getFile(java.lang.Object)
|
||||||
|
*/
|
||||||
|
public IFile getFile(Object element) {
|
||||||
|
if (element instanceof ICElement) {
|
||||||
|
ICElement cElement= (ICElement) element;
|
||||||
|
element= cElement.getUnderlyingResource();
|
||||||
|
}
|
||||||
|
if (element instanceof IFile)
|
||||||
|
return (IFile)element;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.search.ui.text.AbstractTextSearchResult#isShownInEditor(org.eclipse.search.ui.text.Match, org.eclipse.ui.IEditorPart)
|
||||||
|
*/
|
||||||
|
public boolean isShownInEditor(Match match, IEditorPart editor) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.search.ui.text.AbstractTextSearchResult#findContainedMatches(org.eclipse.ui.IEditorPart)
|
||||||
|
*/
|
||||||
|
public Match[] findContainedMatches(IEditorPart editor) {
|
||||||
|
IEditorInput editorInput= editor.getEditorInput();
|
||||||
|
if (editorInput instanceof IFileEditorInput) {
|
||||||
|
IFileEditorInput fileEditorInput= (IFileEditorInput) editorInput;
|
||||||
|
return findContainedMatches(fileEditorInput.getFile());
|
||||||
|
} /*else if (editorInput instanceof IClassFileEditorInput) {
|
||||||
|
IClassFileEditorInput classFileEditorInput= (IClassFileEditorInput) editorInput;
|
||||||
|
Set matches= new HashSet();
|
||||||
|
collectMatches(matches, classFileEditorInput.getClassFile());
|
||||||
|
return (Match[]) matches.toArray(new Match[matches.size()]);
|
||||||
|
}*/
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.search.ui.ISearchResult#getText()
|
||||||
|
*/
|
||||||
|
public String getText() {
|
||||||
|
int matchCount= getMatchCount();
|
||||||
|
String format= null;
|
||||||
|
if (matchCount == 1)
|
||||||
|
format= cQuery.getSingularLabel();
|
||||||
|
else
|
||||||
|
format= cQuery.getPluralLabelPattern();
|
||||||
|
return MessageFormat.format(format, new Object[] { new Integer(matchCount) });
|
||||||
|
}
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.search.ui.ISearchResult#getTooltip()
|
||||||
|
*/
|
||||||
|
public String getTooltip() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return getText();
|
||||||
|
}
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.search.ui.ISearchResult#getImageDescriptor()
|
||||||
|
*/
|
||||||
|
public ImageDescriptor getImageDescriptor() {
|
||||||
|
return cQuery.getImageDescriptor();
|
||||||
|
}
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.search.ui.ISearchResult#getQuery()
|
||||||
|
*/
|
||||||
|
public ISearchQuery getQuery() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return cQuery;
|
||||||
|
}
|
||||||
|
}
|
|
@ -72,17 +72,32 @@ public class CSearchResultCollector extends BasicSearchResultCollector{
|
||||||
_computer = new GroupByKeyComputer();
|
_computer = new GroupByKeyComputer();
|
||||||
|
|
||||||
if( _view != null ){
|
if( _view != null ){
|
||||||
_view.searchStarted(
|
if (_operation != null){
|
||||||
null,//new ActionGroupFactory(),
|
_view.searchStarted(
|
||||||
_operation.getSingularLabel(),
|
null,//new ActionGroupFactory(),
|
||||||
_operation.getPluralLabelPattern(),
|
_operation.getSingularLabel(),
|
||||||
_operation.getImageDescriptor(),
|
_operation.getPluralLabelPattern(),
|
||||||
CSearchPage.EXTENSION_POINT_ID,
|
_operation.getImageDescriptor(),
|
||||||
labelProvider,
|
CSearchPage.EXTENSION_POINT_ID,
|
||||||
new GotoMarkerAction(),
|
labelProvider,
|
||||||
_computer,
|
new GotoMarkerAction(),
|
||||||
_operation
|
_computer,
|
||||||
);
|
_operation
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else if (_query != null){
|
||||||
|
_view.searchStarted(
|
||||||
|
null,//new ActionGroupFactory(),
|
||||||
|
_query.getSingularLabel(),
|
||||||
|
_query.getPluralLabelPattern(),
|
||||||
|
_query.getImageDescriptor(),
|
||||||
|
CSearchPage.EXTENSION_POINT_ID,
|
||||||
|
labelProvider,
|
||||||
|
new GotoMarkerAction(),
|
||||||
|
_computer,
|
||||||
|
null
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( getProgressMonitor() != null && !getProgressMonitor().isCanceled() ){
|
if( getProgressMonitor() != null && !getProgressMonitor().isCanceled() ){
|
||||||
|
@ -200,4 +215,12 @@ public class CSearchResultCollector extends BasicSearchResultCollector{
|
||||||
private ISearchResultView _view;
|
private ISearchResultView _view;
|
||||||
private IGroupByKeyComputer _computer;
|
private IGroupByKeyComputer _computer;
|
||||||
private int _matchCount;
|
private int _matchCount;
|
||||||
|
private CSearchQuery _query;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param query
|
||||||
|
*/
|
||||||
|
public void setOperation(CSearchQuery query) {
|
||||||
|
_query = query;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue