mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-06 01:06:01 +02:00
Patch for Andrew Niefer
This commit is contained in:
parent
b8321abb0a
commit
5022fcb844
5 changed files with 130 additions and 65 deletions
|
@ -1,3 +1,11 @@
|
|||
2003-09-03 Andrew Niefer
|
||||
C++ Search: Changed default sort order to be by path
|
||||
changed search dialog to have checkboxes for Search For items.
|
||||
* src/org/eclipse/cdt/ui/CSearchResultLabelProvider.java
|
||||
* src/org/eclipse/cdt/internal/ui/search/CSearchPage.java
|
||||
* src/org/eclipse/cdt/internal/ui/search/CSearchOperation.java
|
||||
* src/org/eclipse/cdt/internal/ui/search/CSearchMessages.properties
|
||||
|
||||
2003-09-03 David Inglis
|
||||
Fixed parser block to save ids properly.
|
||||
Use shared preference key for error parsers.
|
||||
|
|
|
@ -50,11 +50,17 @@ Search.potentialMatchDialog.message= Inexact matches were found and will be disp
|
|||
|
||||
CSearchPage.searchFor.label= Search For
|
||||
CSearchPage.searchFor.type= &Type
|
||||
CSearchPage.searchFor.namespace= N&amespace
|
||||
CSearchPage.searchFor.namespace= Name&space
|
||||
CSearchPage.searchFor.method= &Method
|
||||
CSearchPage.searchFor.function= F&unction
|
||||
CSearchPage.searchFor.field= &Field
|
||||
CSearchPage.searchFor.variable= &Variable
|
||||
CSearchPage.searchFor.class= &Class
|
||||
CSearchPage.searchFor.struct= &Struct
|
||||
CSearchPage.searchFor.union= U&nion
|
||||
CSearchPage.searchFor.enum= &Enumeration
|
||||
CSearchPage.searchFor.any= An&y Element
|
||||
CSearchPage.searchFor.classStruct= &Class / Struct
|
||||
|
||||
CSearchPage.limitTo.label= Limit To
|
||||
CSearchPage.limitTo.declarations= Dec&larations
|
||||
|
|
|
@ -14,12 +14,15 @@
|
|||
package org.eclipse.cdt.internal.ui.search;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
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.SearchEngine;
|
||||
import org.eclipse.cdt.internal.core.search.matching.OrPattern;
|
||||
import org.eclipse.cdt.internal.ui.CPluginImages;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.core.resources.IWorkspace;
|
||||
|
@ -41,7 +44,7 @@ public class CSearchOperation extends WorkspaceModifyOperation implements ICSear
|
|||
_elementPattern = element;
|
||||
}
|
||||
|
||||
public CSearchOperation(IWorkspace workspace, String pattern, boolean caseSensitive, SearchFor searchFor, LimitTo limitTo, ICSearchScope scope, String scopeDescription, CSearchResultCollector collector) {
|
||||
public CSearchOperation(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;
|
||||
|
@ -69,7 +72,21 @@ public class CSearchOperation extends WorkspaceModifyOperation implements ICSear
|
|||
if( _elementPattern != null ){
|
||||
engine.search( _workspace, _elementPattern, _limitTo, _scope, _collector );
|
||||
} else {
|
||||
ICSearchPattern pattern = SearchEngine.createSearchPattern( _stringPattern, _searchFor, _limitTo, _caseSensitive );
|
||||
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 );
|
||||
}
|
||||
|
||||
engine.search( _workspace, pattern, _scope, _collector );
|
||||
}
|
||||
|
||||
|
@ -139,7 +156,7 @@ public class CSearchOperation extends WorkspaceModifyOperation implements ICSear
|
|||
private String _scopeDescription;
|
||||
private boolean _caseSensitive;
|
||||
private LimitTo _limitTo;
|
||||
private SearchFor _searchFor;
|
||||
private List _searchFor;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@ import java.io.StringReader;
|
|||
import java.lang.reflect.InvocationTargetException;
|
||||
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;
|
||||
|
@ -31,15 +33,11 @@ import org.eclipse.core.runtime.IAdaptable;
|
|||
import org.eclipse.jface.dialogs.Dialog;
|
||||
import org.eclipse.jface.dialogs.DialogPage;
|
||||
import org.eclipse.jface.dialogs.IDialogSettings;
|
||||
|
||||
import org.eclipse.jface.text.ITextSelection;
|
||||
import org.eclipse.jface.util.Assert;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.jface.viewers.StructuredSelection;
|
||||
|
||||
import org.eclipse.search.internal.ui.util.RowLayouter;
|
||||
|
||||
import org.eclipse.search.ui.ISearchPage;
|
||||
import org.eclipse.search.ui.ISearchPageContainer;
|
||||
import org.eclipse.search.ui.ISearchResultViewEntry;
|
||||
|
@ -155,7 +153,7 @@ public class CSearchPage extends DialogPage implements ISearchPage, ICSearchCons
|
|||
fCElement= fInitialData.cElement;
|
||||
else
|
||||
fCElement= null;
|
||||
|
||||
handleAllElements( event );
|
||||
setLimitTo( getSearchFor() );
|
||||
updateCaseSensitiveCheckbox();
|
||||
}
|
||||
|
@ -222,7 +220,14 @@ public class CSearchPage extends DialogPage implements ISearchPage, ICSearchCons
|
|||
return result;
|
||||
}
|
||||
|
||||
|
||||
private void handleAllElements( SelectionEvent event ){
|
||||
Button allElements = fSearchFor[ fSearchFor.length - 1 ];
|
||||
if( event.widget == allElements ){
|
||||
for( int i = 0; i < fSearchFor.length - 1; i++ )
|
||||
fSearchFor[i].setEnabled( ! allElements.getSelection() );
|
||||
}
|
||||
}
|
||||
|
||||
private void handlePatternSelected() {
|
||||
if( fPattern.getSelectionIndex() < 0 )
|
||||
return;
|
||||
|
@ -255,6 +260,12 @@ public class CSearchPage extends DialogPage implements ISearchPage, ICSearchCons
|
|||
button.setText( fLimitToText[i] );
|
||||
fLimitTo[i] = button;
|
||||
}
|
||||
|
||||
// Fill with dummy radio buttons
|
||||
Button filler= new Button(result, SWT.RADIO);
|
||||
filler.setVisible(false);
|
||||
filler= new Button(result, SWT.RADIO);
|
||||
filler.setVisible(false);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -267,16 +278,22 @@ public class CSearchPage extends DialogPage implements ISearchPage, ICSearchCons
|
|||
return null;
|
||||
}
|
||||
|
||||
private void setLimitTo( SearchFor searchFor ) {
|
||||
private void setLimitTo( List searchFor ) {
|
||||
HashSet set = new HashSet();
|
||||
|
||||
if ( searchFor == FUNCTION || searchFor == METHOD ) {
|
||||
set.add( DEFINITIONS );
|
||||
}
|
||||
|
||||
|
||||
set.add( DEFINITIONS );
|
||||
set.add( DECLARATIONS );
|
||||
set.add( REFERENCES );
|
||||
set.add( ALL_OCCURRENCES );
|
||||
|
||||
for (Iterator iter = searchFor.iterator(); iter.hasNext();) {
|
||||
SearchFor element = (SearchFor) iter.next();
|
||||
if( element != FUNCTION && element != METHOD ){
|
||||
set.remove( DEFINITIONS );
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for( int i = 0; i < fLimitTo.length; i++ )
|
||||
fLimitTo[ i ].setEnabled( set.contains( fLimitToValues[ i ] ) );
|
||||
|
@ -291,27 +308,25 @@ public class CSearchPage extends DialogPage implements ISearchPage, ICSearchCons
|
|||
|
||||
fSearchFor= new Button[fSearchForText.length];
|
||||
for (int i= 0; i < fSearchForText.length; i++) {
|
||||
Button button= new Button(result, SWT.RADIO);
|
||||
Button button= new Button(result, SWT.CHECK);
|
||||
button.setText(fSearchForText[i]);
|
||||
fSearchFor[i]= button;
|
||||
}
|
||||
|
||||
// Fill with dummy radio buttons
|
||||
//Button filler= new Button(result, SWT.RADIO);
|
||||
//filler.setVisible(false);
|
||||
//filler= new Button(result, SWT.RADIO);
|
||||
//filler.setVisible(false);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private SearchFor getSearchFor() {
|
||||
for (int i= 0; i < fSearchFor.length; i++) {
|
||||
if( fSearchFor[i].getSelection() )
|
||||
return fSearchForValues[ i ];
|
||||
private List getSearchFor() {
|
||||
List search = new LinkedList( );
|
||||
|
||||
boolean all = fSearchFor[ fSearchFor.length - 1 ].getSelection();
|
||||
|
||||
for (int i= 0; i < fSearchFor.length - 1; i++) {
|
||||
if( fSearchFor[i].getSelection() || all )
|
||||
search.add( fSearchForValues[i] );
|
||||
}
|
||||
Assert.isTrue(false, "shouldNeverHappen"); //$NON-NLS-1$
|
||||
return null;
|
||||
|
||||
return search;
|
||||
}
|
||||
|
||||
public void setContainer(ISearchPageContainer container) {
|
||||
|
@ -384,9 +399,15 @@ public class CSearchPage extends DialogPage implements ISearchPage, ICSearchCons
|
|||
fCaseSensitive.setSelection( fInitialData.isCaseSensitive );
|
||||
fCaseSensitive.setEnabled( fInitialData.cElement == null );
|
||||
|
||||
for (int i = 0; i < fSearchFor.length; i++)
|
||||
fSearchFor[i].setSelection( fSearchForValues[i] == fInitialData.searchFor );
|
||||
|
||||
HashSet set = new HashSet( fInitialData.searchFor );
|
||||
|
||||
boolean enabled = ! set.contains( fSearchForValues[ fSearchFor.length - 1 ] );
|
||||
|
||||
for (int i = 0; i < fSearchFor.length; i++){
|
||||
fSearchFor[i].setSelection( set.contains( fSearchForValues[i] ) );
|
||||
fSearchFor[i].setEnabled( enabled );
|
||||
}
|
||||
|
||||
setLimitTo( fInitialData.searchFor );
|
||||
|
||||
for (int i = 0; i < fLimitTo.length; i++)
|
||||
|
@ -414,8 +435,11 @@ public class CSearchPage extends DialogPage implements ISearchPage, ICSearchCons
|
|||
return determineInitValuesFrom( element );
|
||||
} else {
|
||||
IWorkbenchAdapter adapter= (IWorkbenchAdapter)((IAdaptable)o).getAdapter( IWorkbenchAdapter.class );
|
||||
if( adapter != null )
|
||||
return new SearchPatternData( TYPE, REFERENCES, fIsCaseSensitive, adapter.getLabel(o), null );
|
||||
if( adapter != null ){
|
||||
List searchFor = new LinkedList();
|
||||
searchFor.add( CLASS_STRUCT );
|
||||
return new SearchPatternData( searchFor, REFERENCES, fIsCaseSensitive, adapter.getLabel(o), null );
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -438,13 +462,18 @@ public class CSearchPage extends DialogPage implements ISearchPage, ICSearchCons
|
|||
} catch (IOException ex) {
|
||||
text= ""; //$NON-NLS-1$
|
||||
}
|
||||
result= new SearchPatternData( TYPE, REFERENCES, fIsCaseSensitive, text, null);
|
||||
|
||||
List searchFor = new LinkedList();
|
||||
searchFor.add( CLASS_STRUCT );
|
||||
result= new SearchPatternData( searchFor, REFERENCES, fIsCaseSensitive, text, null);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private SearchPatternData getDefaultInitValues() {
|
||||
return new SearchPatternData( TYPE, REFERENCES, fIsCaseSensitive, "", null); //$NON-NLS-1$
|
||||
List searchFor = new LinkedList();
|
||||
searchFor.add( CLASS_STRUCT );
|
||||
return new SearchPatternData( searchFor, REFERENCES, fIsCaseSensitive, "", null); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
private String[] getPreviousSearchPatterns() {
|
||||
|
@ -475,22 +504,22 @@ public class CSearchPage extends DialogPage implements ISearchPage, ICSearchCons
|
|||
private SearchPatternData determineInitValuesFrom( ICElement element ) {
|
||||
if( element == null )
|
||||
return null;
|
||||
|
||||
SearchFor searchFor = UNKNOWN_SEARCH_FOR;
|
||||
LimitTo limitTo = UNKNOWN_LIMIT_TO;
|
||||
|
||||
String pattern = null;
|
||||
switch( element.getElementType() ) {
|
||||
/*case ICElement.PACKAGE_FRAGMENT:
|
||||
searchFor= PACKAGE;
|
||||
limitTo= REFERENCES;
|
||||
pattern= element.getElementName();
|
||||
break;*/
|
||||
}
|
||||
|
||||
if( searchFor != UNKNOWN_SEARCH_FOR && limitTo != UNKNOWN_LIMIT_TO && pattern != null )
|
||||
return new SearchPatternData( searchFor, limitTo, true, pattern, element );
|
||||
|
||||
//TODO search pattern data from element
|
||||
// SearchFor searchFor = UNKNOWN_SEARCH_FOR;
|
||||
// LimitTo limitTo = UNKNOWN_LIMIT_TO;
|
||||
//
|
||||
// String pattern = null;
|
||||
// switch( element.getElementType() ) {
|
||||
// /*case ICElement.PACKAGE_FRAGMENT:
|
||||
// searchFor= PACKAGE;
|
||||
// limitTo= REFERENCES;
|
||||
// pattern= element.getElementName();
|
||||
// break;*/
|
||||
// }
|
||||
//
|
||||
// if( searchFor != UNKNOWN_SEARCH_FOR && limitTo != UNKNOWN_LIMIT_TO && pattern != null )
|
||||
// return new SearchPatternData( searchFor, limitTo, true, pattern, element );
|
||||
//
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -528,7 +557,7 @@ public class CSearchPage extends DialogPage implements ISearchPage, ICSearchCons
|
|||
}
|
||||
|
||||
private static class SearchPatternData {
|
||||
SearchFor searchFor;
|
||||
List searchFor;
|
||||
LimitTo limitTo;
|
||||
String pattern;
|
||||
boolean isCaseSensitive;
|
||||
|
@ -536,11 +565,11 @@ public class CSearchPage extends DialogPage implements ISearchPage, ICSearchCons
|
|||
int scope;
|
||||
IWorkingSet[] workingSets;
|
||||
|
||||
public SearchPatternData(SearchFor s, LimitTo l, boolean i, String p, ICElement element) {
|
||||
public SearchPatternData(List s, LimitTo l, boolean i, String p, ICElement element) {
|
||||
this(s, l, p, i, element, ISearchPageContainer.WORKSPACE_SCOPE, null);
|
||||
}
|
||||
|
||||
public SearchPatternData(SearchFor s, LimitTo l, String p, boolean i, ICElement element, int scope, IWorkingSet[] workingSets) {
|
||||
public SearchPatternData(List s, LimitTo l, String p, boolean i, ICElement element, int scope, IWorkingSet[] workingSets) {
|
||||
searchFor= s;
|
||||
limitTo= l;
|
||||
pattern= p;
|
||||
|
@ -558,14 +587,19 @@ public class CSearchPage extends DialogPage implements ISearchPage, ICSearchCons
|
|||
private static List fgPreviousSearchPatterns = new ArrayList(20);
|
||||
|
||||
private Button[] fSearchFor;
|
||||
private SearchFor[] fSearchForValues = { TYPE, NAMESPACE, METHOD, FUNCTION, FIELD, VAR };
|
||||
private SearchFor[] fSearchForValues = { CLASS_STRUCT, FUNCTION, VAR, UNION, METHOD, FIELD, NAMESPACE, ENUM, null };
|
||||
|
||||
private String[] fSearchForText= {
|
||||
CSearchMessages.getString("CSearchPage.searchFor.type"), //$NON-NLS-1$
|
||||
CSearchMessages.getString("CSearchPage.searchFor.namespace"), //$NON-NLS-1$
|
||||
CSearchMessages.getString("CSearchPage.searchFor.method"), //$NON-NLS-1$
|
||||
CSearchMessages.getString("CSearchPage.searchFor.function"),
|
||||
CSearchMessages.getString("CSearchPage.searchFor.field"),
|
||||
CSearchMessages.getString("CSearchPage.searchFor.variable") }; //$NON-NLS-1$
|
||||
CSearchMessages.getString("CSearchPage.searchFor.classStruct"), //$NON-NLS-1$
|
||||
CSearchMessages.getString("CSearchPage.searchFor.function"), //$NON-NLS-1$
|
||||
CSearchMessages.getString("CSearchPage.searchFor.variable"), //$NON-NLS-1$
|
||||
CSearchMessages.getString("CSearchPage.searchFor.union"), //$NON-NLS-1$
|
||||
CSearchMessages.getString("CSearchPage.searchFor.method"), //$NON-NLS-1$
|
||||
CSearchMessages.getString("CSearchPage.searchFor.field"), //$NON-NLS-1$
|
||||
CSearchMessages.getString("CSearchPage.searchFor.enum"), //$NON-NLS-1$
|
||||
CSearchMessages.getString("CSearchPage.searchFor.namespace"), //$NON-NLS-1$
|
||||
CSearchMessages.getString("CSearchPage.searchFor.any") }; //$NON-NLS-1$
|
||||
|
||||
|
||||
private Button[] fLimitTo;
|
||||
private LimitTo[] fLimitToValues = { DECLARATIONS, DEFINITIONS, REFERENCES, ALL_OCCURRENCES };
|
||||
|
|
|
@ -35,15 +35,15 @@ import org.eclipse.swt.graphics.Point;
|
|||
*/
|
||||
public class CSearchResultLabelProvider extends LabelProvider {
|
||||
|
||||
public static final int SHOW_NAME_ONLY = 0; //default
|
||||
public static final int SHOW_NAME_ONLY = 0;
|
||||
public static final int SHOW_ELEMENT_CONTAINER = 1;
|
||||
public static final int SHOW_CONTAINER_ELEMENT = 2;
|
||||
public static final int SHOW_PATH = 3;
|
||||
public static final int SHOW_PATH = 3;//default
|
||||
|
||||
public static final String POTENTIAL_MATCH = CSearchMessages.getString("CSearchResultLabelProvider.potentialMatch"); //$NON-NLS-1$
|
||||
|
||||
public CSearchResultLabelProvider(){
|
||||
_sortOrder = SHOW_NAME_ONLY;
|
||||
_sortOrder = SHOW_PATH;
|
||||
}
|
||||
|
||||
public Image getImage( Object element ) {
|
||||
|
|
Loading…
Add table
Reference in a new issue