mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-13 19:25:38 +02:00
Fixed up search including assing support for both the List and Tree view, the remove element menu items, and search rerunning. Also made a common Label provider for all index based views. Also removed the LinkageCache which is no longer used since the PDOM now caches Linkages.
This commit is contained in:
parent
475d55c8e1
commit
326fcbaa4f
18 changed files with 483 additions and 289 deletions
|
@ -100,6 +100,16 @@ public class PDOMFile {
|
|||
return record;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == this)
|
||||
return true;
|
||||
if (obj instanceof PDOMFile) {
|
||||
PDOMFile other = (PDOMFile)obj;
|
||||
return pdom.equals(other.pdom) && record == other.record;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public IString getFileName() throws CoreException {
|
||||
Database db = pdom.getDB();
|
||||
return db.getString(db.getInt(record + FILE_NAME));
|
||||
|
|
|
@ -0,0 +1,85 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 QNX Software Systems 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
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
||||
import org.eclipse.cdt.core.dom.ast.IFunction;
|
||||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
||||
import org.eclipse.cdt.core.model.ICContainer;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNamedNode;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
|
||||
import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
import org.eclipse.jface.viewers.LabelProvider;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.ui.ISharedImages;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
|
||||
/**
|
||||
* Common label provider for index based viewers.
|
||||
*
|
||||
* @author Doug Schaefer
|
||||
*/
|
||||
public class IndexLabelProvider extends LabelProvider {
|
||||
public String getText(Object element) {
|
||||
if (element == null) {
|
||||
return "null :(";
|
||||
} else if (element instanceof PDOMNode) {
|
||||
try {
|
||||
return ((PDOMNamedNode)element).getDBName().getString();
|
||||
} catch (CoreException e) {
|
||||
return e.getMessage();
|
||||
}
|
||||
} else
|
||||
return super.getText(element);
|
||||
}
|
||||
|
||||
public Image getImage(Object element) {
|
||||
ImageDescriptor desc = null;
|
||||
|
||||
if (element instanceof IVariable)
|
||||
desc = CElementImageProvider.getVariableImageDescriptor();
|
||||
else if (element instanceof IFunction)
|
||||
desc = CElementImageProvider.getFunctionImageDescriptor();
|
||||
else if (element instanceof ICPPClassType)
|
||||
desc = CElementImageProvider.getClassImageDescriptor();
|
||||
else if (element instanceof ICompositeType)
|
||||
desc = CElementImageProvider.getStructImageDescriptor();
|
||||
else if (element instanceof ICPPNamespace)
|
||||
desc = CElementImageProvider.getNamespaceImageDescriptor();
|
||||
else if (element instanceof ICProject)
|
||||
desc = CPluginImages.DESC_OBJS_SEARCHHIERPROJECT;
|
||||
else if (element instanceof ICContainer)
|
||||
desc = CPluginImages.DESC_OBJS_SEARCHHIERFODLER;
|
||||
else if (element instanceof ITranslationUnit) {
|
||||
ITranslationUnit tu = (ITranslationUnit)element;
|
||||
desc = tu.isHeaderUnit()
|
||||
? CPluginImages.DESC_OBJS_TUNIT_HEADER
|
||||
: CPluginImages.DESC_OBJS_TUNIT;
|
||||
}
|
||||
|
||||
if (desc != null)
|
||||
return CUIPlugin.getImageDescriptorRegistry().get(desc);
|
||||
else if (element instanceof PDOMLinkage)
|
||||
return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT);
|
||||
else
|
||||
return super.getImage(element);
|
||||
}
|
||||
|
||||
}
|
|
@ -18,12 +18,6 @@ import org.eclipse.cdt.core.CCorePlugin;
|
|||
import org.eclipse.cdt.core.dom.IPDOMNode;
|
||||
import org.eclipse.cdt.core.dom.IPDOMVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
||||
import org.eclipse.cdt.core.dom.ast.IFunction;
|
||||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.ElementChangedEvent;
|
||||
|
@ -36,9 +30,7 @@ import org.eclipse.cdt.internal.core.pdom.PDOM;
|
|||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNamedNode;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
|
||||
import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider;
|
||||
import org.eclipse.cdt.internal.ui.IndexLabelProvider;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
@ -54,20 +46,15 @@ import org.eclipse.jface.viewers.DoubleClickEvent;
|
|||
import org.eclipse.jface.viewers.IDoubleClickListener;
|
||||
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
||||
import org.eclipse.jface.viewers.ITreeContentProvider;
|
||||
import org.eclipse.jface.viewers.LabelProvider;
|
||||
import org.eclipse.jface.viewers.SelectionChangedEvent;
|
||||
import org.eclipse.jface.viewers.TreeViewer;
|
||||
import org.eclipse.jface.viewers.Viewer;
|
||||
import org.eclipse.jface.viewers.ViewerFilter;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Menu;
|
||||
import org.eclipse.ui.IActionBars;
|
||||
import org.eclipse.ui.ISharedImages;
|
||||
import org.eclipse.ui.IWorkbenchActionConstants;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.ide.IDE;
|
||||
import org.eclipse.ui.part.ViewPart;
|
||||
|
||||
/**
|
||||
|
@ -281,55 +268,6 @@ public class IndexView extends ViewPart implements PDOM.IListener, IElementChang
|
|||
|
||||
}
|
||||
|
||||
private class IndexLabelProvider extends LabelProvider {
|
||||
public String getText(Object element) {
|
||||
if (element == null) {
|
||||
return "null :(";
|
||||
} else if (element instanceof PDOMNode) {
|
||||
try {
|
||||
return ((PDOMNamedNode)element).getDBName().getString();
|
||||
} catch (CoreException e) {
|
||||
return e.getMessage();
|
||||
}
|
||||
} else if (element instanceof LinkageCache) {
|
||||
try {
|
||||
return ((LinkageCache)element).getName().getString();
|
||||
} catch (CoreException e) {
|
||||
return e.getMessage();
|
||||
}
|
||||
} else
|
||||
return super.getText(element);
|
||||
}
|
||||
|
||||
public Image getImage(Object element) {
|
||||
if (element instanceof IVariable)
|
||||
return CUIPlugin.getImageDescriptorRegistry().get(
|
||||
CElementImageProvider.getVariableImageDescriptor());
|
||||
else if (element instanceof IFunction)
|
||||
return CUIPlugin.getImageDescriptorRegistry().get(
|
||||
CElementImageProvider.getFunctionImageDescriptor());
|
||||
else if (element instanceof ICPPClassType)
|
||||
return CUIPlugin.getImageDescriptorRegistry().get(
|
||||
CElementImageProvider.getClassImageDescriptor());
|
||||
else if (element instanceof ICompositeType)
|
||||
return CUIPlugin.getImageDescriptorRegistry().get(
|
||||
CElementImageProvider.getStructImageDescriptor());
|
||||
else if (element instanceof ICPPNamespace)
|
||||
return CUIPlugin.getImageDescriptorRegistry().get(
|
||||
CElementImageProvider.getNamespaceImageDescriptor());
|
||||
else if (element instanceof IBinding)
|
||||
return PlatformUI.getWorkbench().getSharedImages().getImage(
|
||||
ISharedImages.IMG_OBJ_ELEMENT);
|
||||
else if (element instanceof ICProject)
|
||||
return PlatformUI.getWorkbench().getSharedImages().getImage(
|
||||
IDE.SharedImages.IMG_OBJ_PROJECT);
|
||||
else
|
||||
return PlatformUI.getWorkbench().getSharedImages().getImage(
|
||||
ISharedImages.IMG_OBJ_ELEMENT);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void createPartControl(Composite parent) {
|
||||
viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
|
||||
// viewer = new TreeViewer(parent, SWT.VIRTUAL | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
|
||||
|
|
|
@ -1,89 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 QNX Software Systems 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
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.indexview;
|
||||
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.IString;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
* @author Doug Schaefer
|
||||
*
|
||||
*/
|
||||
public class LinkageCache {
|
||||
|
||||
private final PDOM pdom;
|
||||
private final PDOMLinkage linkage;
|
||||
private int[] cache;
|
||||
|
||||
private static class Counter implements IBTreeVisitor {
|
||||
int count;
|
||||
PDOM pdom;
|
||||
public Counter(PDOM pdom) {
|
||||
this.pdom = pdom;
|
||||
}
|
||||
public int compare(int record) throws CoreException {
|
||||
return 1;
|
||||
}
|
||||
public boolean visit(int record) throws CoreException {
|
||||
if (record != 0 && ! PDOMBinding.isOrphaned(pdom, record))
|
||||
++count;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private static class FillCache implements IBTreeVisitor {
|
||||
final PDOM pdom;
|
||||
final int[] cache;
|
||||
int index;
|
||||
public FillCache(PDOM pdom, int [] cache) {
|
||||
this.pdom = pdom;
|
||||
this.cache = cache;
|
||||
}
|
||||
public int compare(int record) throws CoreException {
|
||||
return 1;
|
||||
};
|
||||
public boolean visit(int record) throws CoreException {
|
||||
if (record == 0 || PDOMBinding.isOrphaned(pdom, record))
|
||||
return true;
|
||||
|
||||
cache[index++] = record;
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
public LinkageCache(PDOM pdom, PDOMLinkage linkage) throws CoreException {
|
||||
this.pdom = pdom;
|
||||
this.linkage = linkage;
|
||||
|
||||
Counter counter = new Counter(pdom);
|
||||
linkage.getIndex().accept(counter);
|
||||
cache = new int[counter.count];
|
||||
FillCache fillCache = new FillCache(pdom, cache);
|
||||
linkage.getIndex().accept(fillCache);
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return cache.length;
|
||||
}
|
||||
|
||||
public PDOMBinding getItem(int index) throws CoreException {
|
||||
return pdom.getBinding(cache[index]);
|
||||
}
|
||||
|
||||
public IString getName() throws CoreException {
|
||||
return linkage.getDBName();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 QNX Software Systems 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
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.search;
|
||||
|
||||
/**
|
||||
* @author Doug Schaefer
|
||||
*
|
||||
*/
|
||||
public interface IPDOMSearchContentProvider {
|
||||
|
||||
public void elementsChanged(Object[] elements);
|
||||
|
||||
public void clear();
|
||||
|
||||
}
|
|
@ -36,6 +36,7 @@ public class PDOMSearchBindingQuery extends PDOMSearchQuery {
|
|||
|
||||
public IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
|
||||
try {
|
||||
result.removeAll();
|
||||
createMatches(binding.getLinkage().getLanguage(), binding);
|
||||
return Status.OK_STATUS;
|
||||
} catch (CoreException e) {
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 QNX Software Systems 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
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Element class used to group matches.
|
||||
*
|
||||
* @author Doug Schaefer
|
||||
*/
|
||||
public class PDOMSearchElement {
|
||||
|
||||
private final PDOMBinding binding;
|
||||
private final PDOMFile file;
|
||||
|
||||
public PDOMSearchElement(PDOMName name) throws CoreException {
|
||||
binding = name.getPDOMBinding();
|
||||
file = name.getFile();
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return binding.getRecord() + file.getRecord();
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof PDOMSearchElement))
|
||||
return false;
|
||||
if (this == obj)
|
||||
return true;
|
||||
PDOMSearchElement other = (PDOMSearchElement)obj;
|
||||
return binding.equals(other.binding)
|
||||
&& file.equals(other.file);
|
||||
}
|
||||
|
||||
public PDOMFile getFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
public PDOMBinding getBinding() {
|
||||
return binding;
|
||||
}
|
||||
|
||||
}
|
|
@ -40,6 +40,7 @@ public class PDOMSearchElementQuery extends PDOMSearchQuery {
|
|||
|
||||
public IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
|
||||
try {
|
||||
result.removeAll();
|
||||
ISourceRange range = element.getSourceRange();
|
||||
ITranslationUnit tu = element.getTranslationUnit();
|
||||
ILanguage language = tu.getLanguage();
|
||||
|
|
|
@ -1,65 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 QNX Software Systems 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
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.search;
|
||||
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
|
||||
import org.eclipse.cdt.internal.ui.CPluginImages;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IFolder;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
import org.eclipse.jface.viewers.LabelProvider;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
|
||||
/**
|
||||
* @author Doug Schaefer
|
||||
*
|
||||
*/
|
||||
public class PDOMSearchLabelProvider extends LabelProvider {
|
||||
|
||||
public Image getImage(Object element) {
|
||||
ImageDescriptor imageDescriptor = null;
|
||||
if (element instanceof IProject) {
|
||||
imageDescriptor = CPluginImages.DESC_OBJS_SEARCHHIERPROJECT;
|
||||
} else if (element instanceof IFolder) {
|
||||
imageDescriptor = CPluginImages.DESC_OBJS_SEARCHHIERFODLER;
|
||||
} else if (element instanceof IFile) {
|
||||
imageDescriptor = CPluginImages.DESC_OBJS_TUNIT;
|
||||
} else if (element instanceof PDOMName) {
|
||||
imageDescriptor = CPluginImages.DESC_OBJS_VARIABLE;
|
||||
} else if (element instanceof String) {
|
||||
// external path, likely a header file
|
||||
imageDescriptor = CPluginImages.DESC_OBJS_TUNIT_HEADER;
|
||||
}
|
||||
|
||||
if (imageDescriptor != null) {
|
||||
return CUIPlugin.getImageDescriptorRegistry().get( imageDescriptor );
|
||||
} else
|
||||
return super.getImage(element);
|
||||
}
|
||||
|
||||
public String getText(Object element) {
|
||||
if (element instanceof IResource) {
|
||||
return ((IResource)element).getName();
|
||||
} else if (element instanceof PDOMName) {
|
||||
PDOMName name = (PDOMName)element;
|
||||
return new String(name.toCharArray())
|
||||
+ " (" + name.getFileName() + ")";
|
||||
} else {
|
||||
return super.getText(element);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 QNX Software Systems 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
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.search;
|
||||
|
||||
import org.eclipse.jface.viewers.IStructuredContentProvider;
|
||||
import org.eclipse.jface.viewers.TableViewer;
|
||||
import org.eclipse.jface.viewers.Viewer;
|
||||
|
||||
/**
|
||||
* @author Doug Schaefer
|
||||
*
|
||||
*/
|
||||
public class PDOMSearchListContentProvider implements
|
||||
IStructuredContentProvider, IPDOMSearchContentProvider {
|
||||
|
||||
private TableViewer viewer;
|
||||
private PDOMSearchResult result;
|
||||
|
||||
public Object[] getElements(Object inputElement) {
|
||||
return result.getElements();
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
}
|
||||
|
||||
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
||||
this.viewer = (TableViewer)viewer;
|
||||
result = (PDOMSearchResult)newInput;
|
||||
}
|
||||
|
||||
public void elementsChanged(Object[] elements) {
|
||||
if (result == null)
|
||||
return;
|
||||
|
||||
for (int i= 0; i < elements.length; i++) {
|
||||
if (result.getMatchCount(elements[i]) > 0) {
|
||||
if (viewer.testFindItem(elements[i]) != null)
|
||||
viewer.refresh(elements[i]);
|
||||
else
|
||||
viewer.add(elements[i]);
|
||||
} else {
|
||||
viewer.remove(elements[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
viewer.refresh();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 QNX Software Systems 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
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author Doug Schaefer
|
||||
*
|
||||
*/
|
||||
public class PDOMSearchListLabelProvider extends IndexLabelProvider {
|
||||
|
||||
private final AbstractTextSearchViewPage page;
|
||||
|
||||
public PDOMSearchListLabelProvider(AbstractTextSearchViewPage page) {
|
||||
this.page = page;
|
||||
}
|
||||
|
||||
public Image getImage(Object element) {
|
||||
if (element instanceof PDOMSearchElement)
|
||||
return getImage(((PDOMSearchElement)element).getBinding());
|
||||
else
|
||||
return super.getImage(element);
|
||||
}
|
||||
|
||||
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$
|
||||
}
|
||||
int count = page.getInput().getMatchCount(element);
|
||||
return getText(searchElement.getBinding()) + filename + " " //$NON-NLS-1$
|
||||
+ CSearchMessages.getFormattedString("CSearchResultCollector.matches", new Integer(count)); //$NON-NLS-1$
|
||||
} else
|
||||
return super.getText(element);
|
||||
}
|
||||
|
||||
}
|
|
@ -12,6 +12,7 @@
|
|||
package org.eclipse.cdt.internal.ui.search;
|
||||
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.search.ui.text.Match;
|
||||
|
||||
/**
|
||||
|
@ -20,11 +21,11 @@ import org.eclipse.search.ui.text.Match;
|
|||
*/
|
||||
public class PDOMSearchMatch extends Match {
|
||||
|
||||
public PDOMSearchMatch(PDOMName name, int offset, int length) {
|
||||
super(name, offset, length);
|
||||
public PDOMSearchMatch(PDOMName name, int offset, int length) throws CoreException {
|
||||
super(new PDOMSearchElement(name), offset, length);
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return ((PDOMName)getElement()).getFileName();
|
||||
public String getFileName() throws CoreException {
|
||||
return ((PDOMSearchElement)getElement()).getFile().getFileName().getString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,6 +62,7 @@ public class PDOMSearchPatternQuery extends PDOMSearchQuery {
|
|||
|
||||
public IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
|
||||
try {
|
||||
result.removeAll();
|
||||
for (int i = 0; i < projects.length; ++i)
|
||||
searchProject(projects[i], monitor);
|
||||
return Status.OK_STATUS;
|
||||
|
|
|
@ -17,8 +17,10 @@ import java.util.List;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
|
||||
import org.eclipse.cdt.internal.ui.util.ExternalEditorInput;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
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.resource.ImageDescriptor;
|
||||
|
@ -66,14 +68,17 @@ public class PDOMSearchResult extends AbstractTextSearchResult implements IEdito
|
|||
}
|
||||
|
||||
public boolean isShownInEditor(Match match, IEditorPart editor) {
|
||||
String filename = getFileName(editor);
|
||||
if (filename != null && match instanceof PDOMSearchMatch) {
|
||||
return filename.equals(((PDOMSearchMatch)match).getFileName());
|
||||
} else
|
||||
return false;
|
||||
try {
|
||||
String filename = getFileName(editor);
|
||||
if (filename != null && match instanceof PDOMSearchMatch)
|
||||
return filename.equals(((PDOMSearchMatch)match).getFileName());
|
||||
} catch (CoreException e) {
|
||||
CUIPlugin.getDefault().log(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private Match[] computeContainedMatches(AbstractTextSearchResult result, String filename) {
|
||||
private Match[] computeContainedMatches(AbstractTextSearchResult result, String filename) throws CoreException {
|
||||
List list = new ArrayList();
|
||||
Object[] elements = result.getElements();
|
||||
for (int i = 0; i < elements.length; ++i) {
|
||||
|
@ -90,17 +95,24 @@ public class PDOMSearchResult extends AbstractTextSearchResult implements IEdito
|
|||
}
|
||||
|
||||
public Match[] computeContainedMatches(AbstractTextSearchResult result, IEditorPart editor) {
|
||||
String filename = getFileName(editor);
|
||||
if (filename != null) {
|
||||
return computeContainedMatches(result, filename);
|
||||
} else {
|
||||
return new Match[0];
|
||||
try {
|
||||
String filename = getFileName(editor);
|
||||
if (filename != null)
|
||||
return computeContainedMatches(result, filename);
|
||||
} catch (CoreException e) {
|
||||
CUIPlugin.getDefault().log(e);
|
||||
}
|
||||
return new Match[0];
|
||||
}
|
||||
|
||||
public Match[] computeContainedMatches(AbstractTextSearchResult result, IFile file) {
|
||||
String filename = file.getLocation().toOSString();
|
||||
return computeContainedMatches(result, filename);
|
||||
try {
|
||||
String filename = file.getLocation().toOSString();
|
||||
return computeContainedMatches(result, filename);
|
||||
} catch (CoreException e) {
|
||||
CUIPlugin.getDefault().log(e);
|
||||
}
|
||||
return new Match[0];
|
||||
}
|
||||
|
||||
public IFile getFile(Object element) {
|
||||
|
|
|
@ -41,6 +41,7 @@ public class PDOMSearchTextSelectionQuery extends PDOMSearchQuery {
|
|||
|
||||
public IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
|
||||
try {
|
||||
result.removeAll();
|
||||
ILanguage language = tu.getLanguage();
|
||||
IASTTranslationUnit ast = language.getASTTranslationUnit(tu, ILanguage.AST_SKIP_ALL_HEADERS | ILanguage.AST_USE_INDEX);
|
||||
IASTName[] names = language.getSelectedNames(ast, selection.getOffset(), selection.getLength());
|
||||
|
|
|
@ -13,15 +13,19 @@ package org.eclipse.cdt.internal.ui.search;
|
|||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
|
||||
import org.eclipse.core.resources.IContainer;
|
||||
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.IResource;
|
||||
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;
|
||||
|
@ -33,11 +37,11 @@ import org.eclipse.swt.widgets.Display;
|
|||
* @author Doug Schaefer
|
||||
*
|
||||
*/
|
||||
public class PDOMSearchTreeContentProvider implements ITreeContentProvider {
|
||||
public class PDOMSearchTreeContentProvider implements ITreeContentProvider, IPDOMSearchContentProvider {
|
||||
|
||||
private TreeViewer viewer;
|
||||
private PDOMSearchResult result;
|
||||
private HashMap tree;
|
||||
private Map tree = new HashMap();
|
||||
|
||||
public Object[] getChildren(Object parentElement) {
|
||||
Set children = (Set)tree.get(parentElement);
|
||||
|
@ -47,6 +51,13 @@ public class PDOMSearchTreeContentProvider implements ITreeContentProvider {
|
|||
}
|
||||
|
||||
public Object getParent(Object element) {
|
||||
Iterator p = tree.keySet().iterator();
|
||||
while (p.hasNext()) {
|
||||
Object parent = p.next();
|
||||
Set children = (Set)tree.get(parent);
|
||||
if (children.contains(element))
|
||||
return parent;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -64,7 +75,13 @@ public class PDOMSearchTreeContentProvider implements ITreeContentProvider {
|
|||
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
||||
this.viewer = (TreeViewer)viewer;
|
||||
result = (PDOMSearchResult)newInput;
|
||||
tree = new HashMap();
|
||||
tree.clear();
|
||||
if (result != null) {
|
||||
Object[] elements = result.getElements();
|
||||
for (int i = 0; i < elements.length; ++i) {
|
||||
insertSearchElement((PDOMSearchElement)elements[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void insertChild(Object parent, Object child) {
|
||||
|
@ -76,40 +93,49 @@ public class PDOMSearchTreeContentProvider implements ITreeContentProvider {
|
|||
children.add(child);
|
||||
}
|
||||
|
||||
private void insertName(PDOMName name) {
|
||||
IASTFileLocation loc = name.getFileLocation();
|
||||
IPath path = new Path(loc.getFileName());
|
||||
IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(path);
|
||||
if (files.length > 0) {
|
||||
for (int j = 0; j < files.length; ++j) {
|
||||
insertChild(files[j], name);
|
||||
insertResource(files[j]);
|
||||
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);
|
||||
}
|
||||
} else {
|
||||
String pathName = path.toOSString();
|
||||
insertChild(pathName, name);
|
||||
insertChild(result, pathName);
|
||||
} catch (CoreException e) {
|
||||
CUIPlugin.getDefault().log(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void insertResource(IResource resource) {
|
||||
if (resource instanceof IProject) {
|
||||
insertChild(result, resource);
|
||||
} else {
|
||||
IContainer parent = resource.getParent();
|
||||
insertChild(parent, resource);
|
||||
insertResource(parent);
|
||||
private void insertCElement(ICElement element) {
|
||||
if (element instanceof ICProject)
|
||||
insertChild(result, element);
|
||||
else {
|
||||
ICElement parent = element.getParent();
|
||||
if (parent instanceof ISourceRoot && parent.getUnderlyingResource() instanceof IProject)
|
||||
// Skip source roots that are projects
|
||||
parent = parent.getParent();
|
||||
insertChild(parent, element);
|
||||
insertCElement(parent);
|
||||
}
|
||||
}
|
||||
|
||||
public void elementsChanged(Object[] elements) {
|
||||
if (elements == null || elements.length == 0)
|
||||
return;
|
||||
if (elements != null)
|
||||
for (int i = 0; i < elements.length; ++i) {
|
||||
PDOMSearchElement element = (PDOMSearchElement)elements[i];
|
||||
if (result.getMatchCount(element) > 0)
|
||||
insertSearchElement(element);
|
||||
else
|
||||
remove(element);
|
||||
}
|
||||
|
||||
for (int i = 0; i < elements.length; ++i) {
|
||||
PDOMName name = (PDOMName)elements[i];
|
||||
insertName(name);
|
||||
}
|
||||
Display.getDefault().asyncExec(new Runnable() {
|
||||
public void run() {
|
||||
viewer.refresh();
|
||||
|
@ -118,5 +144,28 @@ public class PDOMSearchTreeContentProvider implements ITreeContentProvider {
|
|||
}
|
||||
|
||||
public void clear() {
|
||||
tree.clear();
|
||||
Display.getDefault().asyncExec(new Runnable() {
|
||||
public void run() {
|
||||
viewer.refresh();
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
protected void remove(Object element) {
|
||||
Object parent = getParent(element);
|
||||
if (parent == null)
|
||||
// reached the search result
|
||||
return;
|
||||
|
||||
Set siblings = (Set)tree.get(parent);
|
||||
siblings.remove(element);
|
||||
|
||||
if (siblings.isEmpty()) {
|
||||
// remove the parent
|
||||
remove(parent);
|
||||
tree.remove(parent);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 QNX Software Systems 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
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.search;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.IndexLabelProvider;
|
||||
import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
|
||||
/**
|
||||
* @author Doug Schaefer
|
||||
*
|
||||
*/
|
||||
public class PDOMSearchTreeLabelProvider extends IndexLabelProvider {
|
||||
|
||||
private final AbstractTextSearchViewPage page;
|
||||
|
||||
public PDOMSearchTreeLabelProvider(AbstractTextSearchViewPage page) {
|
||||
this.page = page;
|
||||
}
|
||||
|
||||
public Image getImage(Object element) {
|
||||
if (element instanceof PDOMSearchElement)
|
||||
return getImage(((PDOMSearchElement)element).getBinding());
|
||||
else
|
||||
return super.getImage(element);
|
||||
}
|
||||
|
||||
public String getText(Object element) {
|
||||
if (element instanceof PDOMSearchElement) {
|
||||
int count = page.getInput().getMatchCount(element);
|
||||
return getText(((PDOMSearchElement)element).getBinding()) + " " //$NON-NLS-1$
|
||||
+ CSearchMessages.getFormattedString("CSearchResultCollector.matches", new Integer(count)); //$NON-NLS-1$
|
||||
} else
|
||||
return super.getText(element);
|
||||
}
|
||||
|
||||
}
|
|
@ -38,7 +38,7 @@ import org.eclipse.ui.texteditor.ITextEditor;
|
|||
*/
|
||||
public class PDOMSearchViewPage extends AbstractTextSearchViewPage {
|
||||
|
||||
private PDOMSearchTreeContentProvider contentProvider;
|
||||
private IPDOMSearchContentProvider contentProvider;
|
||||
|
||||
public PDOMSearchViewPage(int supportedLayouts) {
|
||||
super(supportedLayouts);
|
||||
|
@ -60,38 +60,45 @@ public class PDOMSearchViewPage extends AbstractTextSearchViewPage {
|
|||
|
||||
protected void configureTreeViewer(TreeViewer viewer) {
|
||||
contentProvider = new PDOMSearchTreeContentProvider();
|
||||
viewer.setContentProvider(contentProvider);
|
||||
viewer.setLabelProvider(new PDOMSearchLabelProvider());
|
||||
viewer.setContentProvider((PDOMSearchTreeContentProvider)contentProvider);
|
||||
viewer.setLabelProvider(new PDOMSearchTreeLabelProvider(this));
|
||||
}
|
||||
|
||||
protected void configureTableViewer(TableViewer viewer) {
|
||||
contentProvider = new PDOMSearchListContentProvider();
|
||||
viewer.setContentProvider((PDOMSearchListContentProvider)contentProvider);
|
||||
viewer.setLabelProvider(new PDOMSearchListLabelProvider(this));
|
||||
}
|
||||
|
||||
protected void showMatch(Match match, int currentOffset, int currentLength, boolean activate) throws PartInitException {
|
||||
if (!(match instanceof PDOMSearchMatch))
|
||||
return;
|
||||
|
||||
IPath path = new Path(((PDOMSearchMatch)match).getFileName());
|
||||
IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(path);
|
||||
if (files.length > 0) {
|
||||
IEditorPart editor = IDE.openEditor(CUIPlugin.getActivePage(), files[0]);
|
||||
try {
|
||||
IMarker marker = files[0].createMarker(NewSearchUI.SEARCH_MARKER);
|
||||
marker.setAttribute(IMarker.CHAR_START, currentOffset);
|
||||
marker.setAttribute(IMarker.CHAR_END, currentOffset + currentLength);
|
||||
IDE.gotoMarker(editor, marker);
|
||||
marker.delete();
|
||||
} catch (CoreException e) {
|
||||
CUIPlugin.getDefault().log(e);
|
||||
}
|
||||
} else {
|
||||
// external file
|
||||
IEditorInput input = new ExternalEditorInput(new FileStorage(path));
|
||||
IEditorPart editor = CUIPlugin.getActivePage().openEditor(input, ExternalSearchEditor.EDITOR_ID);
|
||||
if (editor instanceof ITextEditor) {
|
||||
ITextEditor textEditor = (ITextEditor)editor;
|
||||
textEditor.selectAndReveal(currentOffset, currentLength);
|
||||
try {
|
||||
IPath path = new Path(((PDOMSearchMatch)match).getFileName());
|
||||
IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(path);
|
||||
if (files.length > 0) {
|
||||
IEditorPart editor = IDE.openEditor(CUIPlugin.getActivePage(), files[0]);
|
||||
try {
|
||||
IMarker marker = files[0].createMarker(NewSearchUI.SEARCH_MARKER);
|
||||
marker.setAttribute(IMarker.CHAR_START, currentOffset);
|
||||
marker.setAttribute(IMarker.CHAR_END, currentOffset + currentLength);
|
||||
IDE.gotoMarker(editor, marker);
|
||||
marker.delete();
|
||||
} catch (CoreException e) {
|
||||
CUIPlugin.getDefault().log(e);
|
||||
}
|
||||
} else {
|
||||
// external file
|
||||
IEditorInput input = new ExternalEditorInput(new FileStorage(path));
|
||||
IEditorPart editor = CUIPlugin.getActivePage().openEditor(input, ExternalSearchEditor.EDITOR_ID);
|
||||
if (editor instanceof ITextEditor) {
|
||||
ITextEditor textEditor = (ITextEditor)editor;
|
||||
textEditor.selectAndReveal(currentOffset, currentLength);
|
||||
}
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
CUIPlugin.getDefault().log(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue