diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CReconcilingStrategy.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CReconcilingStrategy.java index 94ad30e70dd..16705e5afc2 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CReconcilingStrategy.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CReconcilingStrategy.java @@ -6,11 +6,12 @@ package org.eclipse.cdt.internal.ui.text; */ import org.eclipse.cdt.core.model.CModelException; +import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.internal.core.model.IWorkingCopy; import org.eclipse.cdt.internal.ui.editor.CContentOutlinePage; import org.eclipse.cdt.internal.ui.editor.CEditor; -import org.eclipse.cdt.internal.ui.editor.IWorkingCopyManager; import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.cdt.ui.IWorkingCopyManager; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IRegion; @@ -79,8 +80,9 @@ public class CReconcilingStrategy implements IReconcilingStrategy { private void reconcile() { try { - IWorkingCopy workingCopy = fManager.getWorkingCopy(fEditor.getEditorInput()); - if (workingCopy != null) { + ITranslationUnit tu = fManager.getWorkingCopy(fEditor.getEditorInput()); + if (tu != null && tu.isWorkingCopy()) { + IWorkingCopy workingCopy = (IWorkingCopy)tu; // reconcile synchronized (workingCopy) { workingCopy.reconcile(true, fProgressMonitor); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CUIPlugin.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CUIPlugin.java index be90c42868f..8bf3edf8f60 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CUIPlugin.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CUIPlugin.java @@ -17,7 +17,7 @@ import org.eclipse.cdt.internal.ui.CPluginImages; import org.eclipse.cdt.internal.ui.ResourceAdapterFactory; import org.eclipse.cdt.internal.ui.cview.CView; import org.eclipse.cdt.internal.ui.editor.CDocumentProvider; -import org.eclipse.cdt.internal.ui.editor.IWorkingCopyManager; +import org.eclipse.cdt.internal.ui.editor.WorkingCopyManager; import org.eclipse.cdt.internal.ui.editor.asm.AsmTextTools; import org.eclipse.cdt.internal.ui.preferences.BuildConsolePreferencePage; import org.eclipse.cdt.internal.ui.preferences.CEditorPreferencePage; @@ -140,10 +140,13 @@ public class CUIPlugin extends AbstractUIPlugin { private CoreModel fCoreModel; private CDocumentProvider fDocumentProvider; + private IWorkingCopyManager fWorkingCopyManager; private CTextTools fTextTools; private AsmTextTools fAsmTextTools; private ProblemMarkerManager fProblemMarkerManager; private BuildConsoleManager fBuildConsoleManager; + private ResourceAdapterFactory fResourceAdapterFactory; + private CElementAdapterFactory fCElementAdapterFactory; public CUIPlugin(IPluginDescriptor descriptor) { @@ -167,8 +170,12 @@ public class CUIPlugin extends AbstractUIPlugin { * Returns the working copy manager * @return IWorkingCopyManager */ - public IWorkingCopyManager getWorkingCopyManager() { - return getDocumentProvider(); + public synchronized IWorkingCopyManager getWorkingCopyManager() { + if (fWorkingCopyManager == null) { + CDocumentProvider provider = getDocumentProvider(); + fWorkingCopyManager = new WorkingCopyManager(provider); + } + return fWorkingCopyManager; } /** @@ -210,7 +217,20 @@ public class CUIPlugin extends AbstractUIPlugin { fBuildConsoleManager.shutdown(); fBuildConsoleManager = null; } + + unregisterAdapters(); + super.shutdown(); + + if (fWorkingCopyManager != null) { + fWorkingCopyManager.shutdown(); + fWorkingCopyManager= null; + } + + if (fDocumentProvider != null) { + fDocumentProvider.shutdown(); + fDocumentProvider= null; + } } private void runUI(Runnable run) { @@ -230,9 +250,7 @@ public class CUIPlugin extends AbstractUIPlugin { */ public void startup() throws CoreException { super.startup(); - IAdapterManager manager = Platform.getAdapterManager(); - manager.registerAdapters(new ResourceAdapterFactory(), IResource.class); - manager.registerAdapters(new CElementAdapterFactory(), ICElement.class); + registerAdapters(); runUI(new Runnable() { public void run() { CPluginImages.initialize(); @@ -282,4 +300,19 @@ public class CUIPlugin extends AbstractUIPlugin { return fProblemMarkerManager; } + private void registerAdapters() { + fResourceAdapterFactory = new ResourceAdapterFactory(); + fCElementAdapterFactory = new CElementAdapterFactory(); + + IAdapterManager manager = Platform.getAdapterManager(); + manager.registerAdapters(fResourceAdapterFactory, IResource.class); + manager.registerAdapters(fCElementAdapterFactory, ICElement.class); + } + + private void unregisterAdapters() { + IAdapterManager manager = Platform.getAdapterManager(); + manager.unregisterAdapters(fResourceAdapterFactory); + manager.unregisterAdapters(fCElementAdapterFactory); + } + } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/IWorkingCopyManager.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/IWorkingCopyManager.java new file mode 100644 index 00000000000..c3588c44f58 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/IWorkingCopyManager.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * 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.ui; + +import org.eclipse.core.runtime.CoreException; + +import org.eclipse.ui.IEditorInput; + +import org.eclipse.cdt.core.model.ITranslationUnit; + +/** + * Interface for accessing working copies of ITranslationUnit + * objects. The original translation unit is only given indirectly by means + * of an IEditorInput. The life cycle is as follows: + * + *

+ * This interface is not intended to be implemented by clients. + *

+ * + * @see JavaUI#getWorkingCopyManager + */ +public interface IWorkingCopyManager { + + /** + * Connects the given editor input to this manager. After calling + * this method, a working copy will be available for the translation unit encoded + * in the given editor input (does nothing if there is no encoded translation unit). + * + * @param input the editor input + * @exception CoreException if the working copy cannot be created for the + * translation unit + */ + void connect(IEditorInput input) throws CoreException; + + /** + * Disconnects the given editor input from this manager. After calling + * this method, a working copy for the translation unit encoded + * in the given editor input will no longer be available. Does nothing if there + * is no encoded translation unit, or if there is no remembered working copy for + * the translation unit. + * + * @param input the editor input + */ + void disconnect(IEditorInput input); + + /** + * Returns the working copy remembered for the translation unit encoded in the + * given editor input. + * + * @param input the editor input + * @return the working copy of the translation unit, or null if the + * input does not encode an editor input, or if there is no remembered working + * copy for this translation unit + */ + ITranslationUnit getWorkingCopy(IEditorInput input); + + /** + * Shuts down this working copy manager. All working copies still remembered + * by this manager are destroyed. + */ + void shutdown(); +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/IWorkingCopyManagerExtension.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/IWorkingCopyManagerExtension.java new file mode 100644 index 00000000000..00354408d3f --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/IWorkingCopyManagerExtension.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * 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.ui; + +import org.eclipse.ui.IEditorInput; + +import org.eclipse.cdt.core.model.ITranslationUnit; + +/** + * Extension interface for IWorkingCopyManager. + * @since 2.1 + */ +public interface IWorkingCopyManagerExtension { + + /** + * Sets the given working copy for the given editor input. If the given editor input + * is not connected to this working copy manager, this call has no effect.

+ * This working copy manager does not assume the ownership of this working copy, i.e., + * the given working copy is not automatically be freed when this manager is shut down. + * + * @param input the editor input + * @param workingCopy the working copy + */ + void setWorkingCopy(IEditorInput input, ITranslationUnit workingCopy); + + /** + * Removes the working copy set for the given editor input. If there is no + * working copy set for this input or this input is not connected to this + * working copy manager, this call has no effect. + * + * @param input the editor input + */ + void removeWorkingCopy(IEditorInput input); +}