diff --git a/core/org.eclipse.cdt.ui/ChangeLog b/core/org.eclipse.cdt.ui/ChangeLog index 8996122e8dc..dd1b529daae 100644 --- a/core/org.eclipse.cdt.ui/ChangeLog +++ b/core/org.eclipse.cdt.ui/ChangeLog @@ -1,3 +1,6 @@ +2004-07-08 Bogdan Gheorghe + Add some fixes from head branch: Added support for search name grouping. + 2004-07-07 Hoda Amer Fix for PR 69411: Bad label: WizardNewFileCreationPage.progress diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchMatch.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchMatch.java index 3f04195a512..3e61df3d523 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchMatch.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchMatch.java @@ -1,9 +1,14 @@ -/* - * Created on Jun 27, 2004 - * - * TODO To change the template for this generated file go to - * Window - Preferences - Java - Code Style - Code Templates - */ +/******************************************************************************* + * 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.search.BasicSearchMatch; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchResult.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchResult.java index b5f64d13acc..af7befb8416 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchResult.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchResult.java @@ -117,6 +117,16 @@ public class CSearchResult extends AbstractTextSearchResult implements IEditorMa else return false; } + } else if (match instanceof CSearchMatch) { + BasicSearchMatch searchMatch = ((CSearchMatch) match).getSearchMatch(); + if (editorInput instanceof IFileEditorInput){ + IFile inputFile= ((IFileEditorInput)editorInput).getFile(); + IResource matchFile = searchMatch.getResource(); + if (matchFile != null) + return inputFile.equals(matchFile); + else + return false; + } } else if (match.getElement() instanceof IFile) { if (editorInput instanceof IFileEditorInput) { return ((IFileEditorInput)editorInput).getFile().equals(match.getElement()); @@ -231,15 +241,10 @@ public class CSearchResult extends AbstractTextSearchResult implements IEditorMa private void collectMatches(Set matches, Object[] test, IFile file) { for (int i=0; i 0) + return getParent(m[0]); + + return null; + } + /** * returns true if the child already was a child of parent. * diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/NewSearchResultCollector.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/NewSearchResultCollector.java index c58f4d15112..2f44faf252d 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/NewSearchResultCollector.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/NewSearchResultCollector.java @@ -28,6 +28,21 @@ import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.search.ui.text.Match; public class NewSearchResultCollector extends BasicSearchResultCollector { + public static final int PARENT_LENGTH = 7; + public static final String PARENT = "PARENT:"; //$NON-NLS-1$ + + public static final int NAME_LENGTH = 5; + public static final String NAME = "NAME:"; //$NON-NLS-1$ + + public static final int LOCATION_LENGTH = 9; + public static final String LOCATION = "LOCATION:"; //$NON-NLS-1$ + + public static final int ELEMENTTYPE_LENGTH = 12; + public static final String ELEMENTTYPE = "ELEMENTTYPE:"; //$NON-NLS-1$ + + public static final int VISIBILITY_LENGTH = 11; + public static final String VISIBILITY = "VISIBILITY:"; //$NON-NLS-1$ + private CSearchResult fSearch; private IProgressMonitor fProgressMonitor; private int fMatchCount; @@ -77,7 +92,9 @@ public class NewSearchResultCollector extends BasicSearchResultCollector { fMatchCount++; int start = match.getStartOffset(); int end = match.getEndOffset(); - fSearch.addMatch(new Match(match,start,end-start)); + String classifier = PARENT + match.getParentName() + NAME + match.getName() + LOCATION + match.getLocation().toOSString() + ELEMENTTYPE + match.getElementType() + VISIBILITY + match.getVisibility(); + fSearch.addMatch(new CSearchMatch(classifier,start,end-start, match)); + return true; } else { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CSearchResultLabelProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CSearchResultLabelProvider.java index 7ad2f1fb8e5..1fb6f77ea5f 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CSearchResultLabelProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CSearchResultLabelProvider.java @@ -19,6 +19,7 @@ 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.cdt.internal.ui.search.NewSearchResultCollector; import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; @@ -35,7 +36,7 @@ import org.eclipse.swt.graphics.Point; * Window>Preferences>Java>Code Generation>Code and Comments */ public class CSearchResultLabelProvider extends LabelProvider { - + public static final int SHOW_NAME_ONLY = 0; public static final int SHOW_ELEMENT_CONTAINER = 1; public static final int SHOW_CONTAINER_ELEMENT = 2; @@ -58,6 +59,7 @@ public class CSearchResultLabelProvider extends LabelProvider { public Image getImage( Object element ) { IMatch match = null; int elementType = -1; + int visibility = -1; if( element instanceof ISearchResultViewEntry ){ ISearchResultViewEntry viewEntry = (ISearchResultViewEntry)element; IMarker marker = viewEntry.getSelectedMarker(); @@ -66,6 +68,7 @@ public class CSearchResultLabelProvider extends LabelProvider { if( match == null ) return null; elementType = match.getElementType(); + visibility = match.getVisibility(); } catch (CoreException e) { return null; } @@ -74,10 +77,20 @@ public class CSearchResultLabelProvider extends LabelProvider { if( match == null ) return null; elementType = match.getElementType(); - + visibility = match.getVisibility(); } else if (element instanceof ICElement){ elementType = ((ICElement) element).getElementType(); - } + } else if (element instanceof String){ + String eleString = (String) element; + int elIndex = eleString.indexOf(NewSearchResultCollector.ELEMENTTYPE); + int vizIndex = eleString.indexOf(NewSearchResultCollector.VISIBILITY); + + String elType = eleString.substring(elIndex+NewSearchResultCollector.ELEMENTTYPE_LENGTH,vizIndex); + String elViz = eleString.substring(vizIndex+NewSearchResultCollector.VISIBILITY_LENGTH,eleString.length()); + + elementType = new Integer(elType).intValue(); + visibility = new Integer(elViz).intValue(); + } @@ -99,7 +112,7 @@ public class CSearchResultLabelProvider extends LabelProvider { case ICElement.C_UNIT: imageDescriptor = CPluginImages.DESC_OBJS_TUNIT; break; case ICElement.C_FIELD: { - switch( match.getVisibility() ){ + switch( visibility ){ case ICElement.CPP_PUBLIC: imageDescriptor = CPluginImages.DESC_OBJS_PUBLIC_FIELD; break; case ICElement.CPP_PRIVATE: imageDescriptor = CPluginImages.DESC_OBJS_PRIVATE_FIELD; break; default: imageDescriptor = CPluginImages.DESC_OBJS_PROTECTED_FIELD; break; @@ -108,7 +121,7 @@ public class CSearchResultLabelProvider extends LabelProvider { } case ICElement.C_METHOD: { - switch( match.getVisibility() ){ + switch( visibility ){ case ICElement.CPP_PUBLIC: imageDescriptor = CPluginImages.DESC_OBJS_PUBLIC_METHOD; break; case ICElement.CPP_PRIVATE: imageDescriptor = CPluginImages.DESC_OBJS_PRIVATE_METHOD; break; default: imageDescriptor = CPluginImages.DESC_OBJS_PROTECTED_METHOD; break; @@ -147,9 +160,21 @@ public class CSearchResultLabelProvider extends LabelProvider { } } else if( element instanceof IMatch ){ match = (IMatch) element; - } - else if ( element instanceof ICElement){ + } else if ( element instanceof ICElement){ return getElementText((ICElement) element); + } else if (element instanceof String){ + String elString = (String) element; + + int parentIndex = elString.indexOf(NewSearchResultCollector.PARENT); + int nameIndex = elString.indexOf(NewSearchResultCollector.NAME); + int locationIndex = elString.indexOf(NewSearchResultCollector.LOCATION); + int elementIndex = elString.indexOf(NewSearchResultCollector.ELEMENTTYPE); + + String elParent = elString.substring(parentIndex+NewSearchResultCollector.PARENT_LENGTH,nameIndex); + String elName = elString.substring(nameIndex+NewSearchResultCollector.NAME_LENGTH,locationIndex); + String elPath = elString.substring(locationIndex+NewSearchResultCollector.LOCATION_LENGTH, elementIndex); + + return getCSearchSortElementText(elParent, elName, elPath); } if( match == null ) @@ -189,6 +214,34 @@ public class CSearchResultLabelProvider extends LabelProvider { return result; } + /** + * @param element + * @return + */ + private String getCSearchSortElementText(String parentName, String name, String path) { + String result = ""; //$NON-NLS-1$ + + switch( getOrder() ){ + case SHOW_NAME_ONLY: + result = name; + case SHOW_ELEMENT_CONTAINER: + if( !parentName.equals("") ) //$NON-NLS-1$ + result = name + " - " + parentName + " ( " + path + " )"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + else + result = name+ " ( " + path + " )"; //$NON-NLS-1$ //$NON-NLS-2$ + + break; + case SHOW_PATH: + result = path + " - " + parentName + "::" + name; //$NON-NLS-1$ //$NON-NLS-2$ + break; + case SHOW_CONTAINER_ELEMENT: + result = parentName + "::" + name + " ( " + path + " )"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + break; + } + + return result; + } + private String getElementText(ICElement element){ String result=""; //$NON-NLS-1$