From 3a46db2f3467130b81d42de3e8c2926f9610e87d Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Mon, 28 Aug 2006 11:43:18 +0000 Subject: [PATCH] Include Browser: Drop support for external files. --- .../cdt/internal/corext/util/CModelUtil.java | 7 ++++-- .../ui/includebrowser/IBConversions.java | 24 +++++++++++++++---- 2 files changed, 25 insertions(+), 6 deletions(-) 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 9d61d065272..bd7d25510b1 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 @@ -159,12 +159,15 @@ public class CModelUtil { } else { CoreModel coreModel = CoreModel.getDefault(); - ITranslationUnit tu= coreModel.createTranslationUnitFrom(preferredProject, location); + ITranslationUnit tu= null; + if (preferredProject != null) { + 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)) { + if (!project.equals(preferredProject)) { tu= coreModel.createTranslationUnitFrom(project, location); } } 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 93dbd931557..b140da6be46 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 @@ -15,10 +15,14 @@ import java.util.Iterator; import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IPath; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.editors.text.ILocationProvider; +import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.ITranslationUnit; +import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.internal.corext.util.CModelUtil; @@ -55,6 +59,9 @@ public class IBConversions { if (object instanceof ITranslationUnit) { return (ITranslationUnit) object; } + if (object instanceof IFile) { + return CModelUtil.findTranslationUnit((IFile) object); + } if (object instanceof IAdaptable) { IAdaptable adaptable = (IAdaptable) object; ITranslationUnit result= (ITranslationUnit) adaptable.getAdapter(ITranslationUnit.class); @@ -63,10 +70,19 @@ public class IBConversions { } IFile file= (IFile) adaptable.getAdapter(IFile.class); if (file != null) { - result= CModelUtil.findTranslationUnit(file); - if (result != null) { - return result; - } + return CModelUtil.findTranslationUnit(file); + } + + ILocationProvider locProvider= (ILocationProvider) adaptable.getAdapter(ILocationProvider.class); + if (locProvider != null) { + IPath path= locProvider.getPath(locProvider); + if (path != null) { + try { + return CModelUtil.findTranslationUnitForLocation(path, null); + } catch (CModelException e) { + CUIPlugin.getDefault().log(e); + } + } } } return null;