mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-30 03:33:37 +02:00
- From Head: Added support for search name grouping
This commit is contained in:
parent
4f3559d20d
commit
6b2957ccda
7 changed files with 130 additions and 30 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<test.length; i++){
|
||||
BasicSearchMatch tempMatch = (BasicSearchMatch) test[i];
|
||||
if (tempMatch.getResource().equals(file)){
|
||||
Match[] m= getMatches(tempMatch);
|
||||
|
||||
if (m.length != 0) {
|
||||
for (int j= 0; j < m.length; j++) {
|
||||
matches.add(m[j]);
|
||||
}
|
||||
}
|
||||
Match[]testMatches=this.getMatches(test[i]);
|
||||
for (int k=0;k<testMatches.length;k++){
|
||||
if (((CSearchMatch) testMatches[k]).getSearchMatch().getResource().equals(file))
|
||||
matches.add(testMatches[k]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,7 +39,6 @@ import org.eclipse.jface.viewers.TreeViewer;
|
|||
import org.eclipse.jface.viewers.ViewerSorter;
|
||||
import org.eclipse.search.ui.IContextMenuConstants;
|
||||
import org.eclipse.search.ui.NewSearchUI;
|
||||
import org.eclipse.search.ui.SearchUI;
|
||||
import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
|
||||
import org.eclipse.search.ui.text.Match;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
|
@ -120,8 +119,8 @@ public class CSearchResultPage extends AbstractTextSearchViewPage {
|
|||
}
|
||||
} else if (element instanceof IFile) {
|
||||
editor= IDE.openEditor(CUIPlugin.getActivePage(), getCanonicalFile((IFile) element), false);
|
||||
} else if (element instanceof BasicSearchMatch){
|
||||
BasicSearchMatch searchMatch = (BasicSearchMatch) element;
|
||||
} else if (match instanceof CSearchMatch){
|
||||
BasicSearchMatch searchMatch = ((CSearchMatch) match).getSearchMatch();
|
||||
if (searchMatch.resource != null){
|
||||
editor = IDE.openEditor(CUIPlugin.getActivePage(), getCanonicalFile((IFile) searchMatch.resource), false);
|
||||
showWithMarker(editor, getCanonicalFile((IFile) searchMatch.resource), currentOffset, currentLength);
|
||||
|
@ -158,7 +157,7 @@ public class CSearchResultPage extends AbstractTextSearchViewPage {
|
|||
viewer.setSorter(new ViewerSorter());
|
||||
CSearchResultLabelProvider labelProvider = new CSearchResultLabelProvider();
|
||||
labelProvider.setOrder(CSearchResultLabelProvider.SHOW_NAME_ONLY);
|
||||
viewer.setLabelProvider(labelProvider);
|
||||
viewer.setLabelProvider(new CountLabelProvider(this, labelProvider));
|
||||
_contentProvider= new LevelTreeContentProvider(viewer, _currentGrouping);
|
||||
viewer.setContentProvider(_contentProvider);
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ 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.search.ui.text.Match;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
|
||||
public class LevelTreeContentProvider extends CSearchContentProvider implements ITreeContentProvider {
|
||||
|
@ -63,8 +64,9 @@ public class LevelTreeContentProvider extends CSearchContentProvider implements
|
|||
|
||||
public Object getParent(Object child) {
|
||||
Object possibleParent= null;
|
||||
if (child instanceof BasicSearchMatch){
|
||||
BasicSearchMatch tempMatch = (BasicSearchMatch)child;
|
||||
|
||||
if (child instanceof CSearchMatch){
|
||||
BasicSearchMatch tempMatch = ((CSearchMatch) child).getSearchMatch();
|
||||
ICElement cTransUnit = CCorePlugin.getDefault().getCoreModel().create(tempMatch.getResource());
|
||||
|
||||
if (cTransUnit instanceof ITranslationUnit){
|
||||
|
@ -123,7 +125,7 @@ public class LevelTreeContentProvider extends CSearchContentProvider implements
|
|||
}
|
||||
|
||||
protected void insert(Object child, boolean refreshViewer) {
|
||||
Object parent= getParent(child);
|
||||
Object parent= getMatchParent(child);
|
||||
while (parent != null) {
|
||||
if (insertChild(parent, child)) {
|
||||
if (refreshViewer)
|
||||
|
@ -143,6 +145,22 @@ public class LevelTreeContentProvider extends CSearchContentProvider implements
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param child
|
||||
* @return
|
||||
*/
|
||||
private Object getMatchParent(Object child) {
|
||||
Match[]m=null;
|
||||
if (child instanceof String){
|
||||
m=this._result.getMatches(child);
|
||||
}
|
||||
|
||||
if (m.length > 0)
|
||||
return getParent(m[0]);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns true if the child already was a child of parent.
|
||||
*
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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$
|
||||
|
|
Loading…
Add table
Reference in a new issue