mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-11 11:05:24 +02:00
Bug 212166, search bug fixes.
This commit is contained in:
parent
79d4ec2886
commit
00ea007d4e
2 changed files with 83 additions and 14 deletions
|
@ -88,6 +88,8 @@ public final class CSearchMessages extends NLS {
|
||||||
public static String PDOMSearchListContentProvider_IndexerNotEnabledMessageFormat;
|
public static String PDOMSearchListContentProvider_IndexerNotEnabledMessageFormat;
|
||||||
public static String PDOMSearchListContentProvider_ProjectClosedMessageFormat;
|
public static String PDOMSearchListContentProvider_ProjectClosedMessageFormat;
|
||||||
public static String CSearchMessages_IndexRunningIncompleteWarning;
|
public static String CSearchMessages_IndexRunningIncompleteWarning;
|
||||||
|
public static String PDOMSearchTreeContentProvider_IndexerNotEnabledWarning;
|
||||||
|
public static String PDOMSearchTreeContentProvider_ProjectClosedWarning;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
NLS.initializeMessages(BUNDLE_NAME, CSearchMessages.class);
|
NLS.initializeMessages(BUNDLE_NAME, CSearchMessages.class);
|
||||||
|
|
|
@ -23,17 +23,21 @@ 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.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
|
import org.eclipse.core.runtime.Status;
|
||||||
import org.eclipse.jface.viewers.ITreeContentProvider;
|
import org.eclipse.jface.viewers.ITreeContentProvider;
|
||||||
import org.eclipse.jface.viewers.TreeViewer;
|
import org.eclipse.jface.viewers.TreeViewer;
|
||||||
import org.eclipse.jface.viewers.Viewer;
|
import org.eclipse.jface.viewers.Viewer;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||||
import org.eclipse.cdt.core.index.IndexLocationFactory;
|
import org.eclipse.cdt.core.index.IndexLocationFactory;
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Doug Schaefer
|
* @author Doug Schaefer
|
||||||
|
@ -76,23 +80,40 @@ public class PDOMSearchTreeContentProvider implements ITreeContentProvider, IPDO
|
||||||
|
|
||||||
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
||||||
this.viewer = (TreeViewer)viewer;
|
this.viewer = (TreeViewer)viewer;
|
||||||
result = (PDOMSearchResult)newInput;
|
this.result = (PDOMSearchResult) newInput;
|
||||||
tree.clear();
|
initialize(result);
|
||||||
if (result != null) {
|
viewer.refresh();
|
||||||
Object[] elements = result.getElements();
|
|
||||||
for (int i = 0; i < elements.length; ++i) {
|
|
||||||
insertSearchElement((PDOMSearchElement)elements[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void insertChild(Object parent, Object child) {
|
/**
|
||||||
|
* Add a message to a project node indicating it has no results because indexer is disabled.
|
||||||
|
* @param project
|
||||||
|
*/
|
||||||
|
private void insertUnindexedProjectWarningElement(ICProject project) {
|
||||||
|
insertCElement(project);
|
||||||
|
insertChild(project,
|
||||||
|
new Status(IStatus.WARNING, CUIPlugin.PLUGIN_ID,
|
||||||
|
CSearchMessages.PDOMSearchTreeContentProvider_IndexerNotEnabledWarning));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a message to a project node indicating it has no results because project is closed
|
||||||
|
* @param project
|
||||||
|
*/
|
||||||
|
private void insertClosedProjectWarningElement(ICProject project) {
|
||||||
|
insertCElement(project);
|
||||||
|
insertChild(project,
|
||||||
|
new Status(IStatus.WARNING, CUIPlugin.PLUGIN_ID,
|
||||||
|
CSearchMessages.PDOMSearchTreeContentProvider_ProjectClosedWarning));
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean insertChild(Object parent, Object child) {
|
||||||
Set children = (Set)tree.get(parent);
|
Set children = (Set)tree.get(parent);
|
||||||
if (children == null) {
|
if (children == null) {
|
||||||
children = new HashSet();
|
children = new HashSet();
|
||||||
tree.put(parent, children);
|
tree.put(parent, children);
|
||||||
}
|
}
|
||||||
children.add(child);
|
return children.add(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void insertSearchElement(PDOMSearchElement element) {
|
private void insertSearchElement(PDOMSearchElement element) {
|
||||||
|
@ -148,20 +169,66 @@ public class PDOMSearchTreeContentProvider implements ITreeContentProvider, IPDO
|
||||||
if (elements != null) {
|
if (elements != null) {
|
||||||
for (int i = 0; i < elements.length; ++i) {
|
for (int i = 0; i < elements.length; ++i) {
|
||||||
PDOMSearchElement element = (PDOMSearchElement)elements[i];
|
PDOMSearchElement element = (PDOMSearchElement)elements[i];
|
||||||
if (result.getMatchCount(element) > 0)
|
if (result.getMatchCount(element) > 0) {
|
||||||
insertSearchElement(element);
|
insertSearchElement(element);
|
||||||
else
|
} else {
|
||||||
|
boolean remove = true;
|
||||||
|
if (element instanceof ICProject) {
|
||||||
|
ICProject cProject = (ICProject) element;
|
||||||
|
remove = !addProjectWarningIfApplicable(cProject);
|
||||||
|
}
|
||||||
|
if (remove) {
|
||||||
remove(element);
|
remove(element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (!viewer.getTree().isDisposed()) {
|
if (!viewer.getTree().isDisposed()) {
|
||||||
viewer.refresh();
|
viewer.refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean addProjectWarningIfApplicable(ICProject cProject) {
|
||||||
|
if (cProject.isOpen()) {
|
||||||
|
if (!CCorePlugin.getIndexManager().isProjectIndexed(cProject)) {
|
||||||
|
insertUnindexedProjectWarningElement(cProject);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
insertClosedProjectWarningElement(cProject);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public void clear() {
|
public void clear() {
|
||||||
|
initialize(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initialize(final PDOMSearchResult result) {
|
||||||
|
this.result = result;
|
||||||
tree.clear();
|
tree.clear();
|
||||||
viewer.refresh();
|
if (result != null) {
|
||||||
|
// if indexer was busy, record that
|
||||||
|
if (result.wasIndexerBusy()) {
|
||||||
|
insertChild(result, IPDOMSearchContentProvider.INCOMPLETE_RESULTS_NODE);
|
||||||
|
}
|
||||||
|
|
||||||
|
Object[] elements = result.getElements();
|
||||||
|
for (int i = 0; i < elements.length; ++i) {
|
||||||
|
insertSearchElement((PDOMSearchElement)elements[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// add all the projects which have no results
|
||||||
|
ICProject[] projects = ((PDOMSearchQuery)result.getQuery()).getProjects();
|
||||||
|
for (int i = 0; i < projects.length; ++i) {
|
||||||
|
ICProject project = projects[i];
|
||||||
|
Object projectResults = tree.get(project);
|
||||||
|
if (projectResults == null) {
|
||||||
|
addProjectWarningIfApplicable(project);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void remove(Object element) {
|
protected void remove(Object element) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue