1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-04 06:45:43 +02:00

Bug 252744 - Make ExternalEditorInput compatible to FileStoreEditorInput

This commit is contained in:
Anton Leherbauer 2008-10-31 13:07:17 +00:00
parent e1e813365b
commit f6622589f1
11 changed files with 159 additions and 210 deletions

View file

@ -21,7 +21,6 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceRuleFactory; import org.eclipse.core.resources.IResourceRuleFactory;
import org.eclipse.core.resources.IStorage;
import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable; 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.text.edits.DeleteEdit;
import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IFileEditorInput; import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.IStorageEditorInput;
import org.eclipse.ui.editors.text.ForwardingDocumentProvider; import org.eclipse.ui.editors.text.ForwardingDocumentProvider;
import org.eclipse.ui.editors.text.ILocationProvider; import org.eclipse.ui.editors.text.ILocationProvider;
import org.eclipse.ui.editors.text.ILocationProviderExtension; import org.eclipse.ui.editors.text.ILocationProviderExtension;
@ -856,15 +854,17 @@ public class CDocumentProvider extends TextFileDocumentProvider {
IBufferFactory factory = CUIPlugin.getDefault().getBufferFactory(); IBufferFactory factory = CUIPlugin.getDefault().getBufferFactory();
tuInfo.fCopy = original.getSharedWorkingCopy(getProgressMonitor(), factory, requestor); tuInfo.fCopy = original.getSharedWorkingCopy(getProgressMonitor(), factory, requestor);
if (tuInfo.fModel == null && element instanceof IStorageEditorInput) { if (tuInfo.fModel == null) {
IStorage storage= ((IStorageEditorInput)element).getStorage(); IPath location = original.getLocation();
IResource markerResource= original.getCProject().getProject(); if (location != null) {
tuInfo.fModel= new ExternalSearchAnnotationModel(markerResource, storage); IResource markerResource= original.getCProject().getProject();
IAnnotationModel fileBufferAnnotationModel= tuInfo.fTextFileBuffer.getAnnotationModel(); tuInfo.fModel= new ExternalSearchAnnotationModel(markerResource, location);
if (fileBufferAnnotationModel != null) { IAnnotationModel fileBufferAnnotationModel= tuInfo.fTextFileBuffer.getAnnotationModel();
((AnnotationModel)tuInfo.fModel).addAnnotationModel("fileBufferModel", fileBufferAnnotationModel); //$NON-NLS-1$ if (fileBufferAnnotationModel != null) {
((AnnotationModel)tuInfo.fModel).addAnnotationModel("fileBufferModel", fileBufferAnnotationModel); //$NON-NLS-1$
}
tuInfo.fCachedReadOnlyState= true;
} }
tuInfo.fCachedReadOnlyState= true;
} }
if (tuInfo.fModel instanceof TranslationUnitAnnotationModel) { if (tuInfo.fModel instanceof TranslationUnitAnnotationModel) {
TranslationUnitAnnotationModel model= (TranslationUnitAnnotationModel) tuInfo.fModel; TranslationUnitAnnotationModel model= (TranslationUnitAnnotationModel) tuInfo.fModel;

View file

@ -10,12 +10,10 @@
* Norbert Ploett (Siemens AG) * Norbert Ploett (Siemens AG)
* Anton Leherbauer (Wind River Systems) * Anton Leherbauer (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.editor; package org.eclipse.cdt.internal.ui.editor;
import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IStorage;
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;
@ -25,37 +23,37 @@ import org.eclipse.cdt.core.model.ICModelMarker;
public class ExternalSearchAnnotationModel extends ResourceMarkerAnnotationModel { public class ExternalSearchAnnotationModel extends ResourceMarkerAnnotationModel {
private final IStorage fStorage; private final IPath fLocation;
private final int fDepth; private final int fDepth;
private final String fLocationAttribute; private final String fLocationAttribute;
/** /**
* @param markerResource * @param markerResource
* @param storage * @param location
*/ */
public ExternalSearchAnnotationModel(IResource markerResource, IStorage storage) { public ExternalSearchAnnotationModel(IResource markerResource, IPath location) {
this(markerResource, storage, IResource.DEPTH_ZERO, ICModelMarker.C_MODEL_MARKER_EXTERNAL_LOCATION); this(markerResource, location, IResource.DEPTH_ZERO, ICModelMarker.C_MODEL_MARKER_EXTERNAL_LOCATION);
} }
/** /**
* @param markerResource * @param markerResource
* @param storage * @param location
* @param depth * @param depth
*/ */
ExternalSearchAnnotationModel(IResource markerResource, IStorage storage, int depth) { ExternalSearchAnnotationModel(IResource markerResource, IPath location, int depth) {
this(markerResource, storage, depth, ICModelMarker.C_MODEL_MARKER_EXTERNAL_LOCATION); this(markerResource, location, depth, ICModelMarker.C_MODEL_MARKER_EXTERNAL_LOCATION);
} }
/** /**
* @param markerResource * @param markerResource
* @param storage * @param location
* @param depth * @param depth
* @param locationAttribute * @param locationAttribute
*/ */
ExternalSearchAnnotationModel(IResource markerResource, ExternalSearchAnnotationModel(IResource markerResource,
IStorage storage, int depth, String locationAttribute) { IPath location, int depth, String locationAttribute) {
super(markerResource); super(markerResource);
fStorage= storage; fLocation= location;
fDepth= depth; fDepth= depth;
fLocationAttribute= locationAttribute; fLocationAttribute= locationAttribute;
} }
@ -76,8 +74,7 @@ public class ExternalSearchAnnotationModel extends ResourceMarkerAnnotationModel
if (externalFileName != null) { // Only accept markers with external if (externalFileName != null) { // Only accept markers with external
// paths set // paths set
IPath externalPath = new Path(externalFileName); IPath externalPath = new Path(externalFileName);
IPath storagePath = fStorage.getFullPath(); acceptable = externalPath.equals(fLocation); // Only accept
acceptable = externalPath.equals(storagePath); // Only accept
// markers for this // markers for this
// annotation // annotation
// model's external // model's external

View file

@ -10,11 +10,11 @@
* Norbert Ploett (Siemens AG) * Norbert Ploett (Siemens AG)
* Anton Leherbauer (Wind River Systems) * Anton Leherbauer (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.editor; package org.eclipse.cdt.internal.ui.editor;
import java.net.URI; import java.net.URI;
import org.eclipse.core.filesystem.URIUtil;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IStorage; import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.CoreException; 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.ILocationProviderExtension;
import org.eclipse.ui.editors.text.TextFileDocumentProvider; 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.ui.CUIPlugin;
import org.eclipse.cdt.internal.ui.util.ExternalEditorInput; import org.eclipse.cdt.internal.ui.util.ExternalEditorInput;
@ -67,29 +65,31 @@ public class ExternalSearchDocumentProvider extends TextFileDocumentProvider {
if (element instanceof IStorageEditorInput) { if (element instanceof IStorageEditorInput) {
IStorage storage= ((IStorageEditorInput)element).getStorage(); IStorage storage= ((IStorageEditorInput)element).getStorage();
if (storage.getFullPath() != null) { if (storage.getFullPath() != null) {
return createExternalSearchAnnotationModel(storage, null); return createExternalSearchAnnotationModel(storage.getFullPath(), null);
} }
} }
if (element instanceof IPathEditorInput) { if (element instanceof IPathEditorInput) {
IPath path= ((IPathEditorInput)element).getPath(); IPath location = ((IPathEditorInput) element).getPath();
IStorage storage= new FileStorage(path); if (location != null) {
return createExternalSearchAnnotationModel(storage, null); return createExternalSearchAnnotationModel(location, null);
}
} }
if (element instanceof IAdaptable) { if (element instanceof IAdaptable) {
IAdaptable adaptable= (IAdaptable) element; 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); ILocationProvider provider = (ILocationProvider) adaptable.getAdapter(ILocationProvider.class);
if (provider != null) { if (provider != null) {
IPath path = provider.getPath(element); IPath location = provider.getPath(element);
IStorage storage = new FileStorage(path); if (location != null) {
return createExternalSearchAnnotationModel(storage, 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; return null;
@ -102,26 +102,29 @@ public class ExternalSearchDocumentProvider extends TextFileDocumentProvider {
* @return a new annotation model for the external editor input * @return a new annotation model for the external editor input
*/ */
private IAnnotationModel createExternalSearchAnnotationModel(ExternalEditorInput externalInput) { private IAnnotationModel createExternalSearchAnnotationModel(ExternalEditorInput externalInput) {
IStorage storage = externalInput.getStorage(); IPath location = externalInput.getPath();
IResource markerResource = externalInput.getMarkerResource(); if (location != null) {
return createExternalSearchAnnotationModel(storage, markerResource); IResource markerResource = externalInput.getMarkerResource();
return createExternalSearchAnnotationModel(location, markerResource);
}
return null;
} }
/** /**
* Create an annotation model for the given file and associated resource marker. * Create an annotation model for the given file and associated resource marker.
* *
* @param storage the file in the form of a <code>IStorage</code> * @param location the local file system location
* @param markerResource the resource to retrieve markers from, may be <code>null</code> * @param markerResource the resource to retrieve markers from, may be <code>null</code>
* @return a new annotation model for the file * @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; AnnotationModel model= null;
if (markerResource != null){ if (markerResource != null){
model = new ExternalSearchAnnotationModel(markerResource, storage); model = new ExternalSearchAnnotationModel(markerResource, location);
} else { } else {
// no marker resource available - search workspace root and all project resources (depth one) // no marker resource available - search workspace root and all project resources (depth one)
markerResource= CUIPlugin.getWorkspace().getRoot(); markerResource= CUIPlugin.getWorkspace().getRoot();
model = new ExternalSearchAnnotationModel(markerResource, storage, IResource.DEPTH_ONE); model = new ExternalSearchAnnotationModel(markerResource, location, IResource.DEPTH_ONE);
} }
return model; return model;
} }

View file

@ -8,19 +8,14 @@
* Contributors: * Contributors:
* QNX Software Systems - Initial API and implementation * QNX Software Systems - Initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.editor; 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; import org.eclipse.cdt.core.model.ITranslationUnit;
/** /**
* ITranslationUnitEditorInput * ITranslationUnitEditorInput
*/ */
public interface ITranslationUnitEditorInput extends IStorageEditorInput, ILocationProvider, ILocationProviderExtension { public interface ITranslationUnitEditorInput {
ITranslationUnit getTranslationUnit(); ITranslationUnit getTranslationUnit();

View file

@ -227,7 +227,7 @@ public class OpenIncludeAction extends Action {
} }
/** /**
* Recuse in the project. * Recurse in the project.
* @param parent * @param parent
* @param name * @param name
* @param list * @param list
@ -239,15 +239,17 @@ public class OpenIncludeAction extends Action {
public boolean visit(IResourceProxy proxy) throws CoreException { public boolean visit(IResourceProxy proxy) throws CoreException {
if (proxy.getType() == IResource.FILE && proxy.getName().equalsIgnoreCase(name.lastSegment())) { if (proxy.getType() == IResource.FILE && proxy.getName().equalsIgnoreCase(name.lastSegment())) {
IPath rPath = proxy.requestResource().getLocation(); IPath rPath = proxy.requestResource().getLocation();
int numSegToRemove = rPath.segmentCount() - name.segmentCount(); if (rPath != null) {
IPath sPath = rPath.removeFirstSegments(numSegToRemove); int numSegToRemove = rPath.segmentCount() - name.segmentCount();
sPath = sPath.setDevice(name.getDevice()); IPath sPath = rPath.removeFirstSegments(numSegToRemove);
if (Platform.getOS().equals(Platform.OS_WIN32) ? sPath = sPath.setDevice(name.getDevice());
sPath.toOSString().equalsIgnoreCase(name.toOSString()) : if (Platform.getOS().equals(Platform.OS_WIN32) ?
sPath.equals(name)) { sPath.toOSString().equalsIgnoreCase(name.toOSString()) :
list.add(rPath); sPath.equals(name)) {
list.add(rPath);
}
return false;
} }
return false;
} }
return true; return true;
} }

View file

@ -74,7 +74,7 @@ public class PDOMSearchResult extends AbstractTextSearchResult implements IEdito
path= fileInput.getFile().getLocation(); path= fileInput.getFile().getLocation();
} else if (input instanceof ExternalEditorInput) { } else if (input instanceof ExternalEditorInput) {
final ExternalEditorInput extInput = (ExternalEditorInput)input; final ExternalEditorInput extInput = (ExternalEditorInput)input;
path= extInput.getStorage().getFullPath(); path= extInput.getPath();
} else if (input instanceof IStorageEditorInput) { } else if (input instanceof IStorageEditorInput) {
try { try {
final IStorage storage= ((IStorageEditorInput)input).getStorage(); final IStorage storage= ((IStorageEditorInput)input).getStorage();

View file

@ -160,7 +160,7 @@ public class EditorReopener implements IDocCommentOwnershipListener {
} else if(oldInput instanceof ExternalEditorInput) { } else if(oldInput instanceof ExternalEditorInput) {
ExternalEditorInput eei= (ExternalEditorInput) oldInput; ExternalEditorInput eei= (ExternalEditorInput) oldInput;
ICElement element= CoreModel.getDefault().create(eei.getMarkerResource()); ICElement element= CoreModel.getDefault().create(eei.getMarkerResource());
newPart= EditorUtility.openInEditor(eei.getPath(null), element); newPart= EditorUtility.openInEditor(eei.getPath(), element);
} }
if(oldPart == oldActive) if(oldPart == oldActive)
newActive= newPart; newActive= newPart;

View file

@ -65,7 +65,6 @@ import org.eclipse.cdt.core.model.ISourceRange;
import org.eclipse.cdt.core.model.ISourceReference; import org.eclipse.cdt.core.model.ISourceReference;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.IWorkingCopy; 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.core.resources.FileStorage;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
@ -253,7 +252,7 @@ public class EditorUtility {
if (resource instanceof IFile) { if (resource instanceof IFile) {
return new FileEditorInput((IFile) resource); return new FileEditorInput((IFile) resource);
} }
return new ExternalEditorInput(unit, new EFSFileStorage(unit.getLocationURI())); return new ExternalEditorInput(unit);
} }
if (element instanceof IBinary) { if (element instanceof IBinary) {
@ -277,7 +276,10 @@ public class EditorUtility {
return new FileEditorInput((IFile) input); return new FileEditorInput((IFile) input);
} }
if (input instanceof IStorage) { if (input instanceof IStorage) {
return new ExternalEditorInput((IStorage)input); final IPath location= ((IStorage)input).getFullPath();
if (location != null) {
return new ExternalEditorInput(location);
}
} }
return null; return null;
} }
@ -361,15 +363,15 @@ public class EditorUtility {
} }
if(fileStore != null) 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 // no translation unit - still try to get a sensible marker resource
// from the associated element // from the associated element
IResource markerResource= cproject.getProject(); 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) { if (cproject != null) {
ITranslationUnit unit = CoreModel.getDefault().createTranslationUnitFrom(cproject, location); ITranslationUnit unit = CoreModel.getDefault().createTranslationUnitFrom(cproject, location);
if (unit != null) { 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 // no translation unit - still try to get a sensible marker resource
// from the associated element // from the associated element
IResource markerResource= cproject.getProject(); 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);
} }

View file

@ -14,22 +14,18 @@ package org.eclipse.cdt.internal.ui.util;
import java.net.URI; 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.filesystem.URIUtil;
import org.eclipse.core.resources.IResource; 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.CoreException;
import org.eclipse.core.runtime.IPath; 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.IMemento;
import org.eclipse.ui.IPersistableElement; import org.eclipse.ui.ide.FileStoreEditorInput;
import org.eclipse.ui.IStorageEditorInput;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.editors.text.ILocationProvider;
import org.eclipse.cdt.core.model.ITranslationUnit; 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; 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. * 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 final IPath location;
private IResource markerResource; private final IResource markerResource;
private ITranslationUnit unit; private ITranslationUnit unit;
private IPath location;
/* /**
*/ * Create an editor input for an external translation unit.
@Override *
public boolean equals(Object obj) { * @param unit the translation unit
if (this == obj) */
return true; public ExternalEditorInput(ITranslationUnit unit) {
if (!(obj instanceof IStorageEditorInput)) this(unit.getLocationURI(), unit.getCProject().getProject());
return false; Assert.isNotNull(unit);
IStorageEditorInput other = (IStorageEditorInput)obj; this.unit = unit;
// externalFile storage type may not be the same so compare the paths }
/**
* 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 <code>null</code>
*/
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 <code>null</code>
*/
public ExternalEditorInput(URI locationURI, IResource markerResource) {
super(getFileStore(locationURI));
this.location = URIUtil.toPath(locationURI);
this.markerResource = markerResource;
}
private static IFileStore getFileStore(URI locationURI) {
try { try {
return externalFile.getFullPath().equals(other.getStorage().getFullPath()); return EFS.getStore(locationURI);
} catch (CoreException exc) { } catch (CoreException exc) {
return false; CUIPlugin.log(exc);
}
}
/*
* @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;
} }
return null; 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() * @see org.eclipse.cdt.internal.ui.editor.ITranslationUnitEditorInput#getTranslationUnit()
*/ */
public ITranslationUnit getTranslationUnit() { public ITranslationUnit getTranslationUnit() {
return unit; 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 * 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() * @see org.eclipse.ui.IPersistableElement#getFactoryId()
*/ */
@Override
public String getFactoryId() { 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) * @see org.eclipse.ui.IPersistable#saveState(org.eclipse.ui.IMemento)
*/ */
@Override
public void saveState(IMemento memento) { 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) { public IPath getPath() {
if (externalFile instanceof EFSFileStorage) { return location;
return ((EFSFileStorage) externalFile).getLocationURI();
}
IPath location = getPath(element);
if (location != null) {
return URIUtil.toURI(location);
}
return null;
} }
} }

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -8,7 +8,6 @@
* Contributors: * Contributors:
* Anton Leherbauer (Wind River Systems) - initial API and implementation * Anton Leherbauer (Wind River Systems) - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.util; package org.eclipse.cdt.internal.ui.util;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
@ -72,7 +71,7 @@ public class ExternalEditorInputFactory implements IElementFactory {
* @param input the element * @param input the element
*/ */
static void saveState(IMemento memento, ExternalEditorInput input) { static void saveState(IMemento memento, ExternalEditorInput input) {
IPath location= input.getPath(input); IPath location= input.getPath();
if (location != null) { if (location != null) {
memento.putString(TAG_PATH, location.toOSString()); memento.putString(TAG_PATH, location.toOSString());
} }

View file

@ -180,7 +180,7 @@ public class CDebugModelPresentation extends LabelProvider implements IDebugMode
ICProject cproject = CoreModel.getDefault().create(project); ICProject cproject = CoreModel.getDefault().create(project);
String id = CoreModel.getRegistedContentTypeId(project, path.lastSegment()); String id = CoreModel.getRegistedContentTypeId(project, path.lastSegment());
ExternalTranslationUnit tu = new ExternalTranslationUnit(cproject, URIUtil.toURI(path), id); 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 ); return new FileEditorInput( file );
} }
if ( element instanceof FileStorage || element instanceof LocalFileStorage ) { if ( element instanceof FileStorage || element instanceof LocalFileStorage ) {
return new ExternalEditorInput( (IStorage)element ); return new ExternalEditorInput( ((IStorage) element).getFullPath() );
} }
if ( element instanceof ExternalTranslationUnit ) { if ( element instanceof ExternalTranslationUnit ) {
ExternalTranslationUnit etu = (ExternalTranslationUnit) element; ExternalTranslationUnit etu = (ExternalTranslationUnit) element;
return new ExternalEditorInput( etu , new LocalFileStorage( etu.getLocation().toFile() ) ); return new ExternalEditorInput( etu );
} }
if (element instanceof CSourceNotFoundElement) if (element instanceof CSourceNotFoundElement)
{ {
return new CSourceNotFoundEditorInput((CSourceNotFoundElement) element); return new CSourceNotFoundEditorInput(element);
} }
return null; return null;
} }
@ -222,6 +222,7 @@ public class CDebugModelPresentation extends LabelProvider implements IDebugMode
return id; return id;
} }
@Override
public Image getImage( Object element ) { public Image getImage( Object element ) {
Image baseImage = getBaseImage( element ); Image baseImage = getBaseImage( element );
if ( baseImage != null ) { if ( baseImage != null ) {
@ -367,6 +368,7 @@ public class CDebugModelPresentation extends LabelProvider implements IDebugMode
return getImageCache().getImageFor( new OverlayImageDescriptor( fDebugImageRegistry.get( descriptor ), computeBreakpointOverlays( watchpoint ) ) ); return getImageCache().getImageFor( new OverlayImageDescriptor( fDebugImageRegistry.get( descriptor ), computeBreakpointOverlays( watchpoint ) ) );
} }
@Override
public String getText( Object element ) { public String getText( Object element ) {
String bt = getBaseText( element ); String bt = getBaseText( element );
if ( bt == null ) if ( bt == null )