diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/util/CModelUtil.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/util/CModelUtil.java
index 857e1c8115e..9d61d065272 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/util/CModelUtil.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/util/CModelUtil.java
@@ -11,15 +11,21 @@
*******************************************************************************/
package org.eclipse.cdt.internal.corext.util;
+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.IPath;
+import org.eclipse.cdt.core.model.CModelException;
+import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICContainer;
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.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.IWorkingCopy;
+import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.ui.util.EditorUtility;
@@ -114,4 +120,57 @@ public class CModelUtil {
}
return null;
}
+
+ /**
+ * Returns the translation unit for the file given or null
.
+ */
+ public static ITranslationUnit findTranslationUnit(IFile file) {
+ if (CoreModel.isTranslationUnit(file)) {
+ ICProject cp= CoreModel.getDefault().getCModel().getCProject(file.getProject().getName());
+ if (cp != null) {
+ ICElement tu;
+ try {
+ tu = cp.findElement(file.getProjectRelativePath());
+ if (tu instanceof ITranslationUnit) {
+ return (ITranslationUnit) tu;
+ }
+ } catch (CModelException e) {
+ CUIPlugin.getDefault().log(e);
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns the translation unit for the location given or null
.
+ * @throws CModelException
+ */
+ public static ITranslationUnit findTranslationUnitForLocation(IPath location, ICProject preferredProject) throws CModelException {
+ IFile[] files= ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(location);
+ if (files.length > 0) {
+ for (int i = 0; i < files.length; i++) {
+ IFile file = files[i];
+ ITranslationUnit tu= findTranslationUnit(file);
+ if (tu != null) {
+ return tu;
+ }
+ }
+ }
+ else {
+ CoreModel coreModel = CoreModel.getDefault();
+ ITranslationUnit tu= coreModel.createTranslationUnitFrom(preferredProject, location);
+ if (tu == null) {
+ ICProject[] projects= coreModel.getCModel().getCProjects();
+ for (int i = 0; i < projects.length && tu == null; i++) {
+ ICProject project = projects[i];
+ if (!preferredProject.equals(project)) {
+ tu= coreModel.createTranslationUnitFrom(project, location);
+ }
+ }
+ }
+ return tu;
+ }
+ return null;
+ }
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHContentProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHContentProvider.java
index b20b69f77a7..e5f5ad9049f 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHContentProvider.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHContentProvider.java
@@ -12,6 +12,7 @@
package org.eclipse.cdt.internal.ui.callhierarchy;
import java.util.ArrayList;
+import java.util.Arrays;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -120,6 +121,7 @@ public class CHContentProvider extends AsyncTreeContentProvider {
private CHNode createRefbyNode(CHNode parent, ICElement element, CIndexReference[] refs) {
ITranslationUnit tu= CModelUtil.getTranslationUnit(element);
CHNode node= new CHNode(parent, tu, refs[0].getTimestamp(), element);
+ Arrays.sort(refs, CIndexReference.COMPARE_OFFSET);
for (int i = 0; i < refs.length; i++) {
CIndexReference reference = refs[i];
node.addReference(new CHReferenceInfo(reference.getOffset(), reference.getLength()));
@@ -130,6 +132,7 @@ public class CHContentProvider extends AsyncTreeContentProvider {
private CHNode createReftoNode(CHNode parent, ITranslationUnit tu, ICElement[] elements, CIndexReference[] references) {
CIndexReference firstRef= references[0];
CHNode node= new CHNode(parent, tu, firstRef.getTimestamp(), elements[0]);
+ Arrays.sort(references, CIndexReference.COMPARE_OFFSET);
for (int i = 0; i < references.length; i++) {
CIndexReference reference = references[i];
node.addReference(new CHReferenceInfo(reference.getOffset(), reference.getLength()));
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHLabelProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHLabelProvider.java
index 73a1e7ed65a..9f71e526093 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHLabelProvider.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHLabelProvider.java
@@ -24,16 +24,18 @@ import org.eclipse.swt.widgets.Display;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.ui.CElementImageDescriptor;
-import org.eclipse.cdt.ui.CElementLabelProvider;
+import org.eclipse.cdt.internal.ui.viewsupport.CElementLabels;
+import org.eclipse.cdt.internal.ui.viewsupport.CUILabelProvider;
import org.eclipse.cdt.internal.ui.viewsupport.ImageImageDescriptor;
public class CHLabelProvider extends LabelProvider implements IColorProvider {
- private CElementLabelProvider fCLabelProvider= new CElementLabelProvider(CElementLabelProvider.SHOW_PARAMETERS);
-// private Color fColorInactive;
+ private final static int LABEL_OPTIONS_SIMPLE= CElementLabels.ALL_FULLY_QUALIFIED | CElementLabels.M_PARAMETER_TYPES;
+ private final static int LABEL_OPTIONS_SHOW_FILES= LABEL_OPTIONS_SIMPLE | CElementLabels.MF_POST_FILE_QUALIFIED;
+
+ private CUILabelProvider fCLabelProvider= new CUILabelProvider(LABEL_OPTIONS_SIMPLE, 0);
private CHContentProvider fContentProvider;
private HashMap fCachedImages= new HashMap();
- private boolean fShowFiles;
public CHLabelProvider(Display display, CHContentProvider cp) {
// fColorInactive= display.getSystemColor(SWT.COLOR_DARK_GRAY);
@@ -57,22 +59,7 @@ public class CHLabelProvider extends LabelProvider implements IColorProvider {
CHNode node= (CHNode) element;
ICElement decl= node.getRepresentedDeclaration();
if (decl != null) {
- String text= fCLabelProvider.getText(decl);
- if (fShowFiles) {
- // mstodo append filenames
-// ICElement tu= null;
-// while (tu == null && decl != null) {
-// if (decl instanceof ITranslationUnit) {
-// tu= decl;
-// }
-// else {
-// decl= decl.getParent();
-// }
-// }
-// if (tu != null) {
-//
- }
- return text;
+ return fCLabelProvider.getText(decl);
}
}
return super.getText(element);
@@ -118,16 +105,10 @@ public class CHLabelProvider extends LabelProvider implements IColorProvider {
}
public Color getForeground(Object element) {
-// if (element instanceof CHNode) {
-// CHNode node= (CHNode) element;
-// if (!node.isActiveCode()) {
-// return fColorInactive;
-// }
-// }
return null;
}
public void setShowFiles(boolean show) {
- fShowFiles= show;
+ fCLabelProvider.setTextFlags(show ? LABEL_OPTIONS_SHOW_FILES : LABEL_OPTIONS_SIMPLE);
}
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHMessages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHMessages.properties
index 1a48a2dbbb8..20752fa6eee 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHMessages.properties
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHMessages.properties
@@ -9,8 +9,8 @@ CHViewPart_FilterVariables_label=Filter Variables
CHViewPart_FilterVariables_tooltip=Hide Variables, Constents and Enumerators
CHViewPart_HideMacros_label=Hide Macros
CHViewPart_HideMacros_tooltip=Hides Macros
-CHViewPart_ShowFiles_label=Show Files
-CHViewPart_ShowFiles_tooltip=Show Files
+CHViewPart_ShowFiles_label=Show File Names
+CHViewPart_ShowFiles_tooltip=Show File Names
CHViewPart_NextReference_label=Next Reference
CHViewPart_NextReference_tooltip=Show Next Reference
CHHistoryListAction_Remove_label=Remove
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHViewPart.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHViewPart.java
index a78eaa25672..89dd000d76c 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHViewPart.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHViewPart.java
@@ -83,6 +83,7 @@ public class CHViewPart extends ViewPart {
private static final String KEY_WORKING_SET_FILTER = "workingSetFilter"; //$NON-NLS-1$
private static final String KEY_FILTER_VARIABLES = "variableFilter"; //$NON-NLS-1$
private static final String KEY_FILTER_MACROS = "macroFilter"; //$NON-NLS-1$
+ private static final String KEY_SHOW_FILES= "showFilesInLabels"; //$NON-NLS-1$
private IMemento fMemento;
private boolean fShowsMessage;
@@ -208,12 +209,17 @@ public class CHViewPart extends ViewPart {
boolean referencedBy= true;
boolean filterVariables= false;
boolean filterMacros= false;
+ boolean showFiles= false;
if (fMemento != null) {
filterVariables= TRUE.equals(fMemento.getString(KEY_FILTER_VARIABLES));
filterMacros= TRUE.equals(fMemento.getString(KEY_FILTER_MACROS));
+ showFiles= TRUE.equals(fMemento.getString(KEY_SHOW_FILES));
}
+ fLabelProvider.setShowFiles(showFiles);
+ fShowFilesInLabelsAction.setChecked(showFiles);
+
fReferencedByAction.setChecked(referencedBy);
fMakesReferenceToAction.setChecked(!referencedBy);
fContentProvider.setComputeReferencedBy(referencedBy);
@@ -237,6 +243,7 @@ public class CHViewPart extends ViewPart {
}
memento.putString(KEY_FILTER_MACROS, String.valueOf(fFilterMacrosAction.isChecked()));
memento.putString(KEY_FILTER_VARIABLES, String.valueOf(fFilterVariablesAction.isChecked()));
+ memento.putString(KEY_SHOW_FILES, String.valueOf(fShowFilesInLabelsAction.isChecked()));
super.saveState(memento);
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/MainActionGroup.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/MainActionGroup.java
index a0ff0073336..bb994b601e0 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/MainActionGroup.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/MainActionGroup.java
@@ -192,7 +192,7 @@ public class MainActionGroup extends CViewActionGroup {
addSearchMenu(menu, celements);
menu.add(new Separator(IContextMenuConstants.GROUP_ADDITIONS));
menu.add(new Separator(IContextMenuConstants.GROUP_ADDITIONS + "-end")); //$NON-NLS-1$
- menu.add(new Separator());
+ menu.add(new Separator(IContextMenuConstants.GROUP_PROPERTIES));
openViewActionGroup.fillContextMenu(menu);
crefactoringActionGroup.fillContextMenu(menu);
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBConversions.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBConversions.java
index a18f62179ca..93dbd931557 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBConversions.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBConversions.java
@@ -18,27 +18,11 @@ import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.cdt.core.model.*;
-import org.eclipse.cdt.ui.CUIPlugin;
+import org.eclipse.cdt.core.model.ITranslationUnit;
+
+import org.eclipse.cdt.internal.corext.util.CModelUtil;
public class IBConversions {
- public static ITranslationUnit fileToTU(IFile file) {
- if (CoreModel.isTranslationUnit(file)) {
- ICProject cp= CoreModel.getDefault().getCModel().getCProject(file.getProject().getName());
- if (cp != null) {
- ICElement tu;
- try {
- tu = cp.findElement(file.getProjectRelativePath());
- if (tu instanceof ITranslationUnit) {
- return (ITranslationUnit) tu;
- }
- } catch (CModelException e) {
- CUIPlugin.getDefault().log(e);
- }
- }
- }
- return null;
- }
public static IBNode selectionToNode(ISelection sel) {
if (sel instanceof IStructuredSelection) {
@@ -79,7 +63,7 @@ public class IBConversions {
}
IFile file= (IFile) adaptable.getAdapter(IFile.class);
if (file != null) {
- result= fileToTU(file);
+ result= CModelUtil.findTranslationUnit(file);
if (result != null) {
return result;
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBDropTargetListener.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBDropTargetListener.java
index d23b0040028..3f018a9b34c 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBDropTargetListener.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBDropTargetListener.java
@@ -32,6 +32,8 @@ import org.eclipse.ui.part.ResourceTransfer;
import org.eclipse.cdt.core.model.ITranslationUnit;
+import org.eclipse.cdt.internal.corext.util.CModelUtil;
+
public class IBDropTargetListener implements DropTargetListener {
private IBViewPart fIncludeBrowser;
@@ -138,7 +140,7 @@ public class IBDropTargetListener implements DropTargetListener {
for (int i = 0; i < files.length; i++) {
IResource resource = files[i];
if (resource.getType() == IResource.FILE) {
- ITranslationUnit tu= IBConversions.fileToTU((IFile) resource);
+ ITranslationUnit tu= CModelUtil.findTranslationUnit((IFile) resource);
if (tu != null) {
return tu;
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBFile.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBFile.java
index d404e044738..f5f94f505ce 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBFile.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBFile.java
@@ -13,14 +13,14 @@ package org.eclipse.cdt.internal.ui.includebrowser;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.cdt.core.model.CModelException;
-import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ITranslationUnit;
+import org.eclipse.cdt.internal.corext.util.CModelUtil;
+
import org.eclipse.cdt.internal.ui.util.CoreUtility;
public class IBFile {
@@ -40,26 +40,7 @@ public class IBFile {
public IBFile(ICProject preferredProject, IPath location) throws CModelException {
fLocation= location;
- IFile[] files= ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(location);
- if (files.length > 0) {
- for (int i = 0; i < files.length && fTU == null; i++) {
- IFile file = files[i];
- fTU= IBConversions.fileToTU(file);
- }
- }
- else {
- CoreModel coreModel = CoreModel.getDefault();
- fTU= coreModel.createTranslationUnitFrom(preferredProject, location);
- if (fTU == null) {
- ICProject[] projects= coreModel.getCModel().getCProjects();
- for (int i = 0; i < projects.length && fTU == null; i++) {
- ICProject project = projects[i];
- if (!preferredProject.equals(project)) {
- fTU= coreModel.createTranslationUnitFrom(project, location);
- }
- }
- }
- }
+ fTU= CModelUtil.findTranslationUnitForLocation(location, preferredProject);
}
public IPath getLocation() {
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/missingapi/CIndexQueries.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/missingapi/CIndexQueries.java
index 6dd7271e003..d0bbe93c6c2 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/missingapi/CIndexQueries.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/missingapi/CIndexQueries.java
@@ -49,6 +49,7 @@ 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.PDOMInclude;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
+import org.eclipse.cdt.internal.corext.util.CModelUtil;
public class CIndexQueries {
public static class IPDOMInclude {
@@ -98,11 +99,7 @@ public class CIndexQueries {
private static ITranslationUnit toTranslationUnit(ICProject cproject, String pathStr) throws CModelException {
IPath path= Path.fromOSString(pathStr);
- ICElement e= cproject.findElement(path);
- if (e instanceof ITranslationUnit) {
- return (ITranslationUnit) e;
- }
- return null;
+ return CModelUtil.findTranslationUnitForLocation(path, cproject);
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/missingapi/CIndexReference.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/missingapi/CIndexReference.java
index 9388baa21ef..242380ae37f 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/missingapi/CIndexReference.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/missingapi/CIndexReference.java
@@ -11,10 +11,19 @@
package org.eclipse.cdt.internal.ui.missingapi;
+import java.util.Comparator;
+
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.model.ITranslationUnit;
public class CIndexReference {
+ public static final Comparator COMPARE_OFFSET = new Comparator() {
+ public int compare(Object o1, Object o2) {
+ CIndexReference r1= (CIndexReference) o1;
+ CIndexReference r2= (CIndexReference) o2;
+ return r1.fOffset - r2.fOffset;
+ }
+ };
private int fOffset;
private int fLength;
private ITranslationUnit fTranslationUnit;
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/EditorUtility.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/EditorUtility.java
index c2079ae8a2f..4d2bace7a77 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/EditorUtility.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/EditorUtility.java
@@ -7,6 +7,7 @@
*
* Contributors:
* QNX Software Systems - Initial API and implementation
+ * Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.util;
@@ -258,7 +259,7 @@ public class EditorUtility {
}
if (input instanceof IStorage) {
- return new ExternalEditorInput((IStorage)input, null);
+ return new ExternalEditorInput((IStorage)input);
}
return null;
}