[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[cdt-patch] WorkingCopyManager refactor
|
Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/ChangeLog,v
retrieving revision 1.82
diff -u -r1.82 ChangeLog
--- ChangeLog 5 Apr 2003 02:05:00 -0000 1.82
+++ ChangeLog 5 Apr 2003 06:26:04 -0000
@@ -1,3 +1,26 @@
+2003-04-05 Alain Magloire
+
+ The way the working copy was implemented, the outline could not
+ work with file outside of the C Model, for example a c file in
+ a non C project. Also some other extended the CEditor to reuse
+ the highligth and outliner functions, but since the DocumentProvider
+ was singleton in CUIPlugin.getDocumentProvider(), the outliner did not
+ work either. A solution is to take the same path as the JDT and provide
+ a workingcopy that can be use by other so they can "connect" thre input.
+
+ Part of this patch a small refactory of IWorkingCopyManager so
+ it can be visible outside.
+
+ * src/org/eclipse/cdt/ui/CUIPlugin.java
+ * src/org/eclipse/cdt/ui/IWorkingCopyManager.java
+ * src/org/eclipse/cdt/ui/IWorkingCopyManagerExtension.java
+ * src/org/eclipse/cdt/internal/ui/editor/CContentOutline.java:
+ * src/org/eclipse/cdt/internal/ui/editor/CDocumentProvider.java
+ * src/org/eclipse/cdt/internal/ui/editor/CEditor.java
+ * src/org/eclipse/cdt/internal/ui/editor/WorkingCopyManager.java
+ * src/org/eclipse/cdt/internal/ui/editor/WorkingCopyManager.java
+ * src/org/eclipse/cdt/internal/ui/text/CReconcilerStrategy.java
+
2003-04-04 Alain Magloire
The TextEditor provides a way to select a range to be edited.
Index: src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java,v
retrieving revision 1.8
diff -u -r1.8 CContentOutlinePage.java
--- src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java 5 Apr 2003 02:04:45 -0000 1.8
+++ src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java 5 Apr 2003 06:26:07 -0000
@@ -15,6 +15,7 @@
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 @@
//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);
Index: src/org/eclipse/cdt/internal/ui/editor/CDocumentProvider.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CDocumentProvider.java,v
retrieving revision 1.11
diff -u -r1.11 CDocumentProvider.java
--- src/org/eclipse/cdt/internal/ui/editor/CDocumentProvider.java 27 Mar 2003 17:40:15 -0000 1.11
+++ src/org/eclipse/cdt/internal/ui/editor/CDocumentProvider.java 5 Apr 2003 06:26:08 -0000
@@ -42,7 +42,7 @@
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 void shutdown() {
+ // TODO Auto-generated method stub
+ }
+
+ /**
+ * @param input
+ * @return
+ */
+ public boolean isConnected(IEditorInput input) {
+ return getElementInfo(input) != null;
+ }
}
Index: src/org/eclipse/cdt/internal/ui/editor/CEditor.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java,v
retrieving revision 1.19
diff -u -r1.19 CEditor.java
--- src/org/eclipse/cdt/internal/ui/editor/CEditor.java 4 Apr 2003 20:33:45 -0000 1.19
+++ src/org/eclipse/cdt/internal/ui/editor/CEditor.java 5 Apr 2003 06:26:12 -0000
@@ -200,7 +200,7 @@
setEditorContextMenuId("#CEditorContext"); //$NON-NLS-1$
setRulerContextMenuId("#CEditorRulerContext"); //$NON-NLS-1$
- //setOutlinerContextMenuId("#CEditorOutlinerContext"); //$NON-NLS-1$
+ setOutlinerContextMenuId("#CEditorOutlinerContext"); //$NON-NLS-1$
fCEditorErrorTickUpdater= new CEditorErrorTickUpdater(this);
}
Index: src/org/eclipse/cdt/internal/ui/editor/IWorkingCopyManager.java
===================================================================
RCS file: src/org/eclipse/cdt/internal/ui/editor/IWorkingCopyManager.java
diff -N src/org/eclipse/cdt/internal/ui/editor/IWorkingCopyManager.java
--- src/org/eclipse/cdt/internal/ui/editor/IWorkingCopyManager.java 19 Mar 2003 20:21:08 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -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 <code>ITranslationUnit</code>
- * objects. The original Translation unit is only given indirectly by means of
- * an <code>IEditorInput</code>.
- * <p>
- * This interface is not intended to be implemented by clients.
- * </p>
- *
- * @see CUIPlugin#getWorkingCopyManager
- *
- * This interface is similar to the JDT IWorkingCopyManager.
- */
-
-public interface IWorkingCopyManager {
-
- IWorkingCopy getWorkingCopy(IEditorInput input);
-
-}
\ No newline at end of file
Index: src/org/eclipse/cdt/internal/ui/editor/WorkingCopyManager.java
===================================================================
RCS file: src/org/eclipse/cdt/internal/ui/editor/WorkingCopyManager.java
diff -N src/org/eclipse/cdt/internal/ui/editor/WorkingCopyManager.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/internal/ui/editor/WorkingCopyManager.java 5 Apr 2003 06:26:13 -0000
@@ -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;
+ }
+}
Index: src/org/eclipse/cdt/internal/ui/text/CReconcilingStrategy.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CReconcilingStrategy.java,v
retrieving revision 1.2
diff -u -r1.2 CReconcilingStrategy.java
--- src/org/eclipse/cdt/internal/ui/text/CReconcilingStrategy.java 19 Mar 2003 20:21:14 -0000 1.2
+++ src/org/eclipse/cdt/internal/ui/text/CReconcilingStrategy.java 5 Apr 2003 06:26:13 -0000
@@ -6,11 +6,12 @@
*/
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 @@
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);
Index: src/org/eclipse/cdt/ui/CUIPlugin.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CUIPlugin.java,v
retrieving revision 1.11
diff -u -r1.11 CUIPlugin.java
--- src/org/eclipse/cdt/ui/CUIPlugin.java 4 Apr 2003 20:38:29 -0000 1.11
+++ src/org/eclipse/cdt/ui/CUIPlugin.java 5 Apr 2003 06:26:15 -0000
@@ -17,7 +17,7 @@
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 @@
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 @@
* 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 @@
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 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();
@@ -280,6 +298,21 @@
if (fProblemMarkerManager == null)
fProblemMarkerManager = new ProblemMarkerManager();
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);
}
}
Index: src/org/eclipse/cdt/ui/IWorkingCopyManager.java
===================================================================
RCS file: src/org/eclipse/cdt/ui/IWorkingCopyManager.java
diff -N src/org/eclipse/cdt/ui/IWorkingCopyManager.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/ui/IWorkingCopyManager.java 5 Apr 2003 06:26:15 -0000
@@ -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 <code>ITranslationUnit</code>
+ * objects. The original translation unit is only given indirectly by means
+ * of an <code>IEditorInput</code>. The life cycle is as follows:
+ * <ul>
+ * <li> <code>connect</code> creates and remembers a working copy of the
+ * translation unit which is encoded in the given editor input</li>
+ * <li> <code>getWorkingCopy</code> returns the working copy remembered on
+ * <code>connect</code></li>
+ * <li> <code>disconnect</code> destroys the working copy remembered on
+ * <code>connect</code></li>
+ * </ul>
+ * <p>
+ * This interface is not intended to be implemented by clients.
+ * </p>
+ *
+ * @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 <code>null</code> 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();
+}
Index: src/org/eclipse/cdt/ui/IWorkingCopyManagerExtension.java
===================================================================
RCS file: src/org/eclipse/cdt/ui/IWorkingCopyManagerExtension.java
diff -N src/org/eclipse/cdt/ui/IWorkingCopyManagerExtension.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/ui/IWorkingCopyManagerExtension.java 5 Apr 2003 06:26:15 -0000
@@ -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 <code>IWorkingCopyManager</code>.
+ * @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. <p>
+ * 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);
+}