mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-29 20:05:35 +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;
|
package org.eclipse.cdt.internal.ui.search;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
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.cdt.internal.core.pdom.dom.PDOMName;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
|
||||||
|
@ -24,15 +23,17 @@ import org.eclipse.core.runtime.CoreException;
|
||||||
public class PDOMSearchElement {
|
public class PDOMSearchElement {
|
||||||
|
|
||||||
private final PDOMBinding binding;
|
private final PDOMBinding binding;
|
||||||
private final PDOMFile file;
|
private final String name;
|
||||||
|
private final String filename;
|
||||||
|
|
||||||
public PDOMSearchElement(PDOMName name) throws CoreException {
|
public PDOMSearchElement(PDOMName name) throws CoreException {
|
||||||
binding = name.getPDOMBinding();
|
binding = name.getPDOMBinding();
|
||||||
file = name.getFile();
|
this.name = binding.getName();
|
||||||
|
filename = name.getFile().getFileName().getString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return binding.getRecord() + file.getRecord();
|
return name.hashCode() + filename.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
|
@ -41,12 +42,12 @@ public class PDOMSearchElement {
|
||||||
if (this == obj)
|
if (this == obj)
|
||||||
return true;
|
return true;
|
||||||
PDOMSearchElement other = (PDOMSearchElement)obj;
|
PDOMSearchElement other = (PDOMSearchElement)obj;
|
||||||
return binding.equals(other.binding)
|
return name.equals(other.name)
|
||||||
&& file.equals(other.file);
|
&& filename.equals(other.filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PDOMFile getFile() {
|
public String getFileName() {
|
||||||
return file;
|
return filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PDOMBinding getBinding() {
|
public PDOMBinding getBinding() {
|
||||||
|
|
|
@ -12,8 +12,6 @@
|
||||||
package org.eclipse.cdt.internal.ui.search;
|
package org.eclipse.cdt.internal.ui.search;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.IndexLabelProvider;
|
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.search.ui.text.AbstractTextSearchViewPage;
|
||||||
import org.eclipse.swt.graphics.Image;
|
import org.eclipse.swt.graphics.Image;
|
||||||
|
|
||||||
|
@ -39,13 +37,7 @@ public class PDOMSearchListLabelProvider extends IndexLabelProvider {
|
||||||
public String getText(Object element) {
|
public String getText(Object element) {
|
||||||
if (element instanceof PDOMSearchElement) {
|
if (element instanceof PDOMSearchElement) {
|
||||||
PDOMSearchElement searchElement = (PDOMSearchElement)element;
|
PDOMSearchElement searchElement = (PDOMSearchElement)element;
|
||||||
String filename = null;
|
String filename = " - " + searchElement.getFileName(); //$NON-NLS-1$
|
||||||
try {
|
|
||||||
filename = " - " + searchElement.getFile().getFileName().getString(); //$NON-NLS-1$
|
|
||||||
} catch (CoreException e) {
|
|
||||||
CUIPlugin.getDefault().log(e);
|
|
||||||
filename = ""; //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
int count = page.getInput().getMatchCount(element);
|
int count = page.getInput().getMatchCount(element);
|
||||||
return getText(searchElement.getBinding()) + filename + " " //$NON-NLS-1$
|
return getText(searchElement.getBinding()) + filename + " " //$NON-NLS-1$
|
||||||
+ CSearchMessages.getFormattedString("CSearchResultCollector.matches", new Integer(count)); //$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 {
|
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.ICElement;
|
||||||
import org.eclipse.cdt.core.model.ICProject;
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
import org.eclipse.cdt.core.model.ISourceRoot;
|
import org.eclipse.cdt.core.model.ISourceRoot;
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.resources.ResourcesPlugin;
|
import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
import org.eclipse.jface.viewers.ITreeContentProvider;
|
import org.eclipse.jface.viewers.ITreeContentProvider;
|
||||||
|
@ -94,8 +92,7 @@ public class PDOMSearchTreeContentProvider implements ITreeContentProvider, IPDO
|
||||||
}
|
}
|
||||||
|
|
||||||
private void insertSearchElement(PDOMSearchElement element) {
|
private void insertSearchElement(PDOMSearchElement element) {
|
||||||
try {
|
IPath path = new Path(element.getFileName());
|
||||||
IPath path = new Path(element.getFile().getFileName().getString());
|
|
||||||
IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(path);
|
IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(path);
|
||||||
if (files.length > 0) {
|
if (files.length > 0) {
|
||||||
for (int j = 0; j < files.length; ++j) {
|
for (int j = 0; j < files.length; ++j) {
|
||||||
|
@ -108,9 +105,6 @@ public class PDOMSearchTreeContentProvider implements ITreeContentProvider, IPDO
|
||||||
insertChild(pathName, element);
|
insertChild(pathName, element);
|
||||||
insertChild(result, pathName);
|
insertChild(result, pathName);
|
||||||
}
|
}
|
||||||
} catch (CoreException e) {
|
|
||||||
CUIPlugin.getDefault().log(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void insertCElement(ICElement element) {
|
private void insertCElement(ICElement element) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue