From f6622589f1040f98949772464b879a0e03698b15 Mon Sep 17 00:00:00 2001 From: Anton Leherbauer Date: Fri, 31 Oct 2008 13:07:17 +0000 Subject: [PATCH] Bug 252744 - Make ExternalEditorInput compatible to FileStoreEditorInput --- .../internal/ui/editor/CDocumentProvider.java | 20 +- .../editor/ExternalSearchAnnotationModel.java | 25 +-- .../ExternalSearchDocumentProvider.java | 53 ++--- .../editor/ITranslationUnitEditorInput.java | 7 +- .../internal/ui/editor/OpenIncludeAction.java | 20 +- .../internal/ui/search/PDOMSearchResult.java | 2 +- .../ui/text/doctools/EditorReopener.java | 2 +- .../cdt/internal/ui/util/EditorUtility.java | 20 +- .../internal/ui/util/ExternalEditorInput.java | 205 +++++++----------- .../ui/util/ExternalEditorInputFactory.java | 5 +- .../internal/ui/CDebugModelPresentation.java | 10 +- 11 files changed, 159 insertions(+), 210 deletions(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CDocumentProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CDocumentProvider.java index c2753c3b6a7..95f00119e63 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CDocumentProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CDocumentProvider.java @@ -21,7 +21,6 @@ import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResourceRuleFactory; -import org.eclipse.core.resources.IStorage; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdaptable; @@ -49,7 +48,6 @@ import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.text.edits.DeleteEdit; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IFileEditorInput; -import org.eclipse.ui.IStorageEditorInput; import org.eclipse.ui.editors.text.ForwardingDocumentProvider; import org.eclipse.ui.editors.text.ILocationProvider; import org.eclipse.ui.editors.text.ILocationProviderExtension; @@ -856,15 +854,17 @@ public class CDocumentProvider extends TextFileDocumentProvider { IBufferFactory factory = CUIPlugin.getDefault().getBufferFactory(); tuInfo.fCopy = original.getSharedWorkingCopy(getProgressMonitor(), factory, requestor); - if (tuInfo.fModel == null && element instanceof IStorageEditorInput) { - IStorage storage= ((IStorageEditorInput)element).getStorage(); - IResource markerResource= original.getCProject().getProject(); - tuInfo.fModel= new ExternalSearchAnnotationModel(markerResource, storage); - IAnnotationModel fileBufferAnnotationModel= tuInfo.fTextFileBuffer.getAnnotationModel(); - if (fileBufferAnnotationModel != null) { - ((AnnotationModel)tuInfo.fModel).addAnnotationModel("fileBufferModel", fileBufferAnnotationModel); //$NON-NLS-1$ + if (tuInfo.fModel == null) { + IPath location = original.getLocation(); + if (location != null) { + IResource markerResource= original.getCProject().getProject(); + tuInfo.fModel= new ExternalSearchAnnotationModel(markerResource, location); + IAnnotationModel fileBufferAnnotationModel= tuInfo.fTextFileBuffer.getAnnotationModel(); + if (fileBufferAnnotationModel != null) { + ((AnnotationModel)tuInfo.fModel).addAnnotationModel("fileBufferModel", fileBufferAnnotationModel); //$NON-NLS-1$ + } + tuInfo.fCachedReadOnlyState= true; } - tuInfo.fCachedReadOnlyState= true; } if (tuInfo.fModel instanceof TranslationUnitAnnotationModel) { TranslationUnitAnnotationModel model= (TranslationUnitAnnotationModel) tuInfo.fModel; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/ExternalSearchAnnotationModel.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/ExternalSearchAnnotationModel.java index 69f9c23bd2d..1a4b3ead9c2 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/ExternalSearchAnnotationModel.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/ExternalSearchAnnotationModel.java @@ -10,12 +10,10 @@ * Norbert Ploett (Siemens AG) * Anton Leherbauer (Wind River Systems) *******************************************************************************/ - package org.eclipse.cdt.internal.ui.editor; import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IStorage; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; @@ -25,37 +23,37 @@ import org.eclipse.cdt.core.model.ICModelMarker; public class ExternalSearchAnnotationModel extends ResourceMarkerAnnotationModel { - private final IStorage fStorage; + private final IPath fLocation; private final int fDepth; private final String fLocationAttribute; /** * @param markerResource - * @param storage + * @param location */ - public ExternalSearchAnnotationModel(IResource markerResource, IStorage storage) { - this(markerResource, storage, IResource.DEPTH_ZERO, ICModelMarker.C_MODEL_MARKER_EXTERNAL_LOCATION); + public ExternalSearchAnnotationModel(IResource markerResource, IPath location) { + this(markerResource, location, IResource.DEPTH_ZERO, ICModelMarker.C_MODEL_MARKER_EXTERNAL_LOCATION); } /** * @param markerResource - * @param storage + * @param location * @param depth */ - ExternalSearchAnnotationModel(IResource markerResource, IStorage storage, int depth) { - this(markerResource, storage, depth, ICModelMarker.C_MODEL_MARKER_EXTERNAL_LOCATION); + ExternalSearchAnnotationModel(IResource markerResource, IPath location, int depth) { + this(markerResource, location, depth, ICModelMarker.C_MODEL_MARKER_EXTERNAL_LOCATION); } /** * @param markerResource - * @param storage + * @param location * @param depth * @param locationAttribute */ ExternalSearchAnnotationModel(IResource markerResource, - IStorage storage, int depth, String locationAttribute) { + IPath location, int depth, String locationAttribute) { super(markerResource); - fStorage= storage; + fLocation= location; fDepth= depth; fLocationAttribute= locationAttribute; } @@ -76,8 +74,7 @@ public class ExternalSearchAnnotationModel extends ResourceMarkerAnnotationModel if (externalFileName != null) { // Only accept markers with external // paths set IPath externalPath = new Path(externalFileName); - IPath storagePath = fStorage.getFullPath(); - acceptable = externalPath.equals(storagePath); // Only accept + acceptable = externalPath.equals(fLocation); // Only accept // markers for this // annotation // model's external diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/ExternalSearchDocumentProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/ExternalSearchDocumentProvider.java index 6516a07dd02..17dab015c87 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/ExternalSearchDocumentProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/ExternalSearchDocumentProvider.java @@ -10,11 +10,11 @@ * Norbert Ploett (Siemens AG) * Anton Leherbauer (Wind River Systems) *******************************************************************************/ - package org.eclipse.cdt.internal.ui.editor; import java.net.URI; +import org.eclipse.core.filesystem.URIUtil; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IStorage; import org.eclipse.core.runtime.CoreException; @@ -28,8 +28,6 @@ import org.eclipse.ui.editors.text.ILocationProvider; import org.eclipse.ui.editors.text.ILocationProviderExtension; import org.eclipse.ui.editors.text.TextFileDocumentProvider; -import org.eclipse.cdt.core.resources.EFSFileStorage; -import org.eclipse.cdt.core.resources.FileStorage; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.internal.ui.util.ExternalEditorInput; @@ -67,29 +65,31 @@ public class ExternalSearchDocumentProvider extends TextFileDocumentProvider { if (element instanceof IStorageEditorInput) { IStorage storage= ((IStorageEditorInput)element).getStorage(); if (storage.getFullPath() != null) { - return createExternalSearchAnnotationModel(storage, null); + return createExternalSearchAnnotationModel(storage.getFullPath(), null); } } if (element instanceof IPathEditorInput) { - IPath path= ((IPathEditorInput)element).getPath(); - IStorage storage= new FileStorage(path); - return createExternalSearchAnnotationModel(storage, null); + IPath location = ((IPathEditorInput) element).getPath(); + if (location != null) { + return createExternalSearchAnnotationModel(location, null); + } } if (element instanceof IAdaptable) { IAdaptable adaptable= (IAdaptable) element; - - ILocationProviderExtension extendedProvider = (ILocationProviderExtension) adaptable.getAdapter(ILocationProviderExtension.class); - - if(extendedProvider != null) { - URI uri = extendedProvider.getURI(element); - IStorage storage = new EFSFileStorage(uri); - return createExternalSearchAnnotationModel(storage, null); - } ILocationProvider provider = (ILocationProvider) adaptable.getAdapter(ILocationProvider.class); if (provider != null) { - IPath path = provider.getPath(element); - IStorage storage = new FileStorage(path); - return createExternalSearchAnnotationModel(storage, null); + IPath location = provider.getPath(element); + if (location != null) { + return createExternalSearchAnnotationModel(location, null); + } + if (provider instanceof ILocationProviderExtension) { + ILocationProviderExtension extendedProvider = (ILocationProviderExtension) provider; + URI uri = extendedProvider.getURI(element); + location = URIUtil.toPath(uri); + if (location != null) { + return createExternalSearchAnnotationModel(location, null); + } + } } } return null; @@ -102,26 +102,29 @@ public class ExternalSearchDocumentProvider extends TextFileDocumentProvider { * @return a new annotation model for the external editor input */ private IAnnotationModel createExternalSearchAnnotationModel(ExternalEditorInput externalInput) { - IStorage storage = externalInput.getStorage(); - IResource markerResource = externalInput.getMarkerResource(); - return createExternalSearchAnnotationModel(storage, markerResource); + IPath location = externalInput.getPath(); + if (location != null) { + IResource markerResource = externalInput.getMarkerResource(); + return createExternalSearchAnnotationModel(location, markerResource); + } + return null; } /** * Create an annotation model for the given file and associated resource marker. * - * @param storage the file in the form of a IStorage + * @param location the local file system location * @param markerResource the resource to retrieve markers from, may be null * @return a new annotation model for the file */ - private IAnnotationModel createExternalSearchAnnotationModel(IStorage storage, IResource markerResource) { + private IAnnotationModel createExternalSearchAnnotationModel(IPath location, IResource markerResource) { AnnotationModel model= null; if (markerResource != null){ - model = new ExternalSearchAnnotationModel(markerResource, storage); + model = new ExternalSearchAnnotationModel(markerResource, location); } else { // no marker resource available - search workspace root and all project resources (depth one) markerResource= CUIPlugin.getWorkspace().getRoot(); - model = new ExternalSearchAnnotationModel(markerResource, storage, IResource.DEPTH_ONE); + model = new ExternalSearchAnnotationModel(markerResource, location, IResource.DEPTH_ONE); } return model; } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/ITranslationUnitEditorInput.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/ITranslationUnitEditorInput.java index 27dff9d4523..b1dcb2bdaaa 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/ITranslationUnitEditorInput.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/ITranslationUnitEditorInput.java @@ -8,19 +8,14 @@ * Contributors: * QNX Software Systems - Initial API and implementation *******************************************************************************/ - package org.eclipse.cdt.internal.ui.editor; -import org.eclipse.ui.IStorageEditorInput; -import org.eclipse.ui.editors.text.ILocationProvider; -import org.eclipse.ui.editors.text.ILocationProviderExtension; - import org.eclipse.cdt.core.model.ITranslationUnit; /** * ITranslationUnitEditorInput */ -public interface ITranslationUnitEditorInput extends IStorageEditorInput, ILocationProvider, ILocationProviderExtension { +public interface ITranslationUnitEditorInput { ITranslationUnit getTranslationUnit(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/OpenIncludeAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/OpenIncludeAction.java index 9854b8e5949..1a67c5df195 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/OpenIncludeAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/OpenIncludeAction.java @@ -227,7 +227,7 @@ public class OpenIncludeAction extends Action { } /** - * Recuse in the project. + * Recurse in the project. * @param parent * @param name * @param list @@ -239,15 +239,17 @@ public class OpenIncludeAction extends Action { public boolean visit(IResourceProxy proxy) throws CoreException { if (proxy.getType() == IResource.FILE && proxy.getName().equalsIgnoreCase(name.lastSegment())) { IPath rPath = proxy.requestResource().getLocation(); - int numSegToRemove = rPath.segmentCount() - name.segmentCount(); - IPath sPath = rPath.removeFirstSegments(numSegToRemove); - sPath = sPath.setDevice(name.getDevice()); - if (Platform.getOS().equals(Platform.OS_WIN32) ? - sPath.toOSString().equalsIgnoreCase(name.toOSString()) : - sPath.equals(name)) { - list.add(rPath); + if (rPath != null) { + int numSegToRemove = rPath.segmentCount() - name.segmentCount(); + IPath sPath = rPath.removeFirstSegments(numSegToRemove); + sPath = sPath.setDevice(name.getDevice()); + if (Platform.getOS().equals(Platform.OS_WIN32) ? + sPath.toOSString().equalsIgnoreCase(name.toOSString()) : + sPath.equals(name)) { + list.add(rPath); + } + return false; } - return false; } return true; } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchResult.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchResult.java index ab2eb519ea5..03f5d4f90d8 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchResult.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchResult.java @@ -74,7 +74,7 @@ public class PDOMSearchResult extends AbstractTextSearchResult implements IEdito path= fileInput.getFile().getLocation(); } else if (input instanceof ExternalEditorInput) { final ExternalEditorInput extInput = (ExternalEditorInput)input; - path= extInput.getStorage().getFullPath(); + path= extInput.getPath(); } else if (input instanceof IStorageEditorInput) { try { final IStorage storage= ((IStorageEditorInput)input).getStorage(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/doctools/EditorReopener.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/doctools/EditorReopener.java index 8f85c9afb48..a1466ffb0c2 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/doctools/EditorReopener.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/doctools/EditorReopener.java @@ -160,7 +160,7 @@ public class EditorReopener implements IDocCommentOwnershipListener { } else if(oldInput instanceof ExternalEditorInput) { ExternalEditorInput eei= (ExternalEditorInput) oldInput; ICElement element= CoreModel.getDefault().create(eei.getMarkerResource()); - newPart= EditorUtility.openInEditor(eei.getPath(null), element); + newPart= EditorUtility.openInEditor(eei.getPath(), element); } if(oldPart == oldActive) newActive= newPart; 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 fa5d788be74..beb19107d98 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 @@ -65,7 +65,6 @@ import org.eclipse.cdt.core.model.ISourceRange; import org.eclipse.cdt.core.model.ISourceReference; import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.IWorkingCopy; -import org.eclipse.cdt.core.resources.EFSFileStorage; import org.eclipse.cdt.core.resources.FileStorage; import org.eclipse.cdt.ui.CUIPlugin; @@ -253,7 +252,7 @@ public class EditorUtility { if (resource instanceof IFile) { return new FileEditorInput((IFile) resource); } - return new ExternalEditorInput(unit, new EFSFileStorage(unit.getLocationURI())); + return new ExternalEditorInput(unit); } if (element instanceof IBinary) { @@ -277,7 +276,10 @@ public class EditorUtility { return new FileEditorInput((IFile) input); } if (input instanceof IStorage) { - return new ExternalEditorInput((IStorage)input); + final IPath location= ((IStorage)input).getFullPath(); + if (location != null) { + return new ExternalEditorInput(location); + } } return null; } @@ -361,15 +363,15 @@ public class EditorUtility { } if(fileStore != null) - return new ExternalEditorInput(unit, new EFSFileStorage(locationURI)); + return new ExternalEditorInput(unit); } // no translation unit - still try to get a sensible marker resource // from the associated element IResource markerResource= cproject.getProject(); - return new ExternalEditorInput(new EFSFileStorage(locationURI), markerResource); + return new ExternalEditorInput(locationURI, markerResource); } } - return new ExternalEditorInput(new EFSFileStorage(locationURI)); + return new ExternalEditorInput(locationURI); } @@ -407,15 +409,15 @@ public class EditorUtility { if (cproject != null) { ITranslationUnit unit = CoreModel.getDefault().createTranslationUnitFrom(cproject, location); if (unit != null) { - return new ExternalEditorInput(unit, new FileStorage(location)); + return new ExternalEditorInput(unit); } // no translation unit - still try to get a sensible marker resource // from the associated element IResource markerResource= cproject.getProject(); - return new ExternalEditorInput(new FileStorage(location), markerResource); + return new ExternalEditorInput(location, markerResource); } } - return new ExternalEditorInput(new FileStorage(location)); + return new ExternalEditorInput(location); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/ExternalEditorInput.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/ExternalEditorInput.java index 8483537db3f..7a2564a4c13 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/ExternalEditorInput.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/ExternalEditorInput.java @@ -14,22 +14,18 @@ package org.eclipse.cdt.internal.ui.util; import java.net.URI; +import org.eclipse.core.filesystem.EFS; +import org.eclipse.core.filesystem.IFileStore; import org.eclipse.core.filesystem.URIUtil; import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IStorage; +import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Platform; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.ui.IEditorRegistry; import org.eclipse.ui.IMemento; -import org.eclipse.ui.IPersistableElement; -import org.eclipse.ui.IStorageEditorInput; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.editors.text.ILocationProvider; +import org.eclipse.ui.ide.FileStoreEditorInput; import org.eclipse.cdt.core.model.ITranslationUnit; -import org.eclipse.cdt.core.resources.EFSFileStorage; +import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.internal.ui.editor.ITranslationUnitEditorInput; @@ -37,129 +33,79 @@ import org.eclipse.cdt.internal.ui.editor.ITranslationUnitEditorInput; /** * An EditorInput for an external (non-workspace) file. */ -public class ExternalEditorInput implements ITranslationUnitEditorInput, IPersistableElement { +public final class ExternalEditorInput extends FileStoreEditorInput implements ITranslationUnitEditorInput { - private IStorage externalFile; - private IResource markerResource; + private final IPath location; + private final IResource markerResource; private ITranslationUnit unit; - private IPath location; - /* - */ - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (!(obj instanceof IStorageEditorInput)) - return false; - IStorageEditorInput other = (IStorageEditorInput)obj; - // externalFile storage type may not be the same so compare the paths + /** + * Create an editor input for an external translation unit. + * + * @param unit the translation unit + */ + public ExternalEditorInput(ITranslationUnit unit) { + this(unit.getLocationURI(), unit.getCProject().getProject()); + Assert.isNotNull(unit); + this.unit = unit; + } + + /** + * Create an editor input for an external file of the local file system. + * + * @param location the file system location + */ + public ExternalEditorInput(IPath location) { + this(URIUtil.toURI(location), null); + } + + /** + * Create an editor input for an external file of the local file system. + * + * @param location the file system location + * @param markerResource the associated marker resource, may be null + */ + public ExternalEditorInput(IPath location, IResource markerResource) { + this(URIUtil.toURI(location), markerResource); + } + + /** + * Create an editor input for a location URI. + * + * @param locationURI the location URI + */ + public ExternalEditorInput(URI locationURI) { + this(locationURI, null); + } + + /** + * Create an editor input for a location URI. + * + * @param locationURI the location URI + * @param markerResource the associated marker resource, may be null + */ + public ExternalEditorInput(URI locationURI, IResource markerResource) { + super(getFileStore(locationURI)); + this.location = URIUtil.toPath(locationURI); + this.markerResource = markerResource; + } + + private static IFileStore getFileStore(URI locationURI) { try { - return externalFile.getFullPath().equals(other.getStorage().getFullPath()); + return EFS.getStore(locationURI); } catch (CoreException exc) { - return false; - } - } - - /* - * @see IEditorInput#exists() - */ - public boolean exists() { - // External file can not be deleted - return true; - } - - /* - * @see IAdaptable#getAdapter(Class) - */ - @SuppressWarnings("unchecked") - public Object getAdapter(Class adapter) { - if (ILocationProvider.class.equals(adapter)) { - return this; - } - return Platform.getAdapterManager().getAdapter(this, adapter); - } - - /* - * @see IEditorInput#getImageDescriptor() - */ - public ImageDescriptor getImageDescriptor() { - IEditorRegistry registry= PlatformUI.getWorkbench().getEditorRegistry(); - return registry.getImageDescriptor(externalFile.getFullPath().getFileExtension()); - } - - /* - * @see IEditorInput#getName() - */ - public String getName() { - return externalFile.getName(); - } - - /* - * @see IEditorInput#getPersistable() - */ - public IPersistableElement getPersistable() { - if (location != null) { - return this; + CUIPlugin.log(exc); } return null; } /* - * see IStorageEditorInput#getStorage() - */ - public IStorage getStorage() { - return externalFile; - } - - /* - * @see IEditorInput#getToolTipText() - */ - public String getToolTipText() { - IPath path = externalFile.getFullPath(); - if(path != null) - return path.toString(); - return unit.getLocationURI().toString(); - } - - /* (non-Javadoc) * @see org.eclipse.cdt.internal.ui.editor.ITranslationUnitEditorInput#getTranslationUnit() */ public ITranslationUnit getTranslationUnit() { return unit; } - /* (non-Javadoc) - * @see org.eclipse.ui.editors.text.ILocationProvider#getPath(java.lang.Object) - */ - public IPath getPath(Object element) { - return location; - } - - public ExternalEditorInput(ITranslationUnit unit, IStorage exFile) { - this(exFile, exFile.getFullPath()); - this.unit = unit; - markerResource= unit.getCProject().getProject(); - } - - public ExternalEditorInput(IStorage exFile) { - this(exFile, exFile.getFullPath()); - } - - public ExternalEditorInput(IStorage exFile, IPath location) { - externalFile = exFile; - this.location = location; - } - - /** - * This constructor accepts the storage for the editor - * and a reference to a resource which holds the markers for the external file. - */ - public ExternalEditorInput(IStorage exFile, IResource markerResource) { - this(exFile, exFile.getFullPath()); - this.markerResource = markerResource ; - } - /** * Return the resource where markers for this external editor input are stored */ @@ -170,29 +116,32 @@ public class ExternalEditorInput implements ITranslationUnitEditorInput, IPersis /* * @see org.eclipse.ui.IPersistableElement#getFactoryId() */ + @Override public String getFactoryId() { - return ExternalEditorInputFactory.ID; + if (getPath() != null) { + return ExternalEditorInputFactory.ID; + } + return super.getFactoryId(); } /* * @see org.eclipse.ui.IPersistable#saveState(org.eclipse.ui.IMemento) */ + @Override public void saveState(IMemento memento) { - ExternalEditorInputFactory.saveState(memento, this); + if (getPath() != null) { + ExternalEditorInputFactory.saveState(memento, this); + } else { + super.saveState(memento); + } } /* - * @see org.eclipse.ui.editors.text.ILocationProviderExtension#getURI(java.lang.Object) + * @see org.eclipse.ui.IPathEditorInput#getPath() + * Note: ExternalEditorInput must not implement IPathEditorInput! */ - public URI getURI(Object element) { - if (externalFile instanceof EFSFileStorage) { - return ((EFSFileStorage) externalFile).getLocationURI(); - } - IPath location = getPath(element); - if (location != null) { - return URIUtil.toURI(location); - } - return null; + public IPath getPath() { + return location; } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/ExternalEditorInputFactory.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/ExternalEditorInputFactory.java index ebcc7fa86f4..ba51f5bde74 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/ExternalEditorInputFactory.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/ExternalEditorInputFactory.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2008 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,7 +8,6 @@ * Contributors: * Anton Leherbauer (Wind River Systems) - initial API and implementation *******************************************************************************/ - package org.eclipse.cdt.internal.ui.util; import org.eclipse.core.resources.IProject; @@ -72,7 +71,7 @@ public class ExternalEditorInputFactory implements IElementFactory { * @param input the element */ static void saveState(IMemento memento, ExternalEditorInput input) { - IPath location= input.getPath(input); + IPath location= input.getPath(); if (location != null) { memento.putString(TAG_PATH, location.toOSString()); } diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDebugModelPresentation.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDebugModelPresentation.java index 3ebe38c6c66..8c5a4241dbe 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDebugModelPresentation.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDebugModelPresentation.java @@ -180,7 +180,7 @@ public class CDebugModelPresentation extends LabelProvider implements IDebugMode ICProject cproject = CoreModel.getDefault().create(project); String id = CoreModel.getRegistedContentTypeId(project, path.lastSegment()); ExternalTranslationUnit tu = new ExternalTranslationUnit(cproject, URIUtil.toURI(path), id); - return new ExternalEditorInput( tu, new LocalFileStorage( fsfile ) ); + return new ExternalEditorInput( tu ); } } } @@ -194,15 +194,15 @@ public class CDebugModelPresentation extends LabelProvider implements IDebugMode return new FileEditorInput( file ); } if ( element instanceof FileStorage || element instanceof LocalFileStorage ) { - return new ExternalEditorInput( (IStorage)element ); + return new ExternalEditorInput( ((IStorage) element).getFullPath() ); } if ( element instanceof ExternalTranslationUnit ) { ExternalTranslationUnit etu = (ExternalTranslationUnit) element; - return new ExternalEditorInput( etu , new LocalFileStorage( etu.getLocation().toFile() ) ); + return new ExternalEditorInput( etu ); } if (element instanceof CSourceNotFoundElement) { - return new CSourceNotFoundEditorInput((CSourceNotFoundElement) element); + return new CSourceNotFoundEditorInput(element); } return null; } @@ -222,6 +222,7 @@ public class CDebugModelPresentation extends LabelProvider implements IDebugMode return id; } + @Override public Image getImage( Object element ) { Image baseImage = getBaseImage( element ); if ( baseImage != null ) { @@ -367,6 +368,7 @@ public class CDebugModelPresentation extends LabelProvider implements IDebugMode return getImageCache().getImageFor( new OverlayImageDescriptor( fDebugImageRegistry.get( descriptor ), computeBreakpointOverlays( watchpoint ) ) ); } + @Override public String getText( Object element ) { String bt = getBaseText( element ); if ( bt == null )