Lines 1-5
Link Here
|
1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2005 IBM Corporation and others. |
2 |
* Copyright (c) 2005, 2006 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
Lines 8-27
Link Here
|
8 |
* Contributors: |
8 |
* Contributors: |
9 |
* IBM Corporation - initial API and implementation |
9 |
* IBM Corporation - initial API and implementation |
10 |
* QNX Software System |
10 |
* QNX Software System |
|
|
11 |
* Sergey Prigogin, Google - https://bugs.eclipse.org/bugs/show_bug.cgi?id=13221 |
11 |
*******************************************************************************/ |
12 |
*******************************************************************************/ |
12 |
package org.eclipse.cdt.internal.ui.editor; |
13 |
package org.eclipse.cdt.internal.ui.editor; |
13 |
|
14 |
|
14 |
import java.io.File; |
15 |
import java.io.File; |
15 |
import java.io.IOException; |
|
|
16 |
import java.util.ArrayList; |
16 |
import java.util.ArrayList; |
17 |
import java.util.HashSet; |
17 |
import java.util.HashSet; |
18 |
import java.util.List; |
18 |
import java.util.List; |
19 |
|
19 |
|
20 |
import org.eclipse.core.resources.IContainer; |
20 |
import org.eclipse.core.resources.IContainer; |
|
|
21 |
import org.eclipse.core.resources.IFile; |
21 |
import org.eclipse.core.resources.IProject; |
22 |
import org.eclipse.core.resources.IProject; |
22 |
import org.eclipse.core.resources.IResource; |
23 |
import org.eclipse.core.resources.IResource; |
23 |
import org.eclipse.core.resources.IResourceProxy; |
24 |
import org.eclipse.core.resources.IResourceProxy; |
24 |
import org.eclipse.core.resources.IResourceProxyVisitor; |
25 |
import org.eclipse.core.resources.IResourceProxyVisitor; |
|
|
26 |
import org.eclipse.core.resources.IWorkspaceRoot; |
25 |
import org.eclipse.core.resources.ResourcesPlugin; |
27 |
import org.eclipse.core.resources.ResourcesPlugin; |
26 |
import org.eclipse.core.runtime.CoreException; |
28 |
import org.eclipse.core.runtime.CoreException; |
27 |
import org.eclipse.core.runtime.IPath; |
29 |
import org.eclipse.core.runtime.IPath; |
Lines 35-43
Link Here
|
35 |
import org.eclipse.jface.window.Window; |
37 |
import org.eclipse.jface.window.Window; |
36 |
import org.eclipse.swt.SWT; |
38 |
import org.eclipse.swt.SWT; |
37 |
import org.eclipse.swt.widgets.MessageBox; |
39 |
import org.eclipse.swt.widgets.MessageBox; |
38 |
import org.eclipse.ui.IEditorDescriptor; |
|
|
39 |
import org.eclipse.ui.IEditorRegistry; |
40 |
import org.eclipse.ui.PlatformUI; |
41 |
|
40 |
|
42 |
import org.eclipse.cdt.core.CCorePlugin; |
41 |
import org.eclipse.cdt.core.CCorePlugin; |
43 |
import org.eclipse.cdt.core.model.CModelException; |
42 |
import org.eclipse.cdt.core.model.CModelException; |
Lines 94-101
Link Here
|
94 |
} |
93 |
} |
95 |
if (info != null) { |
94 |
if (info != null) { |
96 |
String[] includePaths = info.getIncludePaths(); |
95 |
String[] includePaths = info.getIncludePaths(); |
97 |
HashSet found = new HashSet(); |
96 |
findFile(includePaths, includeName, filesFound); |
98 |
findFile(includePaths, includeName, filesFound, found); |
|
|
99 |
} |
97 |
} |
100 |
if (filesFound.size() == 0) { |
98 |
if (filesFound.size() == 0) { |
101 |
// Fall back and search the project |
99 |
// Fall back and search the project |
Lines 135-175
Link Here
|
135 |
} |
133 |
} |
136 |
|
134 |
|
137 |
private boolean isInProject(IPath path) { |
135 |
private boolean isInProject(IPath path) { |
138 |
return ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path) != null; |
136 |
return getWorkspaceRoot().getFileForLocation(path) != null; |
139 |
} |
137 |
} |
140 |
|
138 |
|
141 |
// If 'path' is not a resource in the current workspace and |
139 |
/** |
142 |
// it is a symlink to a resource that is in the current workspace, |
140 |
* Returns the path as is, if it points to a workspace resource. If the path |
143 |
// use the symlink target instead |
141 |
* does not point to a workspace resource, but there are linked workspace |
144 |
private IPath resolveIncludeLink(File file, IPath path) { |
142 |
* resources pointing to it, returns the paths of these resources. |
145 |
if (isInProject(path)) |
143 |
* Othervise, returns the path as is. |
146 |
return path; |
144 |
*/ |
147 |
|
145 |
private IPath[] resolveIncludeLink(IPath path) { |
148 |
try { |
146 |
if (!isInProject(path)) { |
149 |
String canon = file.getCanonicalPath(); |
147 |
IFile[] files = getWorkspaceRoot().findFilesForLocation(path); |
150 |
if (canon.equals(file.getAbsolutePath())) |
148 |
if (files.length > 0) { |
151 |
return path; |
149 |
IPath[] paths = new IPath[files.length]; |
152 |
|
150 |
for (int i = 0; i < files.length; i++) { |
153 |
IPath p = Path.fromOSString(canon); |
151 |
paths[i] = files[i].getFullPath(); |
154 |
if (isInProject(p)) |
152 |
} |
155 |
return p; |
153 |
return paths; |
156 |
} catch (IOException e) { |
154 |
} |
157 |
// Do nothing; the path is not resolved |
|
|
158 |
} |
155 |
} |
159 |
|
156 |
|
160 |
return path; |
157 |
return new IPath[] { path }; |
|
|
158 |
} |
159 |
|
160 |
private IWorkspaceRoot getWorkspaceRoot() { |
161 |
return ResourcesPlugin.getWorkspace().getRoot(); |
161 |
} |
162 |
} |
162 |
|
163 |
|
163 |
private void findFile(String[] includePaths, String name, ArrayList list, |
164 |
private void findFile(String[] includePaths, String name, ArrayList list) |
164 |
HashSet foundSet) throws CoreException { |
165 |
throws CoreException { |
|
|
166 |
HashSet foundSet = new HashSet(); |
165 |
for (int i = 0; i < includePaths.length; i++) { |
167 |
for (int i = 0; i < includePaths.length; i++) { |
166 |
IPath path = new Path(includePaths[i] + "/" + name); //$NON-NLS-1$ |
168 |
IPath path = new Path(includePaths[i] + "/" + name); //$NON-NLS-1$ |
167 |
File file = path.toFile(); |
169 |
File file = path.toFile(); |
168 |
if (file.exists()) { |
170 |
if (file.exists()) { |
169 |
IPath p = resolveIncludeLink(file, path); |
171 |
IPath[] paths = resolveIncludeLink(path); |
170 |
if (!foundSet.contains(p)) { |
172 |
for (int j = 0; j < paths.length; j++) { |
171 |
foundSet.add(p); |
173 |
IPath p = paths[j]; |
172 |
list.add(p); |
174 |
if (foundSet.add(p)) { |
|
|
175 |
list.add(p); |
176 |
} |
173 |
} |
177 |
} |
174 |
} |
178 |
} |
175 |
} |
179 |
} |
Lines 248-263
Link Here
|
248 |
return false; |
252 |
return false; |
249 |
} |
253 |
} |
250 |
|
254 |
|
251 |
|
|
|
252 |
public static String getEditorID(String name) { |
253 |
IEditorRegistry registry = PlatformUI.getWorkbench().getEditorRegistry(); |
254 |
if (registry != null) { |
255 |
IEditorDescriptor descriptor = registry.getDefaultEditor(name); |
256 |
if (descriptor != null) { |
257 |
return descriptor.getId(); |
258 |
} |
259 |
return IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID; |
260 |
} |
261 |
return null; |
262 |
} |
263 |
} |
255 |
} |