1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

New scheme to use the WorkingCopyManager, this

will allow a the content outliner to work for
editor extending the CEditor and file not
in a c/c++ project.
This commit is contained in:
Alain Magloire 2003-04-05 06:33:29 +00:00
parent f0e9cda669
commit 0ced3f795d
5 changed files with 130 additions and 36 deletions

View file

@ -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);

View file

@ -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;
}
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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;
}
}