mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-26 18:35:32 +02:00
Check in the IScannerInfo for include paths.
This commit is contained in:
parent
572553e0f9
commit
7edad6b418
1 changed files with 62 additions and 41 deletions
|
@ -5,18 +5,25 @@ package org.eclipse.cdt.internal.ui.editor;
|
||||||
* All Rights Reserved.
|
* All Rights Reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.model.CModelException;
|
import org.eclipse.cdt.core.model.CModelException;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
|
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||||
|
import org.eclipse.cdt.core.parser.IScannerInfoProvider;
|
||||||
|
import org.eclipse.cdt.core.resources.FileStorage;
|
||||||
import org.eclipse.cdt.internal.ui.CPluginImages;
|
import org.eclipse.cdt.internal.ui.CPluginImages;
|
||||||
import org.eclipse.cdt.internal.ui.dialogs.ElementListSelectionDialog;
|
import org.eclipse.cdt.internal.ui.dialogs.ElementListSelectionDialog;
|
||||||
import org.eclipse.cdt.internal.ui.util.EditorUtility;
|
import org.eclipse.cdt.internal.ui.util.EditorUtility;
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
import org.eclipse.core.resources.IContainer;
|
import org.eclipse.core.resources.IContainer;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
|
import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
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;
|
||||||
|
@ -63,46 +70,43 @@ public class OpenIncludeAction extends Action {
|
||||||
IResource res = include.getUnderlyingResource();
|
IResource res = include.getUnderlyingResource();
|
||||||
ArrayList filesFound= new ArrayList(4);
|
ArrayList filesFound= new ArrayList(4);
|
||||||
if (res != null) {
|
if (res != null) {
|
||||||
findFile(res.getProject(), new Path(include.getElementName()), filesFound);
|
IProject proj = res.getProject();
|
||||||
|
String includeName = include.getElementName();
|
||||||
|
// Search in the scannerInfo information
|
||||||
|
IScannerInfoProvider provider = CCorePlugin.getDefault().getScannerInfoProvider(proj);
|
||||||
|
if (provider != null) {
|
||||||
|
IScannerInfo info = provider.getScannerInformation(res);
|
||||||
|
// XXXX this should fall back to project by itself
|
||||||
|
if (info == null) {
|
||||||
|
info = provider.getScannerInformation(proj);
|
||||||
|
}
|
||||||
|
if (info != null) {
|
||||||
|
String[] includePaths = info.getIncludePaths();
|
||||||
|
findFile(includePaths, includeName, filesFound);
|
||||||
|
} else {
|
||||||
|
// Fall back and search the project
|
||||||
|
findFile(proj, new Path(includeName), filesFound);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
IFile fileToOpen;
|
IPath fileToOpen;
|
||||||
int nElementsFound= filesFound.size();
|
int nElementsFound= filesFound.size();
|
||||||
if (nElementsFound == 0) {
|
if (nElementsFound == 0) {
|
||||||
fileToOpen= null;
|
fileToOpen= null;
|
||||||
} else if (nElementsFound == 1) {
|
} else if (nElementsFound == 1) {
|
||||||
fileToOpen= (IFile) filesFound.get(0);
|
fileToOpen= (IPath) filesFound.get(0);
|
||||||
} else {
|
} else {
|
||||||
fileToOpen= chooseFile(filesFound);
|
fileToOpen= chooseFile(filesFound);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fileToOpen != null) {
|
if (fileToOpen != null) {
|
||||||
EditorUtility.openInEditor(fileToOpen);
|
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(fileToOpen);
|
||||||
} else { // Try to get via the include path.
|
if (file != null) {
|
||||||
|
EditorUtility.openInEditor(file);
|
||||||
// This code is for getting the include paths from the builder.
|
} else {
|
||||||
// ICBuilder[] builders = CCorePlugin.getDefault().getBuilders(res.getProject());
|
FileStorage storage = new FileStorage(null, fileToOpen);
|
||||||
//
|
EditorUtility.openInEditor(storage);
|
||||||
// IPath includePath = null;
|
}
|
||||||
// for( int j = 0; includePath == null && j < builders.length; j++ ) {
|
|
||||||
// IPath[] paths = builders[j].getIncludePaths();
|
|
||||||
//
|
|
||||||
// for (int i = 0; i < paths.length; i++) {
|
|
||||||
// if (res != null) {
|
|
||||||
// // We've already scan the project.
|
|
||||||
// if (paths[i].isPrefixOf(res.getProject().getLocation()))
|
|
||||||
// continue;
|
|
||||||
// }
|
|
||||||
// IPath path = paths[i].append(include.getElementName());
|
|
||||||
// if (path.toFile().exists()) {
|
|
||||||
// includePath = path;
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (includePath != null) {
|
|
||||||
// EditorUtility.openInEditor(includePath);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
} catch (CModelException e) {
|
} catch (CModelException e) {
|
||||||
CUIPlugin.getDefault().log(e.getStatus());
|
CUIPlugin.getDefault().log(e.getStatus());
|
||||||
|
@ -111,26 +115,36 @@ public class OpenIncludeAction extends Action {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void findFile(IContainer parent, IPath name, ArrayList res) throws CoreException {
|
private void findFile(String[] includePaths, String name, ArrayList list) throws CoreException {
|
||||||
|
for (int i = 0; i < includePaths.length; i++) {
|
||||||
|
IPath path = new Path(includePaths[i] + "/" + name);
|
||||||
|
File file = path.toFile();
|
||||||
|
if (file.exists()) {
|
||||||
|
list.add(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void findFile(IContainer parent, IPath name, ArrayList list) throws CoreException {
|
||||||
IResource found= parent.findMember(name);
|
IResource found= parent.findMember(name);
|
||||||
if (found != null && found.getType() == IResource.FILE) {
|
if (found != null && found.getType() == IResource.FILE) {
|
||||||
res.add(found);
|
list.add(found.getLocation());
|
||||||
}
|
}
|
||||||
IResource[] children= parent.members();
|
IResource[] children= parent.members();
|
||||||
for (int i= 0; i < children.length; i++) {
|
for (int i= 0; i < children.length; i++) {
|
||||||
if (children[i] instanceof IContainer) {
|
if (children[i] instanceof IContainer) {
|
||||||
findFile((IContainer)children[i], name, res);
|
findFile((IContainer)children[i], name, list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private IFile chooseFile(ArrayList filesFound) {
|
private IPath chooseFile(ArrayList filesFound) {
|
||||||
ILabelProvider renderer= new LabelProvider() {
|
ILabelProvider renderer= new LabelProvider() {
|
||||||
public String getText(Object element) {
|
public String getText(Object element) {
|
||||||
if (element instanceof IFile) {
|
if (element instanceof IPath) {
|
||||||
IFile file= (IFile)element;
|
IPath file= (IPath)element;
|
||||||
return file.getName() + " - " + file.getParent().getFullPath().toString();
|
return file.lastSegment() + " - " + file.toString();
|
||||||
}
|
}
|
||||||
return super.getText(element);
|
return super.getText(element);
|
||||||
}
|
}
|
||||||
|
@ -142,7 +156,7 @@ public class OpenIncludeAction extends Action {
|
||||||
dialog.setElements(filesFound);
|
dialog.setElements(filesFound);
|
||||||
|
|
||||||
if (dialog.open() == Window.OK) {
|
if (dialog.open() == Window.OK) {
|
||||||
return (IFile) dialog.getSelectedElement();
|
return (IPath) dialog.getSelectedElement();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -162,7 +176,14 @@ public class OpenIncludeAction extends Action {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean canActionBeAdded(ISelection selection) {
|
public static boolean canActionBeAdded(ISelection selection) {
|
||||||
return getIncludeStatement(selection) != null;
|
ICElement include = getIncludeStatement(selection);
|
||||||
|
if (include != null) {
|
||||||
|
IResource res = include.getUnderlyingResource();
|
||||||
|
if (res != null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue