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;
|
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 {
|
public IString getFileName() throws CoreException {
|
||||||
Database db = pdom.getDB();
|
Database db = pdom.getDB();
|
||||||
return db.getString(db.getInt(record + FILE_NAME));
|
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.IPDOMNode;
|
||||||
import org.eclipse.cdt.core.dom.IPDOMVisitor;
|
import org.eclipse.cdt.core.dom.IPDOMVisitor;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
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.CModelException;
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
import org.eclipse.cdt.core.model.ElementChangedEvent;
|
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.PDOMBinding;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
|
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.PDOMName;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNamedNode;
|
import org.eclipse.cdt.internal.ui.IndexLabelProvider;
|
||||||
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.cdt.ui.CUIPlugin;
|
||||||
import org.eclipse.core.resources.ResourcesPlugin;
|
import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
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.IDoubleClickListener;
|
||||||
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
||||||
import org.eclipse.jface.viewers.ITreeContentProvider;
|
import org.eclipse.jface.viewers.ITreeContentProvider;
|
||||||
import org.eclipse.jface.viewers.LabelProvider;
|
|
||||||
import org.eclipse.jface.viewers.SelectionChangedEvent;
|
import org.eclipse.jface.viewers.SelectionChangedEvent;
|
||||||
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.jface.viewers.ViewerFilter;
|
import org.eclipse.jface.viewers.ViewerFilter;
|
||||||
import org.eclipse.swt.SWT;
|
import org.eclipse.swt.SWT;
|
||||||
import org.eclipse.swt.graphics.Image;
|
|
||||||
import org.eclipse.swt.widgets.Composite;
|
import org.eclipse.swt.widgets.Composite;
|
||||||
import org.eclipse.swt.widgets.Menu;
|
import org.eclipse.swt.widgets.Menu;
|
||||||
import org.eclipse.ui.IActionBars;
|
import org.eclipse.ui.IActionBars;
|
||||||
import org.eclipse.ui.ISharedImages;
|
|
||||||
import org.eclipse.ui.IWorkbenchActionConstants;
|
import org.eclipse.ui.IWorkbenchActionConstants;
|
||||||
import org.eclipse.ui.PlatformUI;
|
|
||||||
import org.eclipse.ui.ide.IDE;
|
|
||||||
import org.eclipse.ui.part.ViewPart;
|
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) {
|
public void createPartControl(Composite parent) {
|
||||||
viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
|
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);
|
// 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 {
|
public IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
|
||||||
try {
|
try {
|
||||||
|
result.removeAll();
|
||||||
createMatches(binding.getLinkage().getLanguage(), binding);
|
createMatches(binding.getLinkage().getLanguage(), binding);
|
||||||
return Status.OK_STATUS;
|
return Status.OK_STATUS;
|
||||||
} catch (CoreException e) {
|
} 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 {
|
public IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
|
||||||
try {
|
try {
|
||||||
|
result.removeAll();
|
||||||
ISourceRange range = element.getSourceRange();
|
ISourceRange range = element.getSourceRange();
|
||||||
ITranslationUnit tu = element.getTranslationUnit();
|
ITranslationUnit tu = element.getTranslationUnit();
|
||||||
ILanguage language = tu.getLanguage();
|
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;
|
package org.eclipse.cdt.internal.ui.search;
|
||||||
|
|
||||||
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.search.ui.text.Match;
|
import org.eclipse.search.ui.text.Match;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -20,11 +21,11 @@ import org.eclipse.search.ui.text.Match;
|
||||||
*/
|
*/
|
||||||
public class PDOMSearchMatch extends Match {
|
public class PDOMSearchMatch extends Match {
|
||||||
|
|
||||||
public PDOMSearchMatch(PDOMName name, int offset, int length) {
|
public PDOMSearchMatch(PDOMName name, int offset, int length) throws CoreException {
|
||||||
super(name, offset, length);
|
super(new PDOMSearchElement(name), offset, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFileName() {
|
public String getFileName() throws CoreException {
|
||||||
return ((PDOMName)getElement()).getFileName();
|
return ((PDOMSearchElement)getElement()).getFile().getFileName().getString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,6 +62,7 @@ public class PDOMSearchPatternQuery extends PDOMSearchQuery {
|
||||||
|
|
||||||
public IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
|
public IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
|
||||||
try {
|
try {
|
||||||
|
result.removeAll();
|
||||||
for (int i = 0; i < projects.length; ++i)
|
for (int i = 0; i < projects.length; ++i)
|
||||||
searchProject(projects[i], monitor);
|
searchProject(projects[i], monitor);
|
||||||
return Status.OK_STATUS;
|
return Status.OK_STATUS;
|
||||||
|
|
|
@ -17,8 +17,10 @@ import java.util.List;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
|
||||||
import org.eclipse.cdt.internal.ui.util.ExternalEditorInput;
|
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.IFile;
|
||||||
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.resource.ImageDescriptor;
|
import org.eclipse.jface.resource.ImageDescriptor;
|
||||||
|
@ -66,14 +68,17 @@ public class PDOMSearchResult extends AbstractTextSearchResult implements IEdito
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isShownInEditor(Match match, IEditorPart editor) {
|
public boolean isShownInEditor(Match match, IEditorPart editor) {
|
||||||
String filename = getFileName(editor);
|
try {
|
||||||
if (filename != null && match instanceof PDOMSearchMatch) {
|
String filename = getFileName(editor);
|
||||||
return filename.equals(((PDOMSearchMatch)match).getFileName());
|
if (filename != null && match instanceof PDOMSearchMatch)
|
||||||
} else
|
return filename.equals(((PDOMSearchMatch)match).getFileName());
|
||||||
return false;
|
} 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();
|
List list = new ArrayList();
|
||||||
Object[] elements = result.getElements();
|
Object[] elements = result.getElements();
|
||||||
for (int i = 0; i < elements.length; ++i) {
|
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) {
|
public Match[] computeContainedMatches(AbstractTextSearchResult result, IEditorPart editor) {
|
||||||
String filename = getFileName(editor);
|
try {
|
||||||
if (filename != null) {
|
String filename = getFileName(editor);
|
||||||
return computeContainedMatches(result, filename);
|
if (filename != null)
|
||||||
} else {
|
return computeContainedMatches(result, filename);
|
||||||
return new Match[0];
|
} catch (CoreException e) {
|
||||||
|
CUIPlugin.getDefault().log(e);
|
||||||
}
|
}
|
||||||
|
return new Match[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
public Match[] computeContainedMatches(AbstractTextSearchResult result, IFile file) {
|
public Match[] computeContainedMatches(AbstractTextSearchResult result, IFile file) {
|
||||||
String filename = file.getLocation().toOSString();
|
try {
|
||||||
return computeContainedMatches(result, filename);
|
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) {
|
public IFile getFile(Object element) {
|
||||||
|
|
|
@ -41,6 +41,7 @@ public class PDOMSearchTextSelectionQuery extends PDOMSearchQuery {
|
||||||
|
|
||||||
public IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
|
public IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
|
||||||
try {
|
try {
|
||||||
|
result.removeAll();
|
||||||
ILanguage language = tu.getLanguage();
|
ILanguage language = tu.getLanguage();
|
||||||
IASTTranslationUnit ast = language.getASTTranslationUnit(tu, ILanguage.AST_SKIP_ALL_HEADERS | ILanguage.AST_USE_INDEX);
|
IASTTranslationUnit ast = language.getASTTranslationUnit(tu, ILanguage.AST_SKIP_ALL_HEADERS | ILanguage.AST_USE_INDEX);
|
||||||
IASTName[] names = language.getSelectedNames(ast, selection.getOffset(), selection.getLength());
|
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.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
import org.eclipse.core.resources.IContainer;
|
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.IFile;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.resources.IResource;
|
|
||||||
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;
|
||||||
|
@ -33,11 +37,11 @@ import org.eclipse.swt.widgets.Display;
|
||||||
* @author Doug Schaefer
|
* @author Doug Schaefer
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class PDOMSearchTreeContentProvider implements ITreeContentProvider {
|
public class PDOMSearchTreeContentProvider implements ITreeContentProvider, IPDOMSearchContentProvider {
|
||||||
|
|
||||||
private TreeViewer viewer;
|
private TreeViewer viewer;
|
||||||
private PDOMSearchResult result;
|
private PDOMSearchResult result;
|
||||||
private HashMap tree;
|
private Map tree = new HashMap();
|
||||||
|
|
||||||
public Object[] getChildren(Object parentElement) {
|
public Object[] getChildren(Object parentElement) {
|
||||||
Set children = (Set)tree.get(parentElement);
|
Set children = (Set)tree.get(parentElement);
|
||||||
|
@ -47,6 +51,13 @@ public class PDOMSearchTreeContentProvider implements ITreeContentProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object getParent(Object element) {
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +75,13 @@ public class PDOMSearchTreeContentProvider implements ITreeContentProvider {
|
||||||
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;
|
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) {
|
private void insertChild(Object parent, Object child) {
|
||||||
|
@ -76,40 +93,49 @@ public class PDOMSearchTreeContentProvider implements ITreeContentProvider {
|
||||||
children.add(child);
|
children.add(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void insertName(PDOMName name) {
|
private void insertSearchElement(PDOMSearchElement element) {
|
||||||
IASTFileLocation loc = name.getFileLocation();
|
try {
|
||||||
IPath path = new Path(loc.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) {
|
||||||
insertChild(files[j], name);
|
ICElement celement = CoreModel.getDefault().create(files[j]);
|
||||||
insertResource(files[j]);
|
insertChild(celement, element);
|
||||||
|
insertCElement(celement);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
String pathName = path.toOSString();
|
||||||
|
insertChild(pathName, element);
|
||||||
|
insertChild(result, pathName);
|
||||||
}
|
}
|
||||||
} else {
|
} catch (CoreException e) {
|
||||||
String pathName = path.toOSString();
|
CUIPlugin.getDefault().log(e);
|
||||||
insertChild(pathName, name);
|
|
||||||
insertChild(result, pathName);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void insertResource(IResource resource) {
|
private void insertCElement(ICElement element) {
|
||||||
if (resource instanceof IProject) {
|
if (element instanceof ICProject)
|
||||||
insertChild(result, resource);
|
insertChild(result, element);
|
||||||
} else {
|
else {
|
||||||
IContainer parent = resource.getParent();
|
ICElement parent = element.getParent();
|
||||||
insertChild(parent, resource);
|
if (parent instanceof ISourceRoot && parent.getUnderlyingResource() instanceof IProject)
|
||||||
insertResource(parent);
|
// Skip source roots that are projects
|
||||||
|
parent = parent.getParent();
|
||||||
|
insertChild(parent, element);
|
||||||
|
insertCElement(parent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void elementsChanged(Object[] elements) {
|
public void elementsChanged(Object[] elements) {
|
||||||
if (elements == null || elements.length == 0)
|
if (elements != null)
|
||||||
return;
|
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() {
|
Display.getDefault().asyncExec(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
viewer.refresh();
|
viewer.refresh();
|
||||||
|
@ -118,5 +144,28 @@ public class PDOMSearchTreeContentProvider implements ITreeContentProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clear() {
|
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 {
|
public class PDOMSearchViewPage extends AbstractTextSearchViewPage {
|
||||||
|
|
||||||
private PDOMSearchTreeContentProvider contentProvider;
|
private IPDOMSearchContentProvider contentProvider;
|
||||||
|
|
||||||
public PDOMSearchViewPage(int supportedLayouts) {
|
public PDOMSearchViewPage(int supportedLayouts) {
|
||||||
super(supportedLayouts);
|
super(supportedLayouts);
|
||||||
|
@ -60,38 +60,45 @@ public class PDOMSearchViewPage extends AbstractTextSearchViewPage {
|
||||||
|
|
||||||
protected void configureTreeViewer(TreeViewer viewer) {
|
protected void configureTreeViewer(TreeViewer viewer) {
|
||||||
contentProvider = new PDOMSearchTreeContentProvider();
|
contentProvider = new PDOMSearchTreeContentProvider();
|
||||||
viewer.setContentProvider(contentProvider);
|
viewer.setContentProvider((PDOMSearchTreeContentProvider)contentProvider);
|
||||||
viewer.setLabelProvider(new PDOMSearchLabelProvider());
|
viewer.setLabelProvider(new PDOMSearchTreeLabelProvider(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void configureTableViewer(TableViewer viewer) {
|
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 {
|
protected void showMatch(Match match, int currentOffset, int currentLength, boolean activate) throws PartInitException {
|
||||||
if (!(match instanceof PDOMSearchMatch))
|
if (!(match instanceof PDOMSearchMatch))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
IPath path = new Path(((PDOMSearchMatch)match).getFileName());
|
try {
|
||||||
IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(path);
|
IPath path = new Path(((PDOMSearchMatch)match).getFileName());
|
||||||
if (files.length > 0) {
|
IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(path);
|
||||||
IEditorPart editor = IDE.openEditor(CUIPlugin.getActivePage(), files[0]);
|
if (files.length > 0) {
|
||||||
try {
|
IEditorPart editor = IDE.openEditor(CUIPlugin.getActivePage(), files[0]);
|
||||||
IMarker marker = files[0].createMarker(NewSearchUI.SEARCH_MARKER);
|
try {
|
||||||
marker.setAttribute(IMarker.CHAR_START, currentOffset);
|
IMarker marker = files[0].createMarker(NewSearchUI.SEARCH_MARKER);
|
||||||
marker.setAttribute(IMarker.CHAR_END, currentOffset + currentLength);
|
marker.setAttribute(IMarker.CHAR_START, currentOffset);
|
||||||
IDE.gotoMarker(editor, marker);
|
marker.setAttribute(IMarker.CHAR_END, currentOffset + currentLength);
|
||||||
marker.delete();
|
IDE.gotoMarker(editor, marker);
|
||||||
} catch (CoreException e) {
|
marker.delete();
|
||||||
CUIPlugin.getDefault().log(e);
|
} catch (CoreException e) {
|
||||||
}
|
CUIPlugin.getDefault().log(e);
|
||||||
} else {
|
}
|
||||||
// external file
|
} else {
|
||||||
IEditorInput input = new ExternalEditorInput(new FileStorage(path));
|
// external file
|
||||||
IEditorPart editor = CUIPlugin.getActivePage().openEditor(input, ExternalSearchEditor.EDITOR_ID);
|
IEditorInput input = new ExternalEditorInput(new FileStorage(path));
|
||||||
if (editor instanceof ITextEditor) {
|
IEditorPart editor = CUIPlugin.getActivePage().openEditor(input, ExternalSearchEditor.EDITOR_ID);
|
||||||
ITextEditor textEditor = (ITextEditor)editor;
|
if (editor instanceof ITextEditor) {
|
||||||
textEditor.selectAndReveal(currentOffset, currentLength);
|
ITextEditor textEditor = (ITextEditor)editor;
|
||||||
|
textEditor.selectAndReveal(currentOffset, currentLength);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (CoreException e) {
|
||||||
|
CUIPlugin.getDefault().log(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue