Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 211069 Details for
Bug 371562
Non-workspace files are treated differently depending on whether the workspace has any C projects
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Patch with the suggested fix
create-project-for-external-files.txt (text/plain), 8.59 KB, created by
Eugene Ostroukhov
on 2012-02-15 14:27:38 EST
(
hide
)
Description:
Patch with the suggested fix
Filename:
MIME Type:
Creator:
Eugene Ostroukhov
Created:
2012-02-15 14:27:38 EST
Size:
8.59 KB
patch
obsolete
>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 2c1f8c9..68f8053 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 >@@ -36,9 +36,12 @@ import org.eclipse.core.resources.IContainer; > import org.eclipse.core.resources.IFile; > import org.eclipse.core.resources.IFolder; > import org.eclipse.core.resources.IProject; >+import org.eclipse.core.resources.IProjectDescription; > import org.eclipse.core.resources.IResource; > import org.eclipse.core.resources.IStorage; >+import org.eclipse.core.resources.IWorkspace; > import org.eclipse.core.resources.IWorkspaceRoot; >+import org.eclipse.core.resources.IWorkspaceRunnable; > import org.eclipse.core.resources.ResourcesPlugin; > import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.IPath; >@@ -50,9 +53,11 @@ import org.eclipse.core.runtime.Path; > import org.eclipse.core.runtime.Platform; > import org.eclipse.core.runtime.SafeRunner; > import org.eclipse.core.runtime.Status; >+import org.eclipse.core.runtime.SubMonitor; > import org.eclipse.core.runtime.SubProgressMonitor; > import org.eclipse.core.runtime.content.IContentType; > import org.eclipse.jface.action.Action; >+import org.eclipse.jface.preference.IPreferenceStore; > import org.eclipse.jface.text.BadLocationException; > import org.eclipse.jface.text.IDocument; > import org.eclipse.jface.text.IRegion; >@@ -81,12 +86,15 @@ import org.eclipse.ui.texteditor.ITextEditor; > > import com.ibm.icu.text.MessageFormat; > >+import org.eclipse.cdt.core.CCProjectNature; > import org.eclipse.cdt.core.CCorePlugin; >+import org.eclipse.cdt.core.CProjectNature; > import org.eclipse.cdt.core.model.CModelException; > import org.eclipse.cdt.core.model.CoreModel; > import org.eclipse.cdt.core.model.IBinary; > import org.eclipse.cdt.core.model.IBuffer; > import org.eclipse.cdt.core.model.ICElement; >+import org.eclipse.cdt.core.model.ICModel; > import org.eclipse.cdt.core.model.ICProject; > import org.eclipse.cdt.core.model.IIncludeReference; > import org.eclipse.cdt.core.model.ISourceRange; >@@ -367,22 +375,42 @@ public class EditorUtility { > // include paths > try { > ICProject[] projects = CCorePlugin.getDefault().getCoreModel().getCModel().getCProjects(); >- outerFor: for (int i = 0; i < projects.length; i++) { >- IIncludeReference[] includeReferences = projects[i].getIncludeReferences(); >- for (int j = 0; j < includeReferences.length; j++) { >- // crecoskie test >- // TODO FIXME >- // include entries don't handle URIs yet, so fake it out for now >- IPath path = URIUtil.toPath(locationURI); >- if(path == null) >- path = new Path(locationURI.getPath()); >- >- if (includeReferences[j].isOnIncludeEntry(path)) { >- context = projects[i]; >- break outerFor; >+ if (projects.length == 1) { >+ // Special case 1 - all non-workspace files will use project configuration >+ // from workspace project when there is only one such project >+ context = projects[0]; >+ } else if (projects.length == 2) { >+ // Special case 2 - when there's only a synthetic project and single user >+ // project, use user project as a context. >+ if (isSyntheticProject(projects[0])) { >+ context = projects[1]; >+ } else if (isSyntheticProject(projects[1])) { >+ context = projects[0]; >+ } else { >+ // Fallback to default multi-project scenario >+ } >+ } >+ if (context == null) { >+ outerFor: for (int i = 0; i < projects.length; i++) { >+ IIncludeReference[] includeReferences = projects[i].getIncludeReferences(); >+ for (int j = 0; j < includeReferences.length; j++) { >+ // crecoskie test >+ // TODO FIXME >+ // include entries don't handle URIs yet, so fake it out for now >+ IPath path = URIUtil.toPath(locationURI); >+ if(path == null) >+ path = new Path(locationURI.getPath()); >+ >+ if (includeReferences[j].isOnIncludeEntry(path)) { >+ context = projects[i]; >+ break outerFor; >+ } > } > } > } >+ if (context == null) { >+ context= createSyntheticProject(); >+ } > if (context == null && projects.length > 0) { > // last resort: just take any of them > context= projects[0]; >@@ -418,6 +446,62 @@ public class EditorUtility { > return new ExternalEditorInput(locationURI); > } > >+ private static synchronized ICElement createSyntheticProject() { >+ try { >+ // Potential race condition - several editors opening concurrently, hence synchronized >+ // and this double-check >+ ICModel model = CCorePlugin.getDefault().getCoreModel().getCModel(); >+ ICProject[] projects = model.getCProjects(); >+ for (ICProject project : projects) { >+ if (isSyntheticProject(project)) { >+ return project; >+ } >+ } >+ final IPreferenceStore preferenceStore = CUIPlugin.getDefault().getPreferenceStore(); >+ if (!preferenceStore.getBoolean("noSyntheticProject")) { //$NON-NLS-1$ >+ final IWorkspace workspace = CUIPlugin.getWorkspace(); >+ workspace.run(new IWorkspaceRunnable() { >+ public void run(IProgressMonitor monitor) throws CoreException { >+ SubMonitor subMonitor = SubMonitor.convert(monitor, >+ Messages.EditorUtility_creatingSyntheticProject_message, 300); >+ final IProjectDescription projectDescription = workspace >+ .newProjectDescription(getSyntheticProjectName()); >+ final IProject project = workspace.getRoot().getProject(projectDescription.getName()); >+ final int flags; >+ if (!preferenceStore.getBoolean("visibleSyntheticProject")) { //$NON-NLS-1$ >+ flags = IResource.HIDDEN; >+ } else { >+ flags = 0; >+ } >+ project.create(projectDescription, flags, subMonitor.newChild(100)); >+ project.open(subMonitor.newChild(100)); >+ CProjectNature.addCNature(project, subMonitor.newChild(100)); >+ CCProjectNature.addCCNature(project, subMonitor.newChild(100)); >+ if (monitor != null) { >+ monitor.done(); >+ } >+ } >+ }, null); // No progress monitor/cancellation - there will be a one-time slowdown >+ return model.getCProject(getSyntheticProjectName()); >+ } else { >+ return null; >+ } >+ } catch (CoreException e) { >+ // Do nothing, log and bail out >+ CUIPlugin.log(e); >+ return null; >+ } >+ } >+ >+ private static boolean isSyntheticProject(ICProject icProject) { >+ return icProject.getElementName().equals(getSyntheticProjectName()); >+ } >+ >+ private static String getSyntheticProjectName() { >+ String name = CUIPlugin.getDefault().getPreferenceStore().getString("syntheticProjectName"); //$NON-NLS-1$ >+ return name != null && !"".equals(name.trim()) ? name : ".cdtexternalfilessupport"; //$NON-NLS-1$ //$NON-NLS-2$ >+ } >+ > public static IEditorInput getEditorInputForLocation(IPath location, ICElement context) { > IFile resource= getWorkspaceFileAtLocation(location, context); > if (resource != null) { >diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/Messages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/Messages.java >index 704f586..ed7f03a 100644 >--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/Messages.java >+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/Messages.java >@@ -19,6 +19,7 @@ public class Messages extends NLS { > private static final String BUNDLE_NAME= Messages.class.getName(); > > public static String EditorUtility_calculatingChangedRegions_message; >+ public static String EditorUtility_creatingSyntheticProject_message; > public static String EditorUtility_error_calculatingChangedRegions; > > public static String OpenExternalProblemAction_CannotReadExternalLocation; >diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/Messages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/Messages.properties >index 4fc6559..3d61413 100644 >--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/Messages.properties >+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/Messages.properties >@@ -10,6 +10,7 @@ > ############################################################################### > > EditorUtility_calculatingChangedRegions_message=Calculating changed regions >+EditorUtility_creatingSyntheticProject_message=Creating a synthetic project > EditorUtility_error_calculatingChangedRegions=An error occurred while calculating the changed regions. See error log for details. > OpenExternalProblemAction_CannotReadExternalLocation=Cannot read external location {0} > OpenExternalProblemAction_ErrorOpeningFile=Error Opening File
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 371562
: 211069