diff --git a/core/org.eclipse.cdt.ui/ChangeLog b/core/org.eclipse.cdt.ui/ChangeLog index d88903a2017..882799374b4 100644 --- a/core/org.eclipse.cdt.ui/ChangeLog +++ b/core/org.eclipse.cdt.ui/ChangeLog @@ -1,3 +1,15 @@ +2004-05-16 Bogdan Gheorghe + Added sorters to the search results + + * src/org/eclipse/cdt/internal/ui/search/CSearchMessages.properties + * src/org/eclipse/cdt/internal/ui/search/CSearchResultPage.java + * src/org/eclipse/cdt/internal/ui/search/ElementNameSorter.java + * src/org/eclipse/cdt/internal/ui/search/LevelTreeContentProvider.java + * src/org/eclipse/cdt/internal/ui/search/ParentNameSorter.java + * src/org/eclipse/cdt/internal/ui/search/PathNameSorter.java + * src/org/eclipse/cdt/internal/ui/search/actions/GroupAction.java + * src/org/eclipse/cdt/internal/ui/search/actions/SortAction.java + 2004-05-14 Bogdan Gheorghe fix bug 48020, Duplicate Mnemonics in Search Dialog * src/org/eclipse/cdt/internal/ui/search/CSearchMessages.properties diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginImages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginImages.java index d2701dc5215..950f4c6ac48 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginImages.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginImages.java @@ -88,6 +88,8 @@ public class CPluginImages { public static final String IMG_OBJS_SOURCE_ATTACH_ATTRIB = NAME_PREFIX + "source_attach_attrib.gif"; //$NON-NLS-1$ public static final String IMG_OBJS_ARCHIVE_WSRC= NAME_PREFIX + "ar_src_obj.gif"; //$NON-NLS-1$ + public static final String IMG_OBJS_PROJECT=NAME_PREFIX + "prj_obj.gif"; //$NON-NLS-1$ + // Breakpoint images public static final String IMG_OBJS_BREAKPOINT = NAME_PREFIX + "breakpoint.gif"; //$NON-NLS-1$ public static final String IMG_OBJS_BREAKPOINT_DISABLED = NAME_PREFIX + "breakpoint_disabled.gif"; //$NON-NLS-1$ diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchMessages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchMessages.properties index edcb9225815..112136ccebd 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchMessages.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchMessages.properties @@ -104,3 +104,17 @@ CSearchQuery.searchfor_declarations=Search for Declarations CSearchQuery.searchfor_definitions=Search for Definitions CSearchQuery.searchfor_all=Search for All Occurrences CSearchQuery.search_label=Search + +# CSearchResultPage Sort +CSearchResultPage.element_name= Name +CSearchResultPage.parent_name= Parent Name +CSearchResultPage.path_name= Path +CSearchResultPage.sort= Sort By + +# Group +CSearchResultPage.groupby_project=Project +CSearchResultPage.groupby_project.tooltip=Group by Project +CSearchResultPage.groupby_file=File +CSearchResultPage.groupby_file.tooltip=Group by File +CSearchResultPage.groupby_namespace=Namespace +CSearchResultPage.groupby_namespace.tooltip=Group by Namespace diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchResultPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchResultPage.java index 332a5f11a79..33b231a90af 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchResultPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchResultPage.java @@ -15,14 +15,23 @@ 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.CPluginImages; +import org.eclipse.cdt.internal.ui.search.actions.GroupAction; +import org.eclipse.cdt.internal.ui.search.actions.SortAction; 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.action.IMenuManager; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.viewers.StructuredViewer; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.ViewerSorter; +import org.eclipse.search.ui.IContextMenuConstants; import org.eclipse.search.ui.SearchUI; import org.eclipse.search.ui.text.AbstractTextSearchViewPage; import org.eclipse.search.ui.text.Match; @@ -36,6 +45,48 @@ public class CSearchResultPage extends AbstractTextSearchViewPage { private int _currentSortOrder; private int _currentGrouping; + private SortAction _parentSortAction; + private SortAction _pathSortAction; + private SortAction _elementNameSortAction; + + private GroupAction _groupFileAction; + private GroupAction _groupNamespaceAction; + private GroupAction _groupProjectAction; + + private static final String KEY_GROUPING= "org.eclipse.cdt.search.resultpage.grouping"; //$NON-NLS-1$ + + + public CSearchResultPage(){ + _parentSortAction = new SortAction(CSearchMessages.getString("CSearchResultPage.parent_name"),this,CSearchResultLabelProvider.SHOW_CONTAINER_ELEMENT); //$NON-NLS-1$ + _pathSortAction = new SortAction(CSearchMessages.getString("CSearchResultPage.path_name"),this,CSearchResultLabelProvider.SHOW_PATH); //$NON-NLS-1$ + _elementNameSortAction = new SortAction(CSearchMessages.getString("CSearchResultPage.element_name"),this, CSearchResultLabelProvider.SHOW_ELEMENT_CONTAINER); //$NON-NLS-1$ + _currentSortOrder= CSearchResultLabelProvider.SHOW_ELEMENT_CONTAINER; + + initGroupingActions(); + } + + + /** + * + */ + private void initGroupingActions() { + _groupProjectAction= new GroupAction(CSearchMessages.getString("CSearchResultPage.groupby_project"),CSearchMessages.getString("CSearchResultPage.groupby_project.tooltip"), this, LevelTreeContentProvider.LEVEL_PROJECT); //$NON-NLS-1$ //$NON-NLS-2$ + CPluginImages.setImageDescriptors(_groupProjectAction,CPluginImages.T_TOOL, CPluginImages.IMG_OBJS_PROJECT); //$NON-NLS-1$)//.setLocalImageDescriptors(f + + _groupNamespaceAction= new GroupAction(CSearchMessages.getString("CSearchResultPage.groupby_namespace"), CSearchMessages.getString("CSearchResultPage.groupby_namespace.tooltip"), this, LevelTreeContentProvider.LEVEL_NAMESPACE); //$NON-NLS-1$ //$NON-NLS-2$ + CPluginImages.setImageDescriptors(_groupNamespaceAction,CPluginImages.T_TOOL, CPluginImages.IMG_OBJS_PROJECT); //$NON-NLS-1$ + + _groupFileAction= new GroupAction(CSearchMessages.getString("CSearchResultPage.groupby_file"), CSearchMessages.getString("CSearchResultPage.groupby_file.tooltip"), this, LevelTreeContentProvider.LEVEL_FILE); //$NON-NLS-1$ //$NON-NLS-2$ + CPluginImages.setImageDescriptors(_groupFileAction,CPluginImages.T_TOOL,CPluginImages.IMG_OBJS_PROJECT); //$NON-NLS-1$ + + try { + _currentGrouping= getSettings().getInt(KEY_GROUPING); + } catch (NumberFormatException e) { + _currentGrouping= LevelTreeContentProvider.LEVEL_PROJECT; + } + } + + /* (non-Javadoc) * @see org.eclipse.search.ui.text.AbstractTextSearchViewPage#showMatch(org.eclipse.search.ui.text.Match, int, int) */ @@ -91,10 +142,13 @@ public class CSearchResultPage extends AbstractTextSearchViewPage { * @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 CountLabelProvider(this,new CSearchResultLabelProvider())); + viewer.setSorter(new ViewerSorter()); + CSearchResultLabelProvider labelProvider = new CSearchResultLabelProvider(); + labelProvider.setOrder(CSearchResultLabelProvider.SHOW_NAME_ONLY); + viewer.setLabelProvider(labelProvider); _contentProvider= new LevelTreeContentProvider(viewer, _currentGrouping); viewer.setContentProvider(_contentProvider); + } /* (non-Javadoc) * @see org.eclipse.search.ui.text.AbstractTextSearchViewPage#configureTableViewer(org.eclipse.jface.viewers.TableViewer) @@ -103,7 +157,7 @@ public class CSearchResultPage extends AbstractTextSearchViewPage { viewer.setLabelProvider(new CountLabelProvider(this, new CSearchResultLabelProvider())); _contentProvider=new CSearchTableContentProvider(viewer); viewer.setContentProvider(_contentProvider); - //setSortOrder(_currentSortOrder); + setSortOrder(_currentSortOrder); } private void showWithMarker(IEditorPart editor, IFile file, int offset, int length) throws PartInitException { @@ -119,4 +173,80 @@ public class CSearchResultPage extends AbstractTextSearchViewPage { throw new PartInitException("Search Result Error", e); //$NON-NLS-1$ } } + /** + * @param sortOrder + */ + public void setSortOrder(int sortOrder) { + _currentSortOrder= sortOrder; + StructuredViewer viewer= getViewer(); + CountLabelProvider lpWrapper= (CountLabelProvider) viewer.getLabelProvider(); + ((CSearchResultLabelProvider)lpWrapper.getLabelProvider()).setOrder(sortOrder); + + if (sortOrder == CSearchResultLabelProvider.SHOW_ELEMENT_CONTAINER) { + viewer.setSorter(new ElementNameSorter()); + } else if (sortOrder == CSearchResultLabelProvider.SHOW_PATH) { + viewer.setSorter(new PathNameSorter()); + } else + viewer.setSorter(new ParentNameSorter()); + + } + + protected void fillContextMenu(IMenuManager mgr) { + super.fillContextMenu(mgr); + addSortActions(mgr); + //fActionGroup.setContext(new ActionContext(getSite().getSelectionProvider().getSelection())); + //fActionGroup.fillContextMenu(mgr); + } + + private void addSortActions(IMenuManager mgr) { + if (getLayout() != FLAG_LAYOUT_FLAT) + return; + MenuManager sortMenu= new MenuManager(CSearchMessages.getString("CSearchResultPage.sort")); //$NON-NLS-1$ + sortMenu.add(_elementNameSortAction); + sortMenu.add(_pathSortAction); + sortMenu.add(_parentSortAction); + + _elementNameSortAction.setChecked(_currentSortOrder == _elementNameSortAction.getSortOrder()); + _pathSortAction.setChecked(_currentSortOrder == _pathSortAction.getSortOrder()); + _parentSortAction.setChecked(_currentSortOrder == _parentSortAction.getSortOrder()); + + mgr.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, sortMenu); + } + + private void addGroupActions(IToolBarManager mgr) { + mgr.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, _groupProjectAction); + mgr.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, _groupNamespaceAction); + mgr.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, _groupFileAction); + //mgr.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, fGroupTypeAction); + + updateGroupingActions(); + } + + + /** + * @param _grouping + */ + public void setGrouping(int groupOrder) { + _currentGrouping = groupOrder; + StructuredViewer viewer= getViewer(); + LevelTreeContentProvider cp= (LevelTreeContentProvider) viewer.getContentProvider(); + cp.setLevel(groupOrder); + updateGroupingActions(); + getSettings().put(KEY_GROUPING, _currentGrouping); + } + + + private void updateGroupingActions() { + _groupProjectAction.setChecked(_currentGrouping == LevelTreeContentProvider.LEVEL_PROJECT); + _groupNamespaceAction.setChecked(_currentGrouping == LevelTreeContentProvider.LEVEL_NAMESPACE); + _groupFileAction.setChecked(_currentGrouping == LevelTreeContentProvider.LEVEL_FILE); + } + + protected void fillToolbar(IToolBarManager tbm) { + super.fillToolbar(tbm); + if (getLayout() != FLAG_LAYOUT_FLAT) + addGroupActions(tbm); + } + + } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/ElementNameSorter.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/ElementNameSorter.java index 2e8bbae4b75..657644e72c4 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/ElementNameSorter.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/ElementNameSorter.java @@ -13,14 +13,11 @@ */ package org.eclipse.cdt.internal.ui.search; -import org.eclipse.cdt.ui.CSearchResultLabelProvider; -import org.eclipse.core.resources.IMarker; -import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.search.BasicSearchMatch; +import org.eclipse.core.resources.IResource; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerSorter; -import org.eclipse.search.ui.ISearchResultView; -import org.eclipse.search.ui.ISearchResultViewEntry; -import org.eclipse.search.ui.SearchUI; /** * @author aniefer @@ -30,64 +27,24 @@ import org.eclipse.search.ui.SearchUI; */ public class ElementNameSorter extends ViewerSorter { - public int compare( Viewer viewer, Object e1, Object e2 ){ - String name1 = null, name2 = null; - - ISearchResultViewEntry entry1 = null; - ISearchResultViewEntry entry2 = null; - - if (e1 instanceof ISearchResultViewEntry){ - name1 = _labelProvider.getText(e1); - entry1 = (ISearchResultViewEntry)e1; - } - - if (e2 instanceof ISearchResultViewEntry){ - name2 = _labelProvider.getText(e2); - entry2 = (ISearchResultViewEntry)e2; - } - - if (name1 == null) - name1= ""; //$NON-NLS-1$ - - if (name2 == null) - name2= ""; //$NON-NLS-1$ - - int compare = getCollator().compare( name1, name2 ); - - if( compare == 0 ){ - int startPos1 = -1; - int startPos2 = -1; - IMarker marker1 = entry1.getSelectedMarker(); - IMarker marker2 = entry2.getSelectedMarker(); - - if (marker1 != null) - startPos1 = marker1.getAttribute( IMarker.CHAR_START, -1 ); - if (marker2 != null) - startPos2 = marker2.getAttribute( IMarker.CHAR_START, -1 ); - - compare = startPos1 - startPos2; - } - - return compare; + public int compare(Viewer viewer, Object e1, Object e2) { + String property1= getProperty(e1); + String property2= getProperty(e2); + return collator.compare(property1, property2); } - public boolean isSorterProperty( Object element, String property ){ + protected String getProperty(Object element) { + if (element instanceof ICElement) + return ((ICElement)element).getElementName(); + if (element instanceof IResource) + return ((IResource)element).getName(); + if (element instanceof BasicSearchMatch) + return ((BasicSearchMatch) element).getName(); + return ""; //$NON-NLS-1$ + } + + public boolean isSorterProperty(Object element, String property) { return true; } - public void sort( Viewer viewer, Object[] elements ) { - // Set label provider to show "element - path" - ISearchResultView view = SearchUI.getSearchResultView(); - if (view == null) - return; - - _labelProvider = view.getLabelProvider(); - - if( _labelProvider instanceof CSearchResultLabelProvider ) { - ((CSearchResultLabelProvider)_labelProvider).setOrder( CSearchResultLabelProvider.SHOW_ELEMENT_CONTAINER ); - super.sort( viewer, elements ); - } - } - - private ILabelProvider _labelProvider; } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/LevelTreeContentProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/LevelTreeContentProvider.java index 29d19df4521..96b7136c1a2 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/LevelTreeContentProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/LevelTreeContentProvider.java @@ -39,6 +39,10 @@ public class LevelTreeContentProvider extends CSearchContentProvider implements {IResource.ROOT}}; private static final int MAX_LEVEL= C_ELEMENT_TYPES.length - 1; private int fCurrentLevel; + + public static final int LEVEL_FILE= 1; + public static final int LEVEL_NAMESPACE= 2; + public static final int LEVEL_PROJECT= 3; public LevelTreeContentProvider(AbstractTreeViewer viewer, int level) { fTreeViewer= viewer; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/ParentNameSorter.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/ParentNameSorter.java index 2b8000e70dc..33533d76fa7 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/ParentNameSorter.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/ParentNameSorter.java @@ -13,14 +13,10 @@ */ package org.eclipse.cdt.internal.ui.search; -import org.eclipse.cdt.ui.CSearchResultLabelProvider; -import org.eclipse.core.resources.IMarker; -import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.search.BasicSearchMatch; +import org.eclipse.core.resources.IResource; import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerSorter; -import org.eclipse.search.ui.ISearchResultView; -import org.eclipse.search.ui.ISearchResultViewEntry; -import org.eclipse.search.ui.SearchUI; /** * @author aniefer @@ -28,73 +24,29 @@ import org.eclipse.search.ui.SearchUI; * To change the template for this generated type comment go to * Window>Preferences>Java>Code Generation>Code and Comments */ -public class ParentNameSorter extends ViewerSorter { - +public class ParentNameSorter extends ElementNameSorter { + public int compare(Viewer viewer, Object e1, Object e2) { - String name1= null; - String name2= null; - - ISearchResultViewEntry entry1 = null; - ISearchResultViewEntry entry2 = null; - - if (e1 instanceof ISearchResultViewEntry){ - name1 = _labelProvider.getText(e1); - entry1 = (ISearchResultViewEntry)e1; - } - - if (e2 instanceof ISearchResultViewEntry){ - name2 = _labelProvider.getText(e2); - entry2 = (ISearchResultViewEntry)e2; - } - - if (name1 == null) - name1= ""; //$NON-NLS-1$ - - if (name2 == null) - name2= ""; //$NON-NLS-1$ - - int compare = getCollator().compare( name1, name2 ); - - if( compare == 0 ){ - int startPos1 = -1; - int startPos2 = -1; - IMarker marker1 = entry1.getSelectedMarker(); - IMarker marker2 = entry2.getSelectedMarker(); - - if (marker1 != null) - startPos1 = marker1.getAttribute( IMarker.CHAR_START, -1 ); - if (marker2 != null) - startPos2 = marker2.getAttribute( IMarker.CHAR_START, -1 ); - - compare = startPos1 - startPos2; - } - - return compare; - } - - /* - * Overrides method from ViewerSorter - */ - public boolean isSorterProperty(Object element, String property) { - return true; - } - - /* - * Overrides method from ViewerSorter - */ - public void sort(Viewer viewer, Object[] elements) { - // Set label provider to show "path - resource" - ISearchResultView view = SearchUI.getSearchResultView(); - if (view == null) - return; - - _labelProvider = view.getLabelProvider(); - - if( _labelProvider instanceof CSearchResultLabelProvider ) - ((CSearchResultLabelProvider)_labelProvider).setOrder( CSearchResultLabelProvider.SHOW_CONTAINER_ELEMENT ); - - super.sort( viewer, elements ); + String leftParent= getParentName(e1); + String rightParent= getParentName(e2); + return collator.compare(leftParent, rightParent); } - private ILabelProvider _labelProvider; + private String getParentName(Object element) { + if (element instanceof ICElement) { + ICElement parent= ((ICElement)element).getParent(); + + if (parent != null) + return parent.getElementName(); + } + if (element instanceof IResource) { + IResource parent= ((IResource)element).getParent(); + if (parent != null) + return parent.getName(); + } + if (element instanceof BasicSearchMatch){ + return ((BasicSearchMatch) element).getParentName(); + } + return ""; //$NON-NLS-1$ + } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PathNameSorter.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PathNameSorter.java index 79216ae4364..4292a7f7146 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PathNameSorter.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PathNameSorter.java @@ -13,15 +13,12 @@ */ package org.eclipse.cdt.internal.ui.search; -import org.eclipse.cdt.core.search.IMatch; -import org.eclipse.cdt.ui.CSearchResultLabelProvider; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.search.BasicSearchMatch; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerSorter; -import org.eclipse.search.ui.ISearchResultView; -import org.eclipse.search.ui.ISearchResultViewEntry; -import org.eclipse.search.ui.SearchUI; /** * @author aniefer @@ -29,87 +26,35 @@ import org.eclipse.search.ui.SearchUI; * To change the template for this generated type comment go to * Window>Preferences>Java>Code Generation>Code and Comments */ -public class PathNameSorter extends ViewerSorter { +public class PathNameSorter extends ElementNameSorter { - /* - * Overrides method from ViewerSorter - */ public int compare(Viewer viewer, Object e1, Object e2) { - String name1 = null; - String name2 = null; - ISearchResultViewEntry entry1 = null; - ISearchResultViewEntry entry2 = null; - IMatch match1 = null; - IMatch match2 = null; - - if( e1 instanceof ISearchResultViewEntry ) { - entry1 = (ISearchResultViewEntry)e1; - try { - match1 = (IMatch)entry1.getSelectedMarker().getAttribute( CSearchResultCollector.IMATCH ); - } catch (CoreException e) { - } - if( match1 == null ){ - return 0; - } - name1 = match1.getLocation().toString(); - } - if( e2 instanceof ISearchResultViewEntry ) { - entry2 = (ISearchResultViewEntry)e2; - try { - match2 = (IMatch)entry2.getSelectedMarker().getAttribute( CSearchResultCollector.IMATCH ); - } catch (CoreException e) { - } - if( match2 == null ){ - return 0; - } - //name2 = _labelProvider.getText( e2 ); - name2 = match2.getLocation().toString(); - } - - if( name1 == null ) - name1 = ""; //$NON-NLS-1$ - - if( name2 == null ) - name2 = ""; //$NON-NLS-1$ - - int compare = getCollator().compare( name1, name2 ); - - if( compare == 0 ){ - int startPos1 = -1; - int startPos2 = -1; - - if (match1 != null) - startPos1 = match1.getStartOffset(); - if (match2 != null) - startPos2 = match2.getStartOffset(); - - compare = startPos1 - startPos2; - } - - return compare; - } - - /* - * Overrides method from ViewerSorter - */ - public boolean isSorterProperty(Object element, String property) { - return true; - } - - /* - * Overrides method from ViewerSorter - */ - public void sort( Viewer viewer, Object[] elements ) { - // Set label provider to show "path - resource" - ISearchResultView view = SearchUI.getSearchResultView(); - if( view == null ) - return; - - _labelProvider = view.getLabelProvider(); - if( _labelProvider instanceof CSearchResultLabelProvider ) - ((CSearchResultLabelProvider)_labelProvider).setOrder( CSearchResultLabelProvider.SHOW_PATH ); - super.sort( viewer, elements ); + IPath path1= getPath(e1); + IPath path2=getPath(e2); + return compare(path1, path2); } - private ILabelProvider _labelProvider; + /** + * @param e1 + * @return + */ + private IPath getPath(Object element) { + if (element instanceof ICElement) + return ((ICElement)element).getPath(); + if (element instanceof IResource) + return ((IResource)element).getFullPath(); + if (element instanceof BasicSearchMatch) + return ((BasicSearchMatch) element).getLocation(); + return new Path(""); //$NON-NLS-1$ + } + + protected int compare(IPath path1, IPath path2) { + int segmentCount= Math.min(path1.segmentCount(), path2.segmentCount()); + for (int i= 0; i < segmentCount; i++) { + int value= collator.compare(path1.segment(i), path2.segment(i)); + if (value != 0) + return value; + } + return path1.segmentCount() - path2.segmentCount(); + } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/GroupAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/GroupAction.java new file mode 100644 index 00000000000..fe784e37640 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/GroupAction.java @@ -0,0 +1,30 @@ +/* + * Created on May 15, 2004 + * + * TODO To change the template for this generated file go to + * Window - Preferences - Java - Code Style - Code Templates + */ +package org.eclipse.cdt.internal.ui.search.actions; + +import org.eclipse.cdt.internal.ui.search.CSearchResultPage; +import org.eclipse.jface.action.Action; + +public class GroupAction extends Action { + private int _grouping; + private CSearchResultPage _page; + + public GroupAction(String label, String tooltip, CSearchResultPage page, int grouping) { + super(label); + setToolTipText(tooltip); + _page= page; + _grouping= grouping; + } + + public void run() { + _page.setGrouping(_grouping); + } + + public int getGrouping() { + return _grouping; + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/SortAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/SortAction.java new file mode 100644 index 00000000000..6c432d7a134 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/SortAction.java @@ -0,0 +1,31 @@ +/* + * Created on May 14, 2004 + * + * TODO To change the template for this generated file go to + * Window - Preferences - Java - Code Style - Code Templates + */ +package org.eclipse.cdt.internal.ui.search.actions; + +import org.eclipse.cdt.internal.ui.search.CSearchResultPage; +import org.eclipse.jface.action.Action; + +public class SortAction extends Action { + + private int fSortOrder; + private CSearchResultPage fPage; + + public SortAction(String label, CSearchResultPage page, int sortOrder) { + super(label); + fPage= page; + fSortOrder= sortOrder; + } + + public void run() { + fPage.setSortOrder(fSortOrder); + } + + public int getSortOrder() { + return fSortOrder; + } + +}