### Eclipse Workspace Patch 1.0 #P org.eclipse.ui.ide Index: extensions/org/eclipse/ui/dialogs/FilteredResourcesSelectionDialog.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/extensions/org/eclipse/ui/dialogs/FilteredResourcesSelectionDialog.java,v retrieving revision 1.16 diff -u -r1.16 FilteredResourcesSelectionDialog.java --- extensions/org/eclipse/ui/dialogs/FilteredResourcesSelectionDialog.java 21 Mar 2007 15:46:13 -0000 1.16 +++ extensions/org/eclipse/ui/dialogs/FilteredResourcesSelectionDialog.java 19 May 2008 10:57:43 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. + * Copyright (c) 2000, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -25,9 +25,12 @@ import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.ListenerList; +import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IAction; @@ -40,6 +43,7 @@ import org.eclipse.jface.viewers.ILabelDecorator; import org.eclipse.jface.viewers.ILabelProviderListener; import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.LabelProviderChangedEvent; import org.eclipse.jface.viewers.Viewer; @@ -95,8 +99,13 @@ private String title; + protected ResourceFilter filter; + private IContainer container; + /** The Container to use for searching for relative resources */ + private IContainer searchContainer; + private int typeMask; private boolean isDerived; @@ -123,6 +132,41 @@ PlatformUI.getWorkbench().getHelpSystem().setHelp(shell, IIDEHelpContextIds.OPEN_RESOURCE_DIALOG); + + /* + * Allow location of paths relative to "searchContainer" + * - searchContainer is the container of the currently active editor + * - or the first container found as a result of querying the selection service + */ + IWorkbenchWindow ww = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + if (ww != null) { + Object[] selection = new Object[0]; + ISelection isel = ww.getSelectionService().getSelection(); + // Search for an Active Editor + if (ww.getActivePage() != null) + if (ww.getActivePage().getActiveEditor() != null) + selection = new Object[] {ww.getActivePage().getActiveEditor().getEditorInput()}; + // Else get active selection if IStructuredSelection + if (selection.length == 0 && isel instanceof IStructuredSelection) + selection = ((IStructuredSelection)isel).toArray(); + + // Iterate over the Objects trying to adapt them to IResource + for (int i = 0 ; i < selection.length ; ++i) { + if (selection[i] instanceof IAdaptable) { + IResource res = (IResource)((IAdaptable)selection[i]).getAdapter(IResource.class); + if (res != null) { + if (res instanceof IContainer) + searchContainer = (IContainer)res; + else + searchContainer = res.getParent(); + break; + } + } + } + } + if (searchContainer == null) + searchContainer = container; + this.container = container; this.typeMask = typesMask; @@ -375,7 +419,8 @@ * @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog#createFilter() */ protected ItemsFilter createFilter() { - return new ResourceFilter(container, isDerived, typeMask); + filter = new ResourceFilter(container, searchContainer, isDerived, typeMask); + return filter; } /* (non-Javadoc) @@ -405,11 +450,31 @@ IResource resource2 = (IResource) o2; String s1 = resource1.getName(); String s2 = resource2.getName(); + // Compare their names int comparability = collator.compare(s1, s2); if (comparability == 0) { - s1 = resource1.getFullPath().toString(); - s2 = resource2.getFullPath().toString(); - comparability = collator.compare(s1, s2); + + // Sort resource relative first + if ((filter.matchesResourceRelativeFilter(resource1) && + !filter.matchesResourceRelativeFilter(resource2)) || + (filter.matchesResourceRelativeFilter(resource2) && + !filter.matchesResourceRelativeFilter(resource1))) { + if (filter.matchesResourceRelativeFilter(resource1)) + return -1; + return 1; + } + + // Finall compare fullpaths; shorter paths sorted first + IPath p1 = resource1.getFullPath(); + IPath p2 = resource2.getFullPath(); + int c1 = p1.segmentCount(); + int c2 = p2.segmentCount(); + for (int i= 0; i < c1 && i < c2; i++) { + comparability = collator.compare(p1.segment(i), p2.segment(i)); + if (comparability != 0) + return comparability; + } + comparability = c2 - c1; } return comparability; @@ -744,6 +809,9 @@ private IContainer filterContainer; + /** Search pattern for resource relative lookups */ + protected SearchPattern resourceRelativePattern = new SearchPattern(); + private int filterTypeMask; /** @@ -754,22 +822,37 @@ * flag which determine showing derived elements * @param typeMask */ - public ResourceFilter(IContainer container, boolean showDerived, - int typeMask) { + public ResourceFilter(IContainer container, IContainer searchContainer, + boolean showDerived, int typeMask) { super(); this.filterContainer = container; this.showDerived = showDerived; this.filterTypeMask = typeMask; + + String stringPattern = getPattern(); + + // If pattern looks relative then add path + stringPattern = searchContainer.getFullPath() + .append(stringPattern).toOSString(); + resourceRelativePattern.setPattern(stringPattern); } /** * Creates new ResourceFilter instance */ public ResourceFilter() { - super(); - this.filterContainer = container; - this.showDerived = isDerived; - this.filterTypeMask = typeMask; + this(container, searchContainer, isDerived, typeMask); + } + + /** + * Creates new Resource Filter which additionally filters + * on resource relative path + * + * @param searchPattern + * the pattern to be used when filtering + */ + public ResourceFilter(SearchPattern searchPattern) { + super (searchPattern); } /** @@ -783,7 +866,7 @@ return false; } IResource resource = (IResource) item; - if (this.filterContainer.findMember(resource.getFullPath()) != null) + if (this.filterContainer.getFullPath().isPrefixOf(resource.getFullPath())) return true; return false; } @@ -802,7 +885,24 @@ if ((!this.showDerived && resource.isDerived()) || ((this.filterTypeMask & resource.getType()) == 0)) return false; - return matches(resource.getName()); + + if (matches(resource.getName()) || + // Allow matching of full path + matches (resource.getFullPath().toOSString()) || + // Allow matching of path relative to current selection + matchesResourceRelativeFilter(resource)) + return true; + + return false; + } + + /** + * Return true if the passed in item matches the resource relative filter + * @param item + * @return + */ + public boolean matchesResourceRelativeFilter(IResource item) { + return resourceRelativePattern.matches(item.getFullPath().toOSString()); } /* @@ -813,9 +913,13 @@ public boolean isSubFilter(ItemsFilter filter) { if (!super.isSubFilter(filter)) return false; - if (filter instanceof ResourceFilter) - if (this.showDerived == ((ResourceFilter) filter).showDerived) - return true; + if (filter instanceof ResourceFilter && + this.showDerived == ((ResourceFilter) filter).showDerived) { + // super.isSubFilter checks whether this pattern is more general than 'filter' pattern + // Also check that the resource relative filter. For relative paths ../../ etc. + IPath otherPath = new Path(((ResourceFilter)filter).resourceRelativePattern.getPattern()); + return (otherPath.segmentCount() >= new Path(resourceRelativePattern.getPattern()).segmentCount()); + } return false; } Index: extensions/org/eclipse/ui/actions/BuildAction.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/BuildAction.java,v retrieving revision 1.19 diff -u -r1.19 BuildAction.java --- extensions/org/eclipse/ui/actions/BuildAction.java 19 Jul 2006 21:34:36 -0000 1.19 +++ extensions/org/eclipse/ui/actions/BuildAction.java 19 May 2008 10:57:42 -0000 @@ -279,8 +279,7 @@ // Save all resources prior to doing build BuildUtilities.saveEditors(projects); - runInBackground(ResourcesPlugin.getWorkspace().getRuleFactory() - .buildRule(), ResourcesPlugin.FAMILY_MANUAL_BUILD); + runInBackground(null, ResourcesPlugin.FAMILY_MANUAL_BUILD); } /* (non-Javadoc)