1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Improve path to resource conversion when opening an editor (related to bug 211056)

This commit is contained in:
Anton Leherbauer 2007-12-12 14:20:49 +00:00
parent 1d3da89cf0
commit 214698ca9c

View file

@ -358,8 +358,9 @@ public class EditorUtility {
* @return an <code>IFile</code> or <code>null</code> * @return an <code>IFile</code> or <code>null</code>
*/ */
private static IFile getWorkspaceFileAtLocation(IPath location, ICElement context) { private static IFile getWorkspaceFileAtLocation(IPath location, ICElement context) {
// search non-linked resource
IFile file= FileBuffers.getWorkspaceFileAtLocation(location); IFile file= FileBuffers.getWorkspaceFileAtLocation(location);
if (file == null) { if (file == null || !CoreModel.hasCNature(file.getProject())) {
// try to find a linked resource // try to find a linked resource
IProject project= null; IProject project= null;
if (context != null) { if (context != null) {
@ -369,24 +370,27 @@ public class EditorUtility {
} }
} }
IFile bestMatch= null; IFile bestMatch= null;
IFile secondBestMatch= null;
IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot(); IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot();
IFile[] files= root.findFilesForLocation(location); IFile[] files= root.findFilesForLocation(location);
for (int i= 0; i < files.length; i++) { for (int i= 0; i < files.length; i++) {
file= files[i]; file= files[i];
if (file.isAccessible()) { if (file.isAccessible()) {
if (project != null && file.getProject() == project) { if (project != null && file.getProject().equals(project)) {
bestMatch= file; bestMatch= file;
break; break;
} } else if (CoreModel.hasCNature(file.getProject())) {
if (bestMatch == null) {
bestMatch= file; bestMatch= file;
if (project == null) { if (project == null) {
break; break;
} }
} else {
// match in non-CDT project
secondBestMatch= file;
} }
} }
} }
return bestMatch; return bestMatch != null ? bestMatch : secondBestMatch;
} }
return file; return file;
} }