mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-25 09:55:29 +02:00
Refactor the IWorkingCopyManager interface in
the public area.
This commit is contained in:
parent
0ced3f795d
commit
ced9493e7a
4 changed files with 164 additions and 9 deletions
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
|
@ -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);
|
||||
}
|
Loading…
Add table
Reference in a new issue