diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java
index 7e1633bdffa..1b33232f82d 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java
@@ -15,6 +15,7 @@ import org.eclipse.cdt.internal.ui.StandardCElementLabelProvider;
import org.eclipse.cdt.internal.ui.util.ProblemTreeViewer;
import org.eclipse.cdt.ui.CElementContentProvider;
import org.eclipse.cdt.ui.CUIPlugin;
+import org.eclipse.cdt.ui.IWorkingCopyManager;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
@@ -167,6 +168,9 @@ public class CContentOutlinePage extends Page implements IContentOutlinePage, IS
//fInput = new CFileElementWorkingCopy((IFileEditorInput)editorInput, provider);
IWorkingCopyManager wcManager = CUIPlugin.getDefault().getWorkingCopyManager();
fInput = (WorkingCopy)wcManager.getWorkingCopy(editorInput);
+ if (fInput == null) {
+ fInput = new CFileElementWorkingCopy((IFileEditorInput)editorInput, provider);
+ }
} else if (editorInput instanceof IStorageEditorInput){
// CHECKPOINT: do we create a CFileElementWorkingCopy or just a working copy for the IStorageEditorInput?
//fInput = ((CUIPlugin.ElementFactory)plugin.getCCore()).createWorkingCopy((IStorageEditorInput)editorInput, provider);
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 e6902d48466..fbc691e6326 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
@@ -42,7 +42,7 @@ import org.eclipse.ui.editors.text.FileDocumentProvider;
import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel;
-public class CDocumentProvider extends FileDocumentProvider implements IWorkingCopyManager {
+public class CDocumentProvider extends FileDocumentProvider {
static private class RegisteredReplace {
IDocumentListener fOwner;
@@ -393,5 +393,19 @@ public class CDocumentProvider extends FileDocumentProvider implements IWorkingC
}
}
+ /**
+ *
+ */
+ public void shutdown() {
+ // TODO Auto-generated method stub
+ }
+
+ /**
+ * @param input
+ * @return
+ */
+ public boolean isConnected(IEditorInput input) {
+ return getElementInfo(input) != null;
+ }
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java
index ee79dea58ef..c071dcd8fdb 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java
@@ -200,7 +200,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener {
setEditorContextMenuId("#CEditorContext"); //$NON-NLS-1$
setRulerContextMenuId("#CEditorRulerContext"); //$NON-NLS-1$
- //setOutlinerContextMenuId("#CEditorOutlinerContext"); //$NON-NLS-1$
+ setOutlinerContextMenuId("#CEditorOutlinerContext"); //$NON-NLS-1$
fCEditorErrorTickUpdater= new CEditorErrorTickUpdater(this);
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/IWorkingCopyManager.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/IWorkingCopyManager.java
deleted file mode 100644
index a87b46ad0bb..00000000000
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/IWorkingCopyManager.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package org.eclipse.cdt.internal.ui.editor;
-
-/**********************************************************************
- * Copyright (c) 2002,2003 Rational Software Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v0.5
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v05.html
- *
- * Contributors:
- * Rational Software - Initial API and implementation
-***********************************************************************/
-
-import org.eclipse.cdt.internal.core.model.IWorkingCopy;
-import org.eclipse.ui.IEditorInput;
-
-/**
- * Interface for accessing working copies of ITranslationUnit
- * objects. The original Translation unit is only given indirectly by means of
- * an IEditorInput
.
- *
- * This interface is not intended to be implemented by clients. - *
- * - * @see CUIPlugin#getWorkingCopyManager - * - * This interface is similar to the JDT IWorkingCopyManager. - */ - -public interface IWorkingCopyManager { - - IWorkingCopy getWorkingCopy(IEditorInput input); - -} \ No newline at end of file diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/WorkingCopyManager.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/WorkingCopyManager.java new file mode 100644 index 00000000000..ba0435f85f0 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/WorkingCopyManager.java @@ -0,0 +1,110 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.internal.ui.editor; + + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.core.runtime.CoreException; + +import org.eclipse.jface.text.Assert; + +import org.eclipse.ui.IEditorInput; + +import org.eclipse.cdt.core.model.ITranslationUnit; + +import org.eclipse.cdt.ui.IWorkingCopyManager; +import org.eclipse.cdt.ui.IWorkingCopyManagerExtension; + + +/** + * This working copy manager works together with a given compilation unit document provider and + * additionally offers to "overwrite" the working copy provided by this document provider. + */ +public class WorkingCopyManager implements IWorkingCopyManager, IWorkingCopyManagerExtension { + + private CDocumentProvider fDocumentProvider; + private Map fMap; + private boolean fIsShuttingDown; + + /** + * Creates a new working copy manager that co-operates with the given + * compilation unit document provider. + * + * @param provider the provider + */ + public WorkingCopyManager(CDocumentProvider provider) { + Assert.isNotNull(provider); + fDocumentProvider= provider; + } + + /* + * @see org.eclipse.cdt.ui.IWorkingCopyManager#connect(org.eclipse.ui.IEditorInput) + */ + public void connect(IEditorInput input) throws CoreException { + fDocumentProvider.connect(input); + } + + /* + * @see org.eclipse.cdt.ui.IWorkingCopyManager#disconnect(org.eclipse.ui.IEditorInput) + */ + public void disconnect(IEditorInput input) { + fDocumentProvider.disconnect(input); + } + + /* + * @see org.eclipse.cdt.ui.IWorkingCopyManager#shutdown() + */ + public void shutdown() { + if (!fIsShuttingDown) { + fIsShuttingDown= true; + try { + if (fMap != null) { + fMap.clear(); + fMap= null; + } + fDocumentProvider.shutdown(); + } finally { + fIsShuttingDown= false; + } + } + } + + /* + * @see org.eclipse.cdt.ui.IWorkingCopyManager#getWorkingCopy(org.eclipse.ui.IEditorInput) + */ + public ITranslationUnit getWorkingCopy(IEditorInput input) { + ITranslationUnit unit= fMap == null ? null : (ITranslationUnit) fMap.get(input); + return unit != null ? unit : fDocumentProvider.getWorkingCopy(input); + } + + /* + * @see org.eclipse.cdt.internal.ui.editor.IWorkingCopyManagerExtension#setWorkingCopy(org.eclipse.ui.IEditorInput, org.eclipse.cdt.core.model.ITranslationUnit) + */ + public void setWorkingCopy(IEditorInput input, ITranslationUnit workingCopy) { + if (fDocumentProvider.isConnected(input)) { + if (fMap == null) + fMap= new HashMap(); + fMap.put(input, workingCopy); + } + } + + /* + * @see org.eclipse.cdt.internal.ui.editor.IWorkingCopyManagerExtension#removeWorkingCopy(org.eclipse.ui.IEditorInput) + */ + public void removeWorkingCopy(IEditorInput input) { + fMap.remove(input); + if (fMap.isEmpty()) + fMap= null; + } +}