mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 08:55:25 +02:00
Fixed up the search element and search match to eliminate duplicate matches from multiple projects.
This commit is contained in:
parent
0fb9f4e4f2
commit
6334301ac3
4 changed files with 36 additions and 37 deletions
|
@ -12,7 +12,6 @@
|
|||
package org.eclipse.cdt.internal.ui.search;
|
||||
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
|
@ -24,15 +23,17 @@ import org.eclipse.core.runtime.CoreException;
|
|||
public class PDOMSearchElement {
|
||||
|
||||
private final PDOMBinding binding;
|
||||
private final PDOMFile file;
|
||||
private final String name;
|
||||
private final String filename;
|
||||
|
||||
public PDOMSearchElement(PDOMName name) throws CoreException {
|
||||
binding = name.getPDOMBinding();
|
||||
file = name.getFile();
|
||||
this.name = binding.getName();
|
||||
filename = name.getFile().getFileName().getString();
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return binding.getRecord() + file.getRecord();
|
||||
return name.hashCode() + filename.hashCode();
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
|
@ -41,16 +42,16 @@ public class PDOMSearchElement {
|
|||
if (this == obj)
|
||||
return true;
|
||||
PDOMSearchElement other = (PDOMSearchElement)obj;
|
||||
return binding.equals(other.binding)
|
||||
&& file.equals(other.file);
|
||||
return name.equals(other.name)
|
||||
&& filename.equals(other.filename);
|
||||
}
|
||||
|
||||
public PDOMFile getFile() {
|
||||
return file;
|
||||
public String getFileName() {
|
||||
return filename;
|
||||
}
|
||||
|
||||
|
||||
public PDOMBinding getBinding() {
|
||||
return binding;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,8 +12,6 @@
|
|||
package org.eclipse.cdt.internal.ui.search;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.IndexLabelProvider;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
|
||||
|
@ -39,13 +37,7 @@ public class PDOMSearchListLabelProvider extends IndexLabelProvider {
|
|||
public String getText(Object element) {
|
||||
if (element instanceof PDOMSearchElement) {
|
||||
PDOMSearchElement searchElement = (PDOMSearchElement)element;
|
||||
String filename = null;
|
||||
try {
|
||||
filename = " - " + searchElement.getFile().getFileName().getString(); //$NON-NLS-1$
|
||||
} catch (CoreException e) {
|
||||
CUIPlugin.getDefault().log(e);
|
||||
filename = ""; //$NON-NLS-1$
|
||||
}
|
||||
String filename = " - " + searchElement.getFileName(); //$NON-NLS-1$
|
||||
int count = page.getInput().getMatchCount(element);
|
||||
return getText(searchElement.getBinding()) + filename + " " //$NON-NLS-1$
|
||||
+ CSearchMessages.getFormattedString("CSearchResultCollector.matches", new Integer(count)); //$NON-NLS-1$
|
||||
|
|
|
@ -26,6 +26,18 @@ public class PDOMSearchMatch extends Match {
|
|||
}
|
||||
|
||||
public String getFileName() throws CoreException {
|
||||
return ((PDOMSearchElement)getElement()).getFile().getFileName().getString();
|
||||
return ((PDOMSearchElement)getElement()).getFileName();
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == this)
|
||||
return true;
|
||||
if (!(obj instanceof PDOMSearchMatch))
|
||||
return false;
|
||||
PDOMSearchMatch other = (PDOMSearchMatch)obj;
|
||||
return getElement().equals(other.getElement())
|
||||
&& getOffset() == other.getOffset()
|
||||
&& getLength() == other.getLength();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -21,11 +21,9 @@ import org.eclipse.cdt.core.model.CoreModel;
|
|||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.ISourceRoot;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.jface.viewers.ITreeContentProvider;
|
||||
|
@ -94,22 +92,18 @@ public class PDOMSearchTreeContentProvider implements ITreeContentProvider, IPDO
|
|||
}
|
||||
|
||||
private void insertSearchElement(PDOMSearchElement element) {
|
||||
try {
|
||||
IPath path = new Path(element.getFile().getFileName().getString());
|
||||
IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(path);
|
||||
if (files.length > 0) {
|
||||
for (int j = 0; j < files.length; ++j) {
|
||||
ICElement celement = CoreModel.getDefault().create(files[j]);
|
||||
insertChild(celement, element);
|
||||
insertCElement(celement);
|
||||
}
|
||||
} else {
|
||||
String pathName = path.toOSString();
|
||||
insertChild(pathName, element);
|
||||
insertChild(result, pathName);
|
||||
IPath path = new Path(element.getFileName());
|
||||
IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(path);
|
||||
if (files.length > 0) {
|
||||
for (int j = 0; j < files.length; ++j) {
|
||||
ICElement celement = CoreModel.getDefault().create(files[j]);
|
||||
insertChild(celement, element);
|
||||
insertCElement(celement);
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
CUIPlugin.getDefault().log(e);
|
||||
} else {
|
||||
String pathName = path.toOSString();
|
||||
insertChild(pathName, element);
|
||||
insertChild(result, pathName);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue