diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml
index e1f9b444662..d3ef418cf17 100644
--- a/core/org.eclipse.cdt.ui/plugin.xml
+++ b/core/org.eclipse.cdt.ui/plugin.xml
@@ -60,6 +60,9 @@
+
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 2dc431c4bcb..208c2c87cf0 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
@@ -12,26 +12,28 @@
package org.eclipse.cdt.internal.ui.util;
-import org.eclipse.jface.resource.ImageDescriptor;
-
-import org.eclipse.cdt.core.model.ITranslationUnit;
-import org.eclipse.cdt.internal.ui.editor.ITranslationUnitEditorInput;
-
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.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.cdt.core.model.ITranslationUnit;
+
+import org.eclipse.cdt.internal.ui.editor.ITranslationUnitEditorInput;
+
/**
* An EditorInput for an external (non-workspace) file.
*/
-public class ExternalEditorInput implements ITranslationUnitEditorInput {
+public class ExternalEditorInput implements ITranslationUnitEditorInput, IPersistableElement {
private IStorage externalFile;
private IResource markerResource;
@@ -43,17 +45,21 @@ public class ExternalEditorInput implements ITranslationUnitEditorInput {
public boolean equals(Object obj) {
if (this == obj)
return true;
- if (!(obj instanceof ExternalEditorInput))
+ if (!(obj instanceof IStorageEditorInput))
return false;
- ExternalEditorInput other = (ExternalEditorInput)obj;
- return externalFile.equals(other.externalFile);
+ IStorageEditorInput other = (IStorageEditorInput)obj;
+ try {
+ return externalFile.equals(other.getStorage());
+ } catch (CoreException exc) {
+ return false;
+ }
}
/*
* @see IEditorInput#exists()
*/
public boolean exists() {
- // External file ca not be deleted
+ // External file can not be deleted
return true;
}
@@ -62,12 +68,7 @@ public class ExternalEditorInput implements ITranslationUnitEditorInput {
*/
public Object getAdapter(Class adapter) {
if (ILocationProvider.class.equals(adapter)) {
- // workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=180003
- // see also https://bugs.eclipse.org/bugs/show_bug.cgi?id=179982
- if (location != null) {
- return this;
- }
- return null;
+ return this;
}
return Platform.getAdapterManager().getAdapter(this, adapter);
}
@@ -91,7 +92,7 @@ public class ExternalEditorInput implements ITranslationUnitEditorInput {
* @see IEditorInput#getPersistable()
*/
public IPersistableElement getPersistable() {
- return null;
+ return this;
}
/*
@@ -119,7 +120,7 @@ public class ExternalEditorInput implements ITranslationUnitEditorInput {
* @see org.eclipse.ui.editors.text.ILocationProvider#getPath(java.lang.Object)
*/
public IPath getPath(Object element) {
- return location ;
+ return location;
}
public ExternalEditorInput(ITranslationUnit unit, IStorage exFile) {
@@ -152,7 +153,19 @@ public class ExternalEditorInput implements ITranslationUnitEditorInput {
public IResource getMarkerResource() {
return markerResource;
}
-
-
+ /*
+ * @see org.eclipse.ui.IPersistableElement#getFactoryId()
+ */
+ public String getFactoryId() {
+ return ExternalEditorInputFactory.ID;
+ }
+
+ /*
+ * @see org.eclipse.ui.IPersistable#saveState(org.eclipse.ui.IMemento)
+ */
+ public void saveState(IMemento memento) {
+ ExternalEditorInputFactory.saveState(memento, this);
+ }
+
}
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
new file mode 100644
index 00000000000..ebcc7fa86f4
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/ExternalEditorInputFactory.java
@@ -0,0 +1,92 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Anton Leherbauer (Wind River Systems) - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.cdt.internal.ui.util;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.ui.IElementFactory;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.IPersistableElement;
+
+import org.eclipse.cdt.core.model.CoreModel;
+import org.eclipse.cdt.core.model.ICProject;
+import org.eclipse.cdt.core.model.ITranslationUnit;
+
+/**
+ * The ExternalEditorInputFactory is used to save and recreate an ExternalEditorInput object.
+ * As such, it implements the IPersistableElement interface for storage
+ * and the IElementFactory interface for recreation.
+ *
+ * @see IMemento
+ * @see IPersistableElement
+ * @see IElementFactory
+ *
+ * @since 4.0
+ */
+public class ExternalEditorInputFactory implements IElementFactory {
+
+ public static final String ID = "org.eclipse.cdt.ui.ExternalEditorInputFactory"; //$NON-NLS-1$
+
+ private static final String TAG_PATH = "path";//$NON-NLS-1$
+ private static final String TAG_PROJECT = "project";//$NON-NLS-1$
+
+ /*
+ * @see org.eclipse.ui.IElementFactory#createElement(org.eclipse.ui.IMemento)
+ */
+ public IAdaptable createElement(IMemento memento) {
+ // Get the file name.
+ String fileName = memento.getString(TAG_PATH);
+ if (fileName == null) {
+ return null;
+ }
+
+ IPath location= new Path(fileName);
+ ICProject cProject= null;
+
+ String projectName= memento.getString(TAG_PROJECT);
+ if (projectName != null) {
+ IProject project= ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+ if (project.isAccessible() && CoreModel.hasCNature(project)) {
+ cProject= CoreModel.getDefault().create(project);
+ }
+ }
+ return EditorUtility.getEditorInputForLocation(location, cProject);
+ }
+
+ /**
+ * Save the element state.
+ *
+ * @param memento the storage
+ * @param input the element
+ */
+ static void saveState(IMemento memento, ExternalEditorInput input) {
+ IPath location= input.getPath(input);
+ if (location != null) {
+ memento.putString(TAG_PATH, location.toOSString());
+ }
+ IProject project= null;
+ ITranslationUnit unit= input.getTranslationUnit();
+ if (unit != null) {
+ project= unit.getCProject().getProject();
+ }
+ if (project == null && input.getMarkerResource() instanceof IProject) {
+ project= (IProject)input.getMarkerResource();
+ }
+ if (project != null) {
+ memento.putString(TAG_PROJECT, project.getName());
+ }
+ }
+
+}