View | Details | Raw Unified | Return to bug 371562
Collapse All | Expand All

(-)a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/EditorUtility.java (-13 / +97 lines)
Lines 36-44 import org.eclipse.core.resources.IContainer; Link Here
36
import org.eclipse.core.resources.IFile;
36
import org.eclipse.core.resources.IFile;
37
import org.eclipse.core.resources.IFolder;
37
import org.eclipse.core.resources.IFolder;
38
import org.eclipse.core.resources.IProject;
38
import org.eclipse.core.resources.IProject;
39
import org.eclipse.core.resources.IProjectDescription;
39
import org.eclipse.core.resources.IResource;
40
import org.eclipse.core.resources.IResource;
40
import org.eclipse.core.resources.IStorage;
41
import org.eclipse.core.resources.IStorage;
42
import org.eclipse.core.resources.IWorkspace;
41
import org.eclipse.core.resources.IWorkspaceRoot;
43
import org.eclipse.core.resources.IWorkspaceRoot;
44
import org.eclipse.core.resources.IWorkspaceRunnable;
42
import org.eclipse.core.resources.ResourcesPlugin;
45
import org.eclipse.core.resources.ResourcesPlugin;
43
import org.eclipse.core.runtime.CoreException;
46
import org.eclipse.core.runtime.CoreException;
44
import org.eclipse.core.runtime.IPath;
47
import org.eclipse.core.runtime.IPath;
Lines 50-58 import org.eclipse.core.runtime.Path; Link Here
50
import org.eclipse.core.runtime.Platform;
53
import org.eclipse.core.runtime.Platform;
51
import org.eclipse.core.runtime.SafeRunner;
54
import org.eclipse.core.runtime.SafeRunner;
52
import org.eclipse.core.runtime.Status;
55
import org.eclipse.core.runtime.Status;
56
import org.eclipse.core.runtime.SubMonitor;
53
import org.eclipse.core.runtime.SubProgressMonitor;
57
import org.eclipse.core.runtime.SubProgressMonitor;
54
import org.eclipse.core.runtime.content.IContentType;
58
import org.eclipse.core.runtime.content.IContentType;
55
import org.eclipse.jface.action.Action;
59
import org.eclipse.jface.action.Action;
60
import org.eclipse.jface.preference.IPreferenceStore;
56
import org.eclipse.jface.text.BadLocationException;
61
import org.eclipse.jface.text.BadLocationException;
57
import org.eclipse.jface.text.IDocument;
62
import org.eclipse.jface.text.IDocument;
58
import org.eclipse.jface.text.IRegion;
63
import org.eclipse.jface.text.IRegion;
Lines 81-92 import org.eclipse.ui.texteditor.ITextEditor; Link Here
81
86
82
import com.ibm.icu.text.MessageFormat;
87
import com.ibm.icu.text.MessageFormat;
83
88
89
import org.eclipse.cdt.core.CCProjectNature;
84
import org.eclipse.cdt.core.CCorePlugin;
90
import org.eclipse.cdt.core.CCorePlugin;
91
import org.eclipse.cdt.core.CProjectNature;
85
import org.eclipse.cdt.core.model.CModelException;
92
import org.eclipse.cdt.core.model.CModelException;
86
import org.eclipse.cdt.core.model.CoreModel;
93
import org.eclipse.cdt.core.model.CoreModel;
87
import org.eclipse.cdt.core.model.IBinary;
94
import org.eclipse.cdt.core.model.IBinary;
88
import org.eclipse.cdt.core.model.IBuffer;
95
import org.eclipse.cdt.core.model.IBuffer;
89
import org.eclipse.cdt.core.model.ICElement;
96
import org.eclipse.cdt.core.model.ICElement;
97
import org.eclipse.cdt.core.model.ICModel;
90
import org.eclipse.cdt.core.model.ICProject;
98
import org.eclipse.cdt.core.model.ICProject;
91
import org.eclipse.cdt.core.model.IIncludeReference;
99
import org.eclipse.cdt.core.model.IIncludeReference;
92
import org.eclipse.cdt.core.model.ISourceRange;
100
import org.eclipse.cdt.core.model.ISourceRange;
Lines 367-388 public class EditorUtility { Link Here
367
			// include paths
375
			// include paths
368
			try {
376
			try {
369
				ICProject[] projects = CCorePlugin.getDefault().getCoreModel().getCModel().getCProjects();
377
				ICProject[] projects = CCorePlugin.getDefault().getCoreModel().getCModel().getCProjects();
370
				outerFor: for (int i = 0; i < projects.length; i++) {
378
				if (projects.length == 1) {
371
					IIncludeReference[] includeReferences = projects[i].getIncludeReferences();
379
					// Special case 1 - all non-workspace files will use project configuration
372
					for (int j = 0; j < includeReferences.length; j++) {
380
					// from workspace project when there is only one such project
373
						// crecoskie test
381
					context = projects[0];
374
						// TODO FIXME
382
				} else if (projects.length == 2) {
375
						// include entries don't handle URIs yet, so fake it out for now
383
					// Special case 2 - when there's only a synthetic project and single user
376
						IPath path = URIUtil.toPath(locationURI);
384
					// project, use user project as a context.
377
						if(path == null)
385
					if (isSyntheticProject(projects[0])) {
378
							path = new Path(locationURI.getPath());
386
						context = projects[1];
379
						
387
					} else if (isSyntheticProject(projects[1])) {
380
						if (includeReferences[j].isOnIncludeEntry(path)) {
388
						context = projects[0];
381
							context = projects[i];
389
					} else {
382
							break outerFor;
390
						// Fallback to default multi-project scenario
391
					}
392
				}
393
				if (context == null) {
394
					outerFor: for (int i = 0; i < projects.length; i++) {
395
						IIncludeReference[] includeReferences = projects[i].getIncludeReferences();
396
						for (int j = 0; j < includeReferences.length; j++) {
397
							// crecoskie test
398
							// TODO FIXME
399
							// include entries don't handle URIs yet, so fake it out for now
400
							IPath path = URIUtil.toPath(locationURI);
401
							if(path == null)
402
								path = new Path(locationURI.getPath());
403
							
404
							if (includeReferences[j].isOnIncludeEntry(path)) {
405
								context = projects[i];
406
								break outerFor;
407
							}
383
						}
408
						}
384
					}
409
					}
385
				}
410
				}
411
				if (context == null) {
412
					context= createSyntheticProject();
413
				}
386
				if (context == null && projects.length > 0) {
414
				if (context == null && projects.length > 0) {
387
					// last resort: just take any of them
415
					// last resort: just take any of them
388
					context= projects[0];
416
					context= projects[0];
Lines 418-423 public class EditorUtility { Link Here
418
		return new ExternalEditorInput(locationURI);
446
		return new ExternalEditorInput(locationURI);
419
	}
447
	}
420
448
449
	private static synchronized ICElement createSyntheticProject() {
450
		try {
451
			// Potential race condition - several editors opening concurrently, hence synchronized
452
			// and this double-check
453
			ICModel model = CCorePlugin.getDefault().getCoreModel().getCModel();
454
			ICProject[] projects = model.getCProjects();
455
			for (ICProject project : projects) {
456
				if (isSyntheticProject(project)) {
457
					return project;
458
				}
459
			}
460
			final IPreferenceStore preferenceStore = CUIPlugin.getDefault().getPreferenceStore();
461
			if (!preferenceStore.getBoolean("noSyntheticProject")) { //$NON-NLS-1$
462
				final IWorkspace workspace = CUIPlugin.getWorkspace();
463
				workspace.run(new IWorkspaceRunnable() {
464
					public void run(IProgressMonitor monitor) throws CoreException {
465
						SubMonitor subMonitor = SubMonitor.convert(monitor,
466
								Messages.EditorUtility_creatingSyntheticProject_message, 300);
467
						final IProjectDescription projectDescription = workspace
468
								.newProjectDescription(getSyntheticProjectName());
469
						final IProject project = workspace.getRoot().getProject(projectDescription.getName());
470
						final int flags;
471
						if (!preferenceStore.getBoolean("visibleSyntheticProject")) { //$NON-NLS-1$
472
							flags = IResource.HIDDEN;
473
						} else {
474
							flags = 0;
475
						}
476
						project.create(projectDescription, flags, subMonitor.newChild(100));
477
						project.open(subMonitor.newChild(100));
478
						CProjectNature.addCNature(project, subMonitor.newChild(100));
479
						CCProjectNature.addCCNature(project, subMonitor.newChild(100));
480
						if (monitor != null) {
481
							monitor.done();
482
						}
483
					}
484
				}, null); // No progress monitor/cancellation - there will be a one-time slowdown
485
				return model.getCProject(getSyntheticProjectName());
486
			} else {
487
				return null;
488
			}
489
		} catch (CoreException e) {
490
			// Do nothing, log and bail out
491
			CUIPlugin.log(e);
492
			return null;
493
		}
494
	}
495
496
	private static boolean isSyntheticProject(ICProject icProject) {
497
		return icProject.getElementName().equals(getSyntheticProjectName());
498
	}
499
500
	private static String getSyntheticProjectName() {
501
		String name = CUIPlugin.getDefault().getPreferenceStore().getString("syntheticProjectName"); //$NON-NLS-1$
502
		return name != null && !"".equals(name.trim()) ? name : ".cdtexternalfilessupport"; //$NON-NLS-1$ //$NON-NLS-2$
503
	}
504
421
	public static IEditorInput getEditorInputForLocation(IPath location, ICElement context) {
505
	public static IEditorInput getEditorInputForLocation(IPath location, ICElement context) {
422
		IFile resource= getWorkspaceFileAtLocation(location, context);
506
		IFile resource= getWorkspaceFileAtLocation(location, context);
423
		if (resource != null) {
507
		if (resource != null) {
(-)a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/Messages.java (+1 lines)
Lines 19-24 public class Messages extends NLS { Link Here
19
	private static final String BUNDLE_NAME= Messages.class.getName();
19
	private static final String BUNDLE_NAME= Messages.class.getName();
20
20
21
	public static String EditorUtility_calculatingChangedRegions_message;
21
	public static String EditorUtility_calculatingChangedRegions_message;
22
	public static String EditorUtility_creatingSyntheticProject_message;
22
	public static String EditorUtility_error_calculatingChangedRegions;
23
	public static String EditorUtility_error_calculatingChangedRegions;
23
24
24
	public static String OpenExternalProblemAction_CannotReadExternalLocation;
25
	public static String OpenExternalProblemAction_CannotReadExternalLocation;
(-)a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/Messages.properties (+1 lines)
Lines 10-15 Link Here
10
###############################################################################
10
###############################################################################
11
11
12
EditorUtility_calculatingChangedRegions_message=Calculating changed regions
12
EditorUtility_calculatingChangedRegions_message=Calculating changed regions
13
EditorUtility_creatingSyntheticProject_message=Creating a synthetic project
13
EditorUtility_error_calculatingChangedRegions=An error occurred while calculating the changed regions. See error log for details.
14
EditorUtility_error_calculatingChangedRegions=An error occurred while calculating the changed regions. See error log for details.
14
OpenExternalProblemAction_CannotReadExternalLocation=Cannot read external location {0}
15
OpenExternalProblemAction_CannotReadExternalLocation=Cannot read external location {0}
15
OpenExternalProblemAction_ErrorOpeningFile=Error Opening File
16
OpenExternalProblemAction_ErrorOpeningFile=Error Opening File

Return to bug 371562