mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Changes to CDocumentProvider to use Eclipse-3.0 TextFileDocumentProvider
The changes had the side effect of moving the IBufferFactory also It is now in CustoBufferFactory. The DocumentAdapter for C File was rewritten
This commit is contained in:
parent
981f445bb4
commit
93dfa55ecf
23 changed files with 590 additions and 773 deletions
|
@ -1,3 +1,37 @@
|
|||
2004-04-18 Alain Magloire
|
||||
|
||||
First part to move to Eclipse-3.0 new DocumentProvider scheme
|
||||
for the CEditor. Changes were made to the IBufferFactory, it
|
||||
is now one class CustomBufferFactory in CUIPlugin.getBufferFactory()
|
||||
|
||||
* plugin.xml
|
||||
* src/org/eclipse/cdt/internal/ui/editor/AddIncludeOnSelectionAction.java
|
||||
* src/org/eclipse/cdt/internal/ui/editor/CContentOutlinerPage.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/CStorageDocumentProvider.java
|
||||
* src/org/eclipse/cdt/internal/ui/editor/CustomBufferFactory.java
|
||||
* src/org/eclipse/cdt/internal/ui/editor/DocumenAdapter.java
|
||||
* src/org/eclipse/cdt/internal/ui/editor/ITranslationUnitEditorInput.java
|
||||
* src/org/eclipse/cdt/internal/ui/editor/OpenIncludeAction.java
|
||||
* src/org/eclipse/cdt/internal/ui/editor/WorkingCopyManager.java
|
||||
|
||||
* src/org/eclipse/cdt/internal/ui/text/CTextTools.java
|
||||
|
||||
* src/org/eclipse/cdt/internal/ui/util/EditorUtility.java
|
||||
* src/org/eclipse/cdt/internal/ui/util/ExternalEditorInput.java
|
||||
|
||||
* src/org/eclipse/cdt/ui/CUIPlugin.java
|
||||
|
||||
* src/org/eclipse/cdt/ui/wizards/NewClassWizardPage.java
|
||||
|
||||
* src/org/eclipse/cdt/internal/ui/BaseCElementContentProvider.java
|
||||
* src/org/eclipse/cdt/internal/ui/CFileElementWorkingCopy.java
|
||||
|
||||
* src/org/eclipse/cdt/internal/ui/codemanipulation/AddIncludeOperation.java
|
||||
* src/org/eclipse/cdt/internal/ui/cview/CViewContentProvider.java
|
||||
* src/org/eclipse/cdt/internal/ui/cview/IncludRefContainer.java
|
||||
|
||||
2004-04-16 Hoda Amer
|
||||
Fix for bug#44364 : [Content Assist] case sensitivity option
|
||||
Fix for bug#53446 : [New Class Wizard] Be able to configure new class wizard to not open source
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
<import plugin="org.eclipse.cdt.core"/>
|
||||
<import plugin="org.eclipse.core.runtime.compatibility"/>
|
||||
<import plugin="org.eclipse.ui.console"/>
|
||||
<import plugin="org.eclipse.core.filebuffers"/>
|
||||
</requires>
|
||||
|
||||
|
||||
|
|
|
@ -143,7 +143,7 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
|
|||
if(!(element instanceof IWorkingCopy)){
|
||||
// if it has a valid working copy
|
||||
ITranslationUnit tu = (ITranslationUnit)element;
|
||||
IWorkingCopy copy = tu.findSharedWorkingCopy(CUIPlugin.getBufferFactory());
|
||||
IWorkingCopy copy = tu.findSharedWorkingCopy(CUIPlugin.getDefault().getBufferFactory());
|
||||
if(copy != null) {
|
||||
return ((IParent)copy).getChildren();
|
||||
}
|
||||
|
|
|
@ -7,225 +7,35 @@ package org.eclipse.cdt.internal.ui;
|
|||
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.IBuffer;
|
||||
import org.eclipse.cdt.core.model.IBufferChangedListener;
|
||||
import org.eclipse.cdt.core.model.IOpenable;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.internal.core.model.WorkingCopy;
|
||||
import org.eclipse.cdt.internal.ui.editor.CDocumentProvider;
|
||||
import org.eclipse.cdt.internal.ui.editor.DocumentAdapter;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IStorage;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.jface.text.BadLocationException;
|
||||
import org.eclipse.jface.text.DefaultLineTracker;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.ui.IEditorInput;
|
||||
import org.eclipse.ui.IStorageEditorInput;
|
||||
import org.eclipse.ui.texteditor.IDocumentProvider;
|
||||
|
||||
public class CFileElementWorkingCopy extends WorkingCopy {
|
||||
|
||||
IDocumentProvider fProvider;
|
||||
IEditorInput input;
|
||||
IBuffer buffer;
|
||||
ITranslationUnit unit;
|
||||
|
||||
/**
|
||||
* Internal IBuffer implementation very simple, must cases will use DocumentAdapter.
|
||||
*
|
||||
*/
|
||||
class Buffer implements IBuffer {
|
||||
|
||||
CFileElementWorkingCopy owner;
|
||||
|
||||
public Buffer(CFileElementWorkingCopy o) {
|
||||
owner = o;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.IBuffer#addBufferChangedListener(org.eclipse.cdt.core.model.IBufferChangedListener)
|
||||
*/
|
||||
public void addBufferChangedListener(IBufferChangedListener listener) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.IBuffer#append(char[])
|
||||
*/
|
||||
public void append(char[] text) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.IBuffer#append(java.lang.String)
|
||||
*/
|
||||
public void append(String text) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.IBuffer#close()
|
||||
*/
|
||||
public void close() {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.IBuffer#getChar(int)
|
||||
*/
|
||||
public char getChar(int position) {
|
||||
IDocument doc = fProvider.getDocument(input);
|
||||
if (doc != null) {
|
||||
try {
|
||||
return doc.getChar(position);
|
||||
} catch (BadLocationException e) {
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.IBuffer#getCharacters()
|
||||
*/
|
||||
public char[] getCharacters() {
|
||||
return getContents().toCharArray();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.IBuffer#getContents()
|
||||
*/
|
||||
public String getContents() {
|
||||
IDocument doc = fProvider.getDocument(input);
|
||||
if (doc != null) {
|
||||
return doc.get();
|
||||
}
|
||||
return new String();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.IBuffer#getLength()
|
||||
*/
|
||||
public int getLength() {
|
||||
IDocument doc = fProvider.getDocument(input);
|
||||
if (doc != null) {
|
||||
return doc.getLength();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.IBuffer#getOwner()
|
||||
*/
|
||||
public IOpenable getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.IBuffer#getText(int, int)
|
||||
*/
|
||||
public String getText(int offset, int length) {
|
||||
IDocument doc = fProvider.getDocument(input);
|
||||
if (doc != null) {
|
||||
try {
|
||||
return doc.get(offset, length);
|
||||
} catch (BadLocationException e) {
|
||||
}
|
||||
}
|
||||
return new String();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.IBuffer#getUnderlyingResource()
|
||||
*/
|
||||
public IResource getUnderlyingResource() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.IBuffer#hasUnsavedChanges()
|
||||
*/
|
||||
public boolean hasUnsavedChanges() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.IBuffer#isClosed()
|
||||
*/
|
||||
public boolean isClosed() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.IBuffer#isReadOnly()
|
||||
*/
|
||||
public boolean isReadOnly() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.IBuffer#removeBufferChangedListener(org.eclipse.cdt.core.model.IBufferChangedListener)
|
||||
*/
|
||||
public void removeBufferChangedListener(IBufferChangedListener listener) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.IBuffer#replace(int, int, char[])
|
||||
*/
|
||||
public void replace(int position, int length, char[] text) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.IBuffer#replace(int, int, java.lang.String)
|
||||
*/
|
||||
public void replace(int position, int length, String text) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.IBuffer#save(org.eclipse.core.runtime.IProgressMonitor, boolean)
|
||||
*/
|
||||
public void save(IProgressMonitor progress, boolean force) throws CModelException {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.IBuffer#setContents(char[])
|
||||
*/
|
||||
public void setContents(char[] contents) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.IBuffer#setContents(java.lang.String)
|
||||
*/
|
||||
public void setContents(String contents) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a working copy of this element
|
||||
*/
|
||||
public CFileElementWorkingCopy(IStorageEditorInput StoreInput, IDocumentProvider provider) throws CoreException {
|
||||
super(null, new Path(StoreInput.getName()), null);
|
||||
input = StoreInput;
|
||||
fProvider = provider;
|
||||
IStorage storage = StoreInput.getStorage();
|
||||
super.setLocation(storage.getFullPath());
|
||||
public CFileElementWorkingCopy(ITranslationUnit unit) throws CoreException {
|
||||
super(unit.getParent(), unit.getPath(), null);
|
||||
this.unit = unit;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.IOpenable#getBuffer()
|
||||
*/
|
||||
public IBuffer getBuffer() throws CModelException {
|
||||
if (buffer == null) {
|
||||
if (fProvider instanceof CDocumentProvider) {
|
||||
buffer = new DocumentAdapter(this, fProvider.getDocument(input), new DefaultLineTracker(), (CDocumentProvider)fProvider, input);
|
||||
} else {
|
||||
buffer = new Buffer(this);
|
||||
}
|
||||
}
|
||||
return buffer;
|
||||
return unit.getBuffer();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.model.IWorkingCopy#getOriginalElement()
|
||||
*/
|
||||
public ITranslationUnit getOriginalElement() {
|
||||
return this;
|
||||
return unit;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import org.eclipse.cdt.core.model.ICElement;
|
|||
import org.eclipse.cdt.core.model.IInclude;
|
||||
import org.eclipse.cdt.core.model.IParent;
|
||||
import org.eclipse.cdt.core.model.ISourceRange;
|
||||
import org.eclipse.cdt.internal.ui.CFileElementWorkingCopy;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.internal.ui.editor.CContentOutlinePage;
|
||||
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
||||
import org.eclipse.cdt.internal.ui.editor.CEditorMessages;
|
||||
|
@ -33,7 +33,7 @@ import org.eclipse.ui.texteditor.ITextEditor;
|
|||
*/
|
||||
public class AddIncludeOperation extends WorkspaceModifyOperation {
|
||||
|
||||
private CFileElementWorkingCopy fTranslationUnit;
|
||||
private ITranslationUnit fTranslationUnit;
|
||||
private IRequiredInclude[] fIncludes;
|
||||
private boolean fDoSave;
|
||||
private ITextEditor fEditor;
|
||||
|
@ -45,7 +45,7 @@ public class AddIncludeOperation extends WorkspaceModifyOperation {
|
|||
* Elements must be of type IType (-> single import) or IPackageFragment
|
||||
* (on-demand-import). Other JavaElements are ignored
|
||||
*/
|
||||
public AddIncludeOperation(ITextEditor ed, CFileElementWorkingCopy tu, IRequiredInclude[] includes, boolean save) {
|
||||
public AddIncludeOperation(ITextEditor ed, ITranslationUnit tu, IRequiredInclude[] includes, boolean save) {
|
||||
super();
|
||||
fEditor = ed;
|
||||
fIncludes= includes;
|
||||
|
|
|
@ -104,4 +104,21 @@ public class CViewContentProvider extends CElementContentProvider {
|
|||
}
|
||||
return extras;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.ui.BaseCElementContentProvider#internalGetParent(java.lang.Object)
|
||||
*/
|
||||
public Object internalGetParent(Object element) {
|
||||
// since we insert logical containers we have to fix
|
||||
// up the parent for includereference so that they refer
|
||||
// to the container and containers refere to the project
|
||||
Object parent = super.internalGetParent(element);
|
||||
if (element instanceof IIncludeReference) {
|
||||
if (parent instanceof ICProject) {
|
||||
parent = new IncludeRefContainer((ICProject)parent);
|
||||
}
|
||||
} else if (element instanceof IncludeRefContainer) {
|
||||
parent = ((IncludeRefContainer)element).getCProject();
|
||||
}
|
||||
return parent;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,4 +82,14 @@ public class IncludeRefContainer implements IAdaptable, IWorkbenchAdapter{
|
|||
return fCProject;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof IncludeRefContainer) {
|
||||
IncludeRefContainer other = (IncludeRefContainer)obj;
|
||||
return fCProject.equals(other.getCProject());
|
||||
}
|
||||
return super.equals(obj);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,8 +5,8 @@ package org.eclipse.cdt.internal.ui.editor;
|
|||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.internal.ui.CCompletionContributorManager;
|
||||
import org.eclipse.cdt.internal.ui.CFileElementWorkingCopy;
|
||||
import org.eclipse.cdt.internal.ui.codemanipulation.AddIncludeOperation;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.ui.IFunctionSummary;
|
||||
|
@ -15,10 +15,6 @@ import java.lang.reflect.InvocationTargetException;
|
|||
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.jface.action.Action;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
|
||||
|
@ -28,9 +24,6 @@ import org.eclipse.jface.text.ITextSelection;
|
|||
import org.eclipse.jface.viewers.ISelection;
|
||||
|
||||
import org.eclipse.ui.IEditorInput;
|
||||
import org.eclipse.ui.IFileEditorInput;
|
||||
import org.eclipse.ui.IStorageEditorInput;
|
||||
import org.eclipse.ui.texteditor.IDocumentProvider;
|
||||
import org.eclipse.ui.texteditor.ITextEditor;
|
||||
import org.eclipse.ui.texteditor.IUpdate;
|
||||
|
||||
|
@ -53,7 +46,7 @@ public class AddIncludeOnSelectionAction extends Action implements IUpdate {
|
|||
//WorkbenchHelp.setHelp(this, new Object[] { IJavaHelpContextIds.ADD_IMPORT_ON_SELECTION_ACTION });
|
||||
}
|
||||
|
||||
private void addInclude(IRequiredInclude[] inc, CFileElementWorkingCopy tu) {
|
||||
private void addInclude(IRequiredInclude[] inc, ITranslationUnit tu) {
|
||||
AddIncludeOperation op= new AddIncludeOperation(fEditor, tu, inc, false);
|
||||
try {
|
||||
ProgressMonitorDialog dialog= new ProgressMonitorDialog(getShell());
|
||||
|
@ -66,22 +59,11 @@ public class AddIncludeOnSelectionAction extends Action implements IUpdate {
|
|||
}
|
||||
}
|
||||
|
||||
private CFileElementWorkingCopy getTranslationUnit () {
|
||||
CFileElementWorkingCopy unit = null;
|
||||
private ITranslationUnit getTranslationUnit () {
|
||||
ITranslationUnit unit = null;
|
||||
if(fEditor != null) {
|
||||
IEditorInput editorInput= (IEditorInput)fEditor.getEditorInput();
|
||||
IDocumentProvider provider= fEditor.getDocumentProvider();
|
||||
try {
|
||||
if (editorInput instanceof IFileEditorInput)
|
||||
unit = new CFileElementWorkingCopy((IFileEditorInput)editorInput, provider);
|
||||
else if (editorInput instanceof IStorageEditorInput)
|
||||
unit = new CFileElementWorkingCopy((IStorageEditorInput)editorInput, provider);
|
||||
else
|
||||
throw new CoreException(new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, 0, CEditorMessages.getString("AddIncludeOnSelectionAction.error.noInput"), null)); //$NON-NLS-1$
|
||||
|
||||
} catch (CoreException e) {
|
||||
CUIPlugin.getDefault().log(e.getStatus());
|
||||
}
|
||||
unit = CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(editorInput);
|
||||
}
|
||||
return unit;
|
||||
}
|
||||
|
@ -129,7 +111,7 @@ public class AddIncludeOnSelectionAction extends Action implements IUpdate {
|
|||
}
|
||||
|
||||
if(requiredIncludes != null && requiredIncludes.length > 0) {
|
||||
CFileElementWorkingCopy tu= getTranslationUnit();
|
||||
ITranslationUnit tu= getTranslationUnit();
|
||||
if(tu != null) {
|
||||
addInclude(requiredIncludes, tu);
|
||||
}
|
||||
|
|
|
@ -9,20 +9,14 @@ import java.util.ArrayList;
|
|||
import java.util.Iterator;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||
import org.eclipse.cdt.internal.core.model.WorkingCopy;
|
||||
import org.eclipse.cdt.internal.ui.CFileElementWorkingCopy;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.internal.ui.StandardCElementLabelProvider;
|
||||
import org.eclipse.cdt.internal.ui.search.actions.SelectionSearchGroup;
|
||||
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.cdt.ui.actions.MemberFilterActionGroup;
|
||||
import org.eclipse.cdt.ui.actions.RefactoringActionGroup;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.jface.action.IMenuListener;
|
||||
import org.eclipse.jface.action.IMenuManager;
|
||||
import org.eclipse.jface.action.IToolBarManager;
|
||||
|
@ -41,19 +35,15 @@ import org.eclipse.swt.widgets.Composite;
|
|||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Menu;
|
||||
import org.eclipse.ui.IActionBars;
|
||||
import org.eclipse.ui.IEditorInput;
|
||||
import org.eclipse.ui.IFileEditorInput;
|
||||
import org.eclipse.ui.IStorageEditorInput;
|
||||
import org.eclipse.ui.IWorkbenchActionConstants;
|
||||
import org.eclipse.ui.actions.ActionGroup;
|
||||
import org.eclipse.ui.part.IPageSite;
|
||||
import org.eclipse.ui.part.Page;
|
||||
import org.eclipse.ui.texteditor.IDocumentProvider;
|
||||
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
|
||||
|
||||
public class CContentOutlinePage extends Page implements IContentOutlinePage, ISelectionChangedListener {
|
||||
private CEditor fEditor;
|
||||
private IWorkingCopy fInput;
|
||||
private ITranslationUnit fInput;
|
||||
private ProblemTreeViewer treeViewer;
|
||||
private ListenerList selectionChangedListeners = new ListenerList();
|
||||
private TogglePresentationAction fTogglePresentation;
|
||||
|
@ -194,29 +184,8 @@ public class CContentOutlinePage extends Page implements IContentOutlinePage, IS
|
|||
fSelectionSearchGroup = new SelectionSearchGroup(this);
|
||||
fRefactoringActionGroup = new RefactoringActionGroup(this);
|
||||
|
||||
treeViewer.setInput(fInput);
|
||||
|
||||
IEditorInput editorInput= (IEditorInput)fEditor.getEditorInput();
|
||||
IDocumentProvider provider= fEditor.getDocumentProvider();
|
||||
try {
|
||||
if (editorInput instanceof IFileEditorInput){
|
||||
IWorkingCopyManager wcManager = CUIPlugin.getDefault().getWorkingCopyManager();
|
||||
fInput = (WorkingCopy)wcManager.getWorkingCopy(editorInput);
|
||||
if (fInput == null) {
|
||||
// XXX This should never happen. Put an assert.
|
||||
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?
|
||||
// If it is an IStorage it means that there is no underlying IFile.
|
||||
fInput = new CFileElementWorkingCopy((IStorageEditorInput)editorInput, provider);
|
||||
} else {
|
||||
throw new CoreException(new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, 0, CEditorMessages.getString("CContentOutlinePage.error.noInput"), null)); //$NON-NLS-1$
|
||||
}
|
||||
treeViewer.setInput(fInput);
|
||||
} catch (CoreException e) {
|
||||
CUIPlugin.getDefault().log(e.getStatus());
|
||||
fInput= null;
|
||||
}
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
|
@ -315,7 +284,7 @@ public class CContentOutlinePage extends Page implements IContentOutlinePage, IS
|
|||
/**
|
||||
* @param unit
|
||||
*/
|
||||
public void setInput(IWorkingCopy unit) {
|
||||
public void setInput(ITranslationUnit unit) {
|
||||
fInput = unit;
|
||||
if (treeViewer != null) {
|
||||
treeViewer.setInput (fInput);
|
||||
|
|
|
@ -1,293 +1,170 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002,2003,2004 QNX Software Systems 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:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
***********************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.editor;
|
||||
|
||||
/*
|
||||
* (c) Copyright IBM Corp. 2000, 2001.
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import java.util.Iterator;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.IBuffer;
|
||||
import org.eclipse.cdt.core.model.IOpenable;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||
import org.eclipse.cdt.internal.core.model.IBufferFactory;
|
||||
import org.eclipse.cdt.internal.ui.CStatusConstants;
|
||||
import org.eclipse.cdt.internal.ui.CFileElementWorkingCopy;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.ui.IEditorInputDelegate;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IStorage;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.jface.text.AbstractDocument;
|
||||
import org.eclipse.jface.text.DefaultLineTracker;
|
||||
import org.eclipse.jface.text.Document;
|
||||
import org.eclipse.jface.text.GapTextStore;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.jface.text.IDocumentPartitioner;
|
||||
import org.eclipse.jface.text.ILineTracker;
|
||||
import org.eclipse.jface.text.ISynchronizable;
|
||||
import org.eclipse.jface.text.source.IAnnotationModel;
|
||||
import org.eclipse.ui.IEditorInput;
|
||||
import org.eclipse.ui.IFileEditorInput;
|
||||
import org.eclipse.ui.IStorageEditorInput;
|
||||
import org.eclipse.ui.editors.text.FileDocumentProvider;
|
||||
import org.eclipse.ui.part.FileEditorInput;
|
||||
import org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel;
|
||||
|
||||
public class CDocumentProvider extends FileDocumentProvider {
|
||||
import org.eclipse.ui.editors.text.TextFileDocumentProvider;
|
||||
|
||||
/**
|
||||
* CDocumentProvider2
|
||||
*/
|
||||
public class CDocumentProvider extends TextFileDocumentProvider {
|
||||
/**
|
||||
* Bundle of all required informations to allow working copy management.
|
||||
*/
|
||||
protected class CDocument extends AbstractDocument {
|
||||
static protected class TranslationUnitInfo extends FileInfo {
|
||||
public IWorkingCopy fCopy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new empty document.
|
||||
*/
|
||||
public CDocument() {
|
||||
super();
|
||||
setTextStore(new GapTextStore(50, 300));
|
||||
setLineTracker(new DefaultLineTracker());
|
||||
completeInitialization();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new document with the given initial content.
|
||||
*
|
||||
* @param initialContent the document's initial content
|
||||
*/
|
||||
public CDocument(String initialContent) {
|
||||
super();
|
||||
setTextStore(new GapTextStore(50, 300));
|
||||
setLineTracker(new DefaultLineTracker());
|
||||
getStore().set(initialContent);
|
||||
getTracker().set(initialContent);
|
||||
completeInitialization();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Bundle of all required informations to allow working copy management.
|
||||
*/
|
||||
protected class TranslationUnitFileInfo extends FileInfo {
|
||||
|
||||
IWorkingCopy fCopy;
|
||||
|
||||
TranslationUnitFileInfo(IDocument document, IAnnotationModel model, FileSynchronizer fileSynchronizer, IWorkingCopy copy) {
|
||||
super(document, model, fileSynchronizer);
|
||||
fCopy= copy;
|
||||
}
|
||||
|
||||
void setModificationStamp(long timeStamp) {
|
||||
fModificationStamp= timeStamp;
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Creates <code>IBuffer</code>s based on documents.
|
||||
*/
|
||||
protected class BufferFactory implements IBufferFactory {
|
||||
|
||||
private IDocument internalGetDocument(IFileEditorInput input) throws CoreException {
|
||||
IDocument document= getDocument(input);
|
||||
if (document != null)
|
||||
return document;
|
||||
return CDocumentProvider.this.createDocument(input);
|
||||
}
|
||||
|
||||
public IBuffer createBuffer(IOpenable owner) {
|
||||
if (owner instanceof IWorkingCopy) {
|
||||
|
||||
IWorkingCopy unit= (IWorkingCopy) owner;
|
||||
ITranslationUnit original= (ITranslationUnit) unit.getOriginalElement();
|
||||
IResource resource= original.getResource();
|
||||
if (resource instanceof IFile) {
|
||||
IFileEditorInput providerKey= new FileEditorInput((IFile) resource);
|
||||
|
||||
IDocument document= null;
|
||||
IStatus status= null;
|
||||
|
||||
try {
|
||||
document= internalGetDocument(providerKey);
|
||||
} catch (CoreException x) {
|
||||
status= x.getStatus();
|
||||
document= new Document();
|
||||
initializeDocument(document);
|
||||
}
|
||||
|
||||
DocumentAdapter adapter= new DocumentAdapter(unit, document, new DefaultLineTracker(), CDocumentProvider.this, providerKey);
|
||||
adapter.setStatus(status);
|
||||
return adapter;
|
||||
}
|
||||
|
||||
}
|
||||
return DocumentAdapter.NULL;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/** The buffer factory */
|
||||
private IBufferFactory fBufferFactory= new BufferFactory();
|
||||
/** Indicates whether the save has been initialized by this provider */
|
||||
private boolean fIsAboutToSave= false;
|
||||
private boolean fIsAboutToSave = false;
|
||||
|
||||
/** The save policy used by this provider */
|
||||
//private ISavePolicy fSavePolicy;
|
||||
|
||||
/**
|
||||
* @see AbstractDocumentProvider#createDocument(Object)
|
||||
*
|
||||
*/
|
||||
protected IDocument createDocument(Object element) throws CoreException {
|
||||
IDocument document = null;
|
||||
IStorage storage = null;
|
||||
|
||||
if (element instanceof IEditorInputDelegate) {
|
||||
if (((IEditorInputDelegate) element).getDelegate() != null)
|
||||
return createDocument(((IEditorInputDelegate) element).getDelegate());
|
||||
else
|
||||
storage = ((IEditorInputDelegate) element).getStorage();
|
||||
}
|
||||
|
||||
if (element instanceof IStorageEditorInput)
|
||||
storage= ((IStorageEditorInput) element).getStorage();
|
||||
|
||||
if ( storage != null ) {
|
||||
document = new CDocument();
|
||||
setDocumentContent(document, storage.getContents(), getDefaultEncoding());
|
||||
}
|
||||
|
||||
//IDocument document= super.createDocument(element);
|
||||
initializeDocument(document);
|
||||
return document;
|
||||
public CDocumentProvider() {
|
||||
super();
|
||||
setParentDocumentProvider(new TextFileDocumentProvider(new CStorageDocumentProvider()));
|
||||
}
|
||||
|
||||
/*
|
||||
* @see AbstractDocumentProvider#createAnnotationModel(Object)
|
||||
*/
|
||||
protected IAnnotationModel createAnnotationModel(Object element) throws CoreException {
|
||||
if ( element instanceof IEditorInputDelegate && ((IEditorInputDelegate)element).getDelegate() != null )
|
||||
return createAnnotationModel( ((IEditorInputDelegate)element).getDelegate() );
|
||||
if (element instanceof IFileEditorInput) {
|
||||
IFileEditorInput input= (IFileEditorInput) element;
|
||||
return new CMarkerAnnotationModel(input.getFile());
|
||||
} else if (element instanceof IStorageEditorInput) {
|
||||
// Fall back on the adapter.
|
||||
IStorageEditorInput input = (IStorageEditorInput) element;
|
||||
IResource res = (IResource)input.getAdapter(IResource.class);
|
||||
if (res != null && res.exists()) {
|
||||
return new CMarkerAnnotationModel(res);
|
||||
}
|
||||
}
|
||||
|
||||
return super.createAnnotationModel(element);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see AbstractDocumentProvider#createElementInfo(Object)
|
||||
*/
|
||||
protected ElementInfo createElementInfo(Object element) throws CoreException {
|
||||
if ( !(element instanceof IFileEditorInput))
|
||||
return super.createElementInfo(element);
|
||||
|
||||
IFileEditorInput input= (IFileEditorInput) element;
|
||||
ITranslationUnit original= createTranslationUnit(input.getFile());
|
||||
if (original != null) {
|
||||
|
||||
try {
|
||||
|
||||
try {
|
||||
refreshFile(input.getFile());
|
||||
} catch (CoreException x) {
|
||||
handleCoreException(x, CEditorMessages.getString("TranslationUnitDocumentProvider.error.createElementInfo")); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
IAnnotationModel m= createAnnotationModel(input);
|
||||
IBufferFactory factory = getBufferFactory();
|
||||
IWorkingCopy c= (IWorkingCopy) original.getSharedWorkingCopy(getProgressMonitor(), factory);
|
||||
|
||||
DocumentAdapter a= null;
|
||||
try {
|
||||
a= (DocumentAdapter) c.getBuffer();
|
||||
} catch (ClassCastException x) {
|
||||
IStatus status= new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, CStatusConstants.TEMPLATE_IO_EXCEPTION, "Shared working copy has wrong buffer", x); //$NON-NLS-1$
|
||||
throw new CoreException(status);
|
||||
}
|
||||
|
||||
FileSynchronizer f= new FileSynchronizer(input);
|
||||
f.install();
|
||||
|
||||
TranslationUnitFileInfo info= new TranslationUnitFileInfo(a.getDocument(), m, f, c);
|
||||
info.setModificationStamp(computeModificationStamp(input.getFile()));
|
||||
info.fStatus= a.getStatus();
|
||||
info.fEncoding= getPersistedEncoding(input);
|
||||
|
||||
return info;
|
||||
|
||||
} catch (CModelException x) {
|
||||
throw new CoreException(x.getStatus());
|
||||
}
|
||||
} else {
|
||||
return super.createElementInfo(element);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Creates a translation unit using the core model
|
||||
/**
|
||||
* Creates a translation unit from the given file.
|
||||
*
|
||||
* @param file
|
||||
* the file from which to create the translation unit
|
||||
*/
|
||||
protected ITranslationUnit createTranslationUnit(IFile file) {
|
||||
Object element= CoreModel.getDefault().create(file);
|
||||
if (element instanceof ITranslationUnit)
|
||||
Object element = CoreModel.getDefault().create(file);
|
||||
if (element instanceof ITranslationUnit) {
|
||||
return (ITranslationUnit) element;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see AbstractDocumentProvider#disposeElementInfo(Object, ElementInfo)
|
||||
* @see org.eclipse.ui.editors.text.TextFileDocumentProvider#createEmptyFileInfo()
|
||||
*/
|
||||
protected void disposeElementInfo(Object element, ElementInfo info) {
|
||||
|
||||
if (info instanceof TranslationUnitFileInfo) {
|
||||
TranslationUnitFileInfo cuInfo= (TranslationUnitFileInfo) info;
|
||||
cuInfo.fCopy.destroy();
|
||||
}
|
||||
|
||||
super.disposeElementInfo(element, info);
|
||||
protected FileInfo createEmptyFileInfo() {
|
||||
return new TranslationUnitInfo();
|
||||
}
|
||||
|
||||
/*
|
||||
* @see AbstractDocumentProvider#doSaveDocument(IProgressMonitor, Object, IDocument, boolean)
|
||||
* @see org.eclipse.ui.editors.text.TextFileDocumentProvider#createAnnotationModel(org.eclipse.core.resources.IFile)
|
||||
*/
|
||||
protected void doSaveDocument(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite) throws CoreException {
|
||||
protected IAnnotationModel createAnnotationModel(IFile file) {
|
||||
return new CMarkerAnnotationModel(file);
|
||||
}
|
||||
|
||||
ElementInfo elementInfo= getElementInfo(element);
|
||||
if (elementInfo instanceof TranslationUnitFileInfo) {
|
||||
TranslationUnitFileInfo info= (TranslationUnitFileInfo) elementInfo;
|
||||
/*
|
||||
* @see org.eclipse.ui.editors.text.TextFileDocumentProvider#createFileInfo(java.lang.Object)
|
||||
*/
|
||||
protected FileInfo createFileInfo(Object element) throws CoreException {
|
||||
ITranslationUnit original = null;
|
||||
IWorkingCopy copy = null;
|
||||
if (element instanceof IFileEditorInput) {
|
||||
IFileEditorInput input = (IFileEditorInput)element;
|
||||
original = createTranslationUnit(input.getFile());
|
||||
IBufferFactory factory = CUIPlugin.getDefault().getBufferFactory();
|
||||
copy = (IWorkingCopy) original.getSharedWorkingCopy(getProgressMonitor(), factory);
|
||||
} else if (element instanceof ITranslationUnitEditorInput) {
|
||||
ITranslationUnitEditorInput input = (ITranslationUnitEditorInput)element;
|
||||
copy = new CFileElementWorkingCopy(input.getTranslationUnit());
|
||||
}
|
||||
|
||||
// update structure, assumes lock on info.fCopy
|
||||
info.fCopy.reconcile();
|
||||
if (copy == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ITranslationUnit original= (ITranslationUnit) info.fCopy.getOriginalElement();
|
||||
IResource resource= original.getResource();
|
||||
FileInfo info = super.createFileInfo(element);
|
||||
if (!(info instanceof TranslationUnitInfo))
|
||||
return null;
|
||||
TranslationUnitInfo tuInfo = (TranslationUnitInfo) info;
|
||||
setUpSynchronization(tuInfo);
|
||||
|
||||
if (resource == null) {
|
||||
// underlying resource has been deleted, just recreate file, ignore the rest
|
||||
super.doSaveDocument(monitor, element, document, overwrite);
|
||||
return;
|
||||
//IProblemRequestor requestor= tuInfo.fModel instanceof IProblemRequestor ? (IProblemRequestor) tuInfo.fModel : null;
|
||||
//original.becomeWorkingCopy(requestor, getProgressMonitor());
|
||||
|
||||
tuInfo.fCopy = copy;
|
||||
|
||||
//if (tuInfo.fModel instanceof CMarkerAnnotationModel) {
|
||||
// CMarkerAnnotationModel model= (CMarkerAnnotationModel) tuInfo.fModel;
|
||||
// model.setCompilationUnit(tuInfo.fCopy);
|
||||
//}
|
||||
//if (tuInfo.fModel != null)
|
||||
// tuInfo.fModel.addAnnotationModelListener(fGlobalAnnotationModelListener);
|
||||
//if (requestor instanceof IProblemRequestorExtension) {
|
||||
// IProblemRequestorExtension extension= (IProblemRequestorExtension)requestor;
|
||||
// extension.setIsActive(isHandlingTemporaryProblems());
|
||||
//}
|
||||
return tuInfo;
|
||||
}
|
||||
|
||||
private void setUpSynchronization(TranslationUnitInfo cuInfo) {
|
||||
IDocument document = cuInfo.fTextFileBuffer.getDocument();
|
||||
IAnnotationModel model = cuInfo.fModel;
|
||||
if (document instanceof ISynchronizable && model instanceof ISynchronizable) {
|
||||
Object lock = ((ISynchronizable) document).getLockObject();
|
||||
((ISynchronizable) model).setLockObject(lock);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.ui.editors.text.TextFileDocumentProvider#disposeFileInfo(java.lang.Object,
|
||||
* org.eclipse.ui.editors.text.TextFileDocumentProvider.FileInfo)
|
||||
*/
|
||||
protected void disposeFileInfo(Object element, FileInfo info) {
|
||||
if (info instanceof TranslationUnitInfo) {
|
||||
TranslationUnitInfo tuInfo = (TranslationUnitInfo) info;
|
||||
tuInfo.fCopy.destroy();
|
||||
//if (cuInfo.fModel != null)
|
||||
// cuInfo.fModel.removeAnnotationModelListener(fGlobalAnnotationModelListener);
|
||||
}
|
||||
super.disposeFileInfo(element, info);
|
||||
}
|
||||
|
||||
protected void commitFileBuffer(IProgressMonitor monitor, Object element, FileInfo fileInfo, boolean overwrite)
|
||||
throws CoreException {
|
||||
if (fileInfo instanceof TranslationUnitInfo) {
|
||||
TranslationUnitInfo info = (TranslationUnitInfo)fileInfo;
|
||||
|
||||
synchronized (info.fCopy) {
|
||||
info.fCopy.reconcile();
|
||||
}
|
||||
|
||||
if (resource != null && !overwrite)
|
||||
checkSynchronizationState(info.fModificationStamp, resource);
|
||||
//if (fSavePolicy != null)
|
||||
// fSavePolicy.preSave(info.fCopy);
|
||||
|
||||
// if (fSavePolicy != null)
|
||||
// fSavePolicy.preSave(info.fCopy);
|
||||
|
||||
// inform about the upcoming content change
|
||||
fireElementStateChanging(element);
|
||||
try {
|
||||
fIsAboutToSave= true;
|
||||
// commit working copy
|
||||
info.fCopy.commit(overwrite, monitor);
|
||||
fIsAboutToSave = true;
|
||||
//info.fCopy.commit(overwrite, monitor);
|
||||
super.commitFileBuffer(monitor, info, overwrite);
|
||||
} catch (CoreException x) {
|
||||
// inform about the failure
|
||||
fireElementStateChangeFailed(element);
|
||||
|
@ -297,41 +174,33 @@ public class CDocumentProvider extends FileDocumentProvider {
|
|||
fireElementStateChangeFailed(element);
|
||||
throw x;
|
||||
} finally {
|
||||
fIsAboutToSave= false;
|
||||
fIsAboutToSave = false;
|
||||
}
|
||||
|
||||
// If here, the dirty state of the editor will change to "not dirty".
|
||||
// Thus, the state changing flag will be reset.
|
||||
|
||||
AbstractMarkerAnnotationModel model= (AbstractMarkerAnnotationModel) info.fModel;
|
||||
model.updateMarkers(info.fDocument);
|
||||
|
||||
if (resource != null)
|
||||
info.setModificationStamp(computeModificationStamp(resource));
|
||||
|
||||
// if (fSavePolicy != null) {
|
||||
// ICompilationUnit unit= fSavePolicy.postSave(original);
|
||||
// if (unit != null) {
|
||||
// IResource r= unit.getResource();
|
||||
// IMarker[] markers= r.findMarkers(IMarker.MARKER, true, IResource.DEPTH_ZERO);
|
||||
// if (markers != null && markers.length > 0) {
|
||||
// for (int i= 0; i < markers.length; i++)
|
||||
// model.updateMarker(markers[i], info.fDocument, null);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
} else {
|
||||
super.doSaveDocument(monitor, element, document, overwrite);
|
||||
super.commitFileBuffer(monitor, fileInfo, overwrite);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the BufferFactory.
|
||||
/*
|
||||
* @see org.eclipse.jdt.internal.ui.javaeditor.ICompilationUnitDocumentProvider#getWorkingCopy(java.lang.Object)
|
||||
*/
|
||||
public IBufferFactory getBufferFactory() {
|
||||
return fBufferFactory;
|
||||
public IWorkingCopy getWorkingCopy(Object element) {
|
||||
FileInfo fileInfo = getFileInfo(element);
|
||||
if (fileInfo instanceof TranslationUnitInfo) {
|
||||
TranslationUnitInfo info = (TranslationUnitInfo) fileInfo;
|
||||
return info.fCopy;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.jdt.internal.ui.javaeditor.ICompilationUnitDocumentProvider#shutdown()
|
||||
*/
|
||||
public void shutdown() {
|
||||
//CUIPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(fPropertyListener);
|
||||
Iterator e = getConnectedElementsIterator();
|
||||
while (e.hasNext())
|
||||
disconnect(e.next());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -348,78 +217,21 @@ public class CDocumentProvider extends FileDocumentProvider {
|
|||
return null;
|
||||
}
|
||||
|
||||
public IWorkingCopy getWorkingCopy(IEditorInput element) {
|
||||
|
||||
ElementInfo elementInfo= getElementInfo(element);
|
||||
if (elementInfo instanceof TranslationUnitFileInfo) {
|
||||
TranslationUnitFileInfo info= (TranslationUnitFileInfo) elementInfo;
|
||||
return info.fCopy;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void initializeDocument(IDocument document) {
|
||||
if (document != null) {
|
||||
IDocumentPartitioner partitioner= CUIPlugin.getDefault().getTextTools().createDocumentPartitioner();
|
||||
partitioner.connect(document);
|
||||
document.setDocumentPartitioner(partitioner);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Saves the content of the given document to the given element.
|
||||
* This is only performed when this provider initiated the save.
|
||||
*
|
||||
* @param monitor the progress monitor
|
||||
* @param element the element to which to save
|
||||
* @param document the document to save
|
||||
* @param overwrite <code>true</code> if the save should be enforced
|
||||
/*
|
||||
* @see org.eclipse.jdt.internal.ui.javaeditor.ICompilationUnitDocumentProvider#saveDocumentContent(org.eclipse.core.runtime.IProgressMonitor,
|
||||
* java.lang.Object, org.eclipse.jface.text.IDocument, boolean)
|
||||
*/
|
||||
public void saveDocumentContent(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite) throws CoreException {
|
||||
|
||||
public void saveDocumentContent(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite)
|
||||
throws CoreException {
|
||||
if (!fIsAboutToSave)
|
||||
return;
|
||||
|
||||
if (element instanceof IFileEditorInput) {
|
||||
IFileEditorInput input= (IFileEditorInput) element;
|
||||
try {
|
||||
String encoding= getEncoding(element);
|
||||
if (encoding == null)
|
||||
encoding= ResourcesPlugin.getEncoding();
|
||||
InputStream stream= new ByteArrayInputStream(document.get().getBytes(encoding));
|
||||
IFile file= input.getFile();
|
||||
file.setContents(stream, overwrite, true, monitor);
|
||||
} catch (IOException x) {
|
||||
IStatus s= new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, IStatus.OK, x.getMessage(), x);
|
||||
throw new CoreException(s);
|
||||
}
|
||||
}
|
||||
super.saveDocument(monitor, element, document, overwrite);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
/*
|
||||
* @see org.eclipse.jdt.internal.ui.javaeditor.ICompilationUnitDocumentProvider#createLineTracker(java.lang.Object)
|
||||
*/
|
||||
public void shutdown() {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
/**
|
||||
* @param input
|
||||
* @return
|
||||
*/
|
||||
public boolean isConnected(IEditorInput input) {
|
||||
return getElementInfo(input) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.ui.texteditor.IDocumentProviderExtension#getStatus(Object)
|
||||
*/
|
||||
public IStatus getStatus(Object element) {
|
||||
if (element instanceof IEditorInputDelegate) {
|
||||
if (((IEditorInputDelegate) element).getDelegate() != null)
|
||||
return super.getStatus(((IEditorInputDelegate) element).getDelegate());
|
||||
else
|
||||
return new Status(IStatus.INFO,CUIPlugin.getPluginId(),0,"",null); //$NON-NLS-1$
|
||||
}
|
||||
return super.getStatus(element);
|
||||
public ILineTracker createLineTracker(Object element) {
|
||||
return new DefaultLineTracker();
|
||||
}
|
||||
}
|
|
@ -73,13 +73,11 @@ import org.eclipse.ui.IEditorActionBarContributor;
|
|||
import org.eclipse.ui.IEditorInput;
|
||||
import org.eclipse.ui.IFileEditorInput;
|
||||
import org.eclipse.ui.IPartService;
|
||||
import org.eclipse.ui.IStorageEditorInput;
|
||||
import org.eclipse.ui.IViewPart;
|
||||
import org.eclipse.ui.IWorkbenchPage;
|
||||
import org.eclipse.ui.IWorkbenchWindow;
|
||||
import org.eclipse.ui.actions.ActionGroup;
|
||||
import org.eclipse.ui.editors.text.TextEditor;
|
||||
import org.eclipse.ui.editors.text.TextFileDocumentProvider;
|
||||
import org.eclipse.ui.part.EditorActionBarContributor;
|
||||
import org.eclipse.ui.part.IShowInSource;
|
||||
import org.eclipse.ui.part.ShowInContext;
|
||||
|
@ -185,11 +183,6 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS
|
|||
* @see AbstractTextEditor#doSetInput(IEditorInput)
|
||||
*/
|
||||
protected void doSetInput(IEditorInput input) throws CoreException {
|
||||
// If the file is not a Storage or an IFile use a different
|
||||
// DocumentProvider. TODO: Rewrite CDocuemtnProviver to handle this.
|
||||
if (!(input instanceof IStorageEditorInput || input instanceof IFileEditorInput)) {
|
||||
setDocumentProvider(new TextFileDocumentProvider(null));
|
||||
}
|
||||
super.doSetInput(input);
|
||||
fCEditorErrorTickUpdater.setAnnotationModel(getDocumentProvider().getAnnotationModel(input));
|
||||
setOutlinePageInput(fOutlinePage, input);
|
||||
|
@ -227,6 +220,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS
|
|||
fOutlinePage = new CContentOutlinePage(this);
|
||||
fOutlinePage.addSelectionChangedListener(this);
|
||||
}
|
||||
setOutlinePageInput(fOutlinePage, getEditorInput());
|
||||
return fOutlinePage;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002,2003,2004 QNX Software Systems 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:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
***********************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.editor;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.text.CTextTools;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.ui.editors.text.StorageDocumentProvider;
|
||||
|
||||
/**
|
||||
* CStorageDocumentProvider
|
||||
*/
|
||||
public class CStorageDocumentProvider extends StorageDocumentProvider {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public CStorageDocumentProvider() {
|
||||
super();
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.ui.editors.text.StorageDocumentProvider#setupDocument(java.lang.Object, org.eclipse.jface.text.IDocument)
|
||||
*/
|
||||
protected void setupDocument(Object element, IDocument document) {
|
||||
if (document != null) {
|
||||
CTextTools tools= CUIPlugin.getDefault().getTextTools();
|
||||
tools.setupCDocument(document);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002,2003,2004 QNX Software Systems 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:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
***********************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.editor;
|
||||
|
||||
import org.eclipse.cdt.core.model.IBuffer;
|
||||
import org.eclipse.cdt.core.model.IOpenable;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||
import org.eclipse.cdt.internal.core.model.IBufferFactory;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
|
||||
/**
|
||||
* CustomBufferFactory
|
||||
*/
|
||||
public class CustomBufferFactory implements IBufferFactory {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public CustomBufferFactory() {
|
||||
super();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.model.IBufferFactory#createBuffer(org.eclipse.cdt.core.model.IOpenable)
|
||||
*/
|
||||
public IBuffer createBuffer(IOpenable owner) {
|
||||
if (owner instanceof IWorkingCopy) {
|
||||
|
||||
IWorkingCopy unit= (IWorkingCopy) owner;
|
||||
ITranslationUnit original= (ITranslationUnit) unit.getOriginalElement();
|
||||
IResource resource= original.getResource();
|
||||
if (resource instanceof IFile) {
|
||||
IFile fFile = (IFile)resource;
|
||||
DocumentAdapter adapter= new DocumentAdapter(owner, fFile);
|
||||
return adapter;
|
||||
}
|
||||
|
||||
}
|
||||
return DocumentAdapter.NULL;
|
||||
}
|
||||
}
|
|
@ -13,24 +13,32 @@ package org.eclipse.cdt.internal.ui.editor;
|
|||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.cdt.core.model.BufferChangedEvent;
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.IBuffer;
|
||||
import org.eclipse.cdt.core.model.IBufferChangedListener;
|
||||
import org.eclipse.cdt.core.model.IOpenable;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.core.filebuffers.FileBuffers;
|
||||
import org.eclipse.core.filebuffers.ITextFileBuffer;
|
||||
import org.eclipse.core.filebuffers.ITextFileBufferManager;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.jface.text.BadLocationException;
|
||||
import org.eclipse.jface.text.DefaultLineTracker;
|
||||
import org.eclipse.jface.text.DocumentEvent;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.jface.text.IDocumentListener;
|
||||
import org.eclipse.jface.text.ILineTracker;
|
||||
import org.eclipse.jface.text.IRegion;
|
||||
import org.eclipse.jface.util.Assert;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
|
||||
|
@ -114,14 +122,7 @@ public class DocumentAdapter implements IBuffer, IDocumentListener {
|
|||
|
||||
/** NULL implementing <code>IBuffer</code> */
|
||||
public final static IBuffer NULL= new NullBuffer();
|
||||
/*
|
||||
* @see IBuffer#addBufferChangedListener(IBufferChangedListener)
|
||||
*/
|
||||
public void addBufferChangedListener(IBufferChangedListener listener) {
|
||||
Assert.isNotNull(listener);
|
||||
if (!fBufferListeners.contains(listener))
|
||||
fBufferListeners.add(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a document set content call in the ui thread.
|
||||
*/
|
||||
|
@ -163,47 +164,52 @@ public class DocumentAdapter implements IBuffer, IDocumentListener {
|
|||
}
|
||||
};
|
||||
|
||||
private static final boolean DEBUG_LINE_DELIMITERS= true;
|
||||
|
||||
private IOpenable fOwner;
|
||||
IDocument fDocument;
|
||||
private IFile fFile;
|
||||
private ITextFileBuffer fTextFileBuffer;
|
||||
private IDocument fDocument;
|
||||
|
||||
private DocumentSetCommand fSetCmd= new DocumentSetCommand();
|
||||
private DocumentReplaceCommand fReplaceCmd= new DocumentReplaceCommand();
|
||||
|
||||
private Object fProviderKey;
|
||||
private CDocumentProvider fProvider;
|
||||
private String fLineDelimiter;
|
||||
private ILineTracker fLineTracker;
|
||||
private Set fLegalLineDelimiters;
|
||||
|
||||
private List fBufferListeners= new ArrayList(3);
|
||||
|
||||
private IStatus fStatus;
|
||||
|
||||
|
||||
public DocumentAdapter(IOpenable owner, IDocument document, ILineTracker lineTracker, CDocumentProvider provider, Object providerKey) {
|
||||
public DocumentAdapter(IOpenable owner, IFile file) {
|
||||
fOwner= owner;
|
||||
fFile= file;
|
||||
|
||||
Assert.isNotNull(document);
|
||||
Assert.isNotNull(lineTracker);
|
||||
|
||||
fOwner= owner;
|
||||
fDocument= document;
|
||||
fLineTracker= lineTracker;
|
||||
fProvider= provider;
|
||||
fProviderKey= providerKey;
|
||||
|
||||
fDocument.addPrenotifiedDocumentListener(this);
|
||||
initialize();
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();
|
||||
IPath location= fFile.getFullPath();
|
||||
try {
|
||||
manager.connect(location, new NullProgressMonitor());
|
||||
fTextFileBuffer= manager.getTextFileBuffer(location);
|
||||
fDocument= fTextFileBuffer.getDocument();
|
||||
} catch (CoreException x) {
|
||||
fStatus= x.getStatus();
|
||||
fDocument= manager.createEmptyDocument(location);
|
||||
}
|
||||
/**
|
||||
* Sets the status of this document adapter.
|
||||
*/
|
||||
public void setStatus(IStatus status) {
|
||||
fStatus= status;
|
||||
fDocument.addPrenotifiedDocumentListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the status of this document adapter.
|
||||
*/
|
||||
public IStatus getStatus() {
|
||||
return fStatus;
|
||||
if (fStatus != null)
|
||||
return fStatus;
|
||||
if (fTextFileBuffer != null)
|
||||
return fTextFileBuffer.getStatus();
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -214,78 +220,25 @@ public class DocumentAdapter implements IBuffer, IDocumentListener {
|
|||
public IDocument getDocument() {
|
||||
return fDocument;
|
||||
}
|
||||
/**
|
||||
* Returns the line delimiter of this buffer. As a document has a set of
|
||||
* valid line delimiters, this set must be reduced to size 1.
|
||||
|
||||
/*
|
||||
* @see IBuffer#addBufferChangedListener(IBufferChangedListener)
|
||||
*/
|
||||
protected String getLineDelimiter() {
|
||||
|
||||
if (fLineDelimiter == null) {
|
||||
|
||||
try {
|
||||
fLineDelimiter= fDocument.getLineDelimiter(0);
|
||||
} catch (BadLocationException x) {
|
||||
}
|
||||
|
||||
if (fLineDelimiter == null) {
|
||||
/*
|
||||
* Follow up fix for: 1GF5UU0: ITPJUI:WIN2000 - "Organize Imports" in java editor inserts lines in wrong format
|
||||
* The line delimiter must always be a legal document line delimiter.
|
||||
*/
|
||||
String sysLineDelimiter= System.getProperty("line.separator"); //$NON-NLS-1$
|
||||
String[] delimiters= fDocument.getLegalLineDelimiters();
|
||||
Assert.isTrue(delimiters.length > 0);
|
||||
for (int i= 0; i < delimiters.length; i++) {
|
||||
if (delimiters[i].equals(sysLineDelimiter)) {
|
||||
fLineDelimiter= sysLineDelimiter;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (fLineDelimiter == null) {
|
||||
// system line delimiter is not a legal document line delimiter
|
||||
fLineDelimiter= delimiters[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return fLineDelimiter;
|
||||
public void addBufferChangedListener(IBufferChangedListener listener) {
|
||||
Assert.isNotNull(listener);
|
||||
if (!fBufferListeners.contains(listener))
|
||||
fBufferListeners.add(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given string to the line delimiter of this buffer.
|
||||
* This method is <code>public</code> for test purposes only.
|
||||
/*
|
||||
* @see IBuffer#removeBufferChangedListener(IBufferChangedListener)
|
||||
*/
|
||||
public String normalize(String text) {
|
||||
fLineTracker.set(text);
|
||||
|
||||
int lines= fLineTracker.getNumberOfLines();
|
||||
if (lines <= 1)
|
||||
return text;
|
||||
|
||||
StringBuffer buffer= new StringBuffer(text);
|
||||
|
||||
try {
|
||||
IRegion previous= fLineTracker.getLineInformation(0);
|
||||
for (int i= 1; i < lines; i++) {
|
||||
int lastLineEnd= previous.getOffset() + previous.getLength();
|
||||
int lineStart= fLineTracker.getLineInformation(i).getOffset();
|
||||
fLineTracker.replace(lastLineEnd, lineStart - lastLineEnd, getLineDelimiter());
|
||||
buffer.replace(lastLineEnd, lineStart, getLineDelimiter());
|
||||
previous= fLineTracker.getLineInformation(i);
|
||||
}
|
||||
|
||||
// last line
|
||||
String delimiter= fLineTracker.getLineDelimiter(lines -1);
|
||||
if (delimiter != null && delimiter.length() > 0)
|
||||
buffer.replace(previous.getOffset() + previous.getLength(), buffer.length(), getLineDelimiter());
|
||||
|
||||
return buffer.toString();
|
||||
} catch (BadLocationException x) {
|
||||
}
|
||||
|
||||
return text;
|
||||
public void removeBufferChangedListener(IBufferChangedListener listener) {
|
||||
Assert.isNotNull(listener);
|
||||
fBufferListeners.remove(listener);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.internal.core.model.IBuffer#append(char)
|
||||
*/
|
||||
|
@ -297,7 +250,10 @@ public class DocumentAdapter implements IBuffer, IDocumentListener {
|
|||
* @see org.eclipse.cdt.internal.core.model.IBuffer#append(java.lang.String)
|
||||
*/
|
||||
public void append(String text) {
|
||||
fReplaceCmd.replace(fDocument.getLength(), 0, normalize(text));
|
||||
if (DEBUG_LINE_DELIMITERS) {
|
||||
validateLineDelimiters(text);
|
||||
}
|
||||
fReplaceCmd.replace(fDocument.getLength(), 0, text);
|
||||
}
|
||||
|
||||
|
||||
|
@ -305,6 +261,7 @@ public class DocumentAdapter implements IBuffer, IDocumentListener {
|
|||
* @see org.eclipse.cdt.internal.core.model.IBuffer#close()
|
||||
*/
|
||||
public void close() {
|
||||
|
||||
if (isClosed())
|
||||
return;
|
||||
|
||||
|
@ -312,6 +269,16 @@ public class DocumentAdapter implements IBuffer, IDocumentListener {
|
|||
fDocument= null;
|
||||
d.removePrenotifiedDocumentListener(this);
|
||||
|
||||
if (fTextFileBuffer != null) {
|
||||
ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();
|
||||
try {
|
||||
manager.disconnect(fTextFileBuffer.getLocation(), new NullProgressMonitor());
|
||||
} catch (CoreException x) {
|
||||
// ignore
|
||||
}
|
||||
fTextFileBuffer= null;
|
||||
}
|
||||
|
||||
fireBufferChanged(new BufferChangedEvent(this, 0, 0, null));
|
||||
fBufferListeners.clear();
|
||||
}
|
||||
|
@ -371,16 +338,14 @@ public class DocumentAdapter implements IBuffer, IDocumentListener {
|
|||
* @see org.eclipse.cdt.internal.core.model.IBuffer#getUnderlyingResource()
|
||||
*/
|
||||
public IResource getUnderlyingResource() {
|
||||
//return null;
|
||||
return fProvider != null ? fProvider.getUnderlyingResource(fProviderKey) : null;
|
||||
return fFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.internal.core.model.IBuffer#hasUnsavedChanges()
|
||||
*/
|
||||
public boolean hasUnsavedChanges() {
|
||||
//return false;
|
||||
return fProvider != null ? fProvider.canSaveDocument(fProviderKey) : false;
|
||||
return fTextFileBuffer != null ? fTextFileBuffer.isDirty() : false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -394,18 +359,10 @@ public class DocumentAdapter implements IBuffer, IDocumentListener {
|
|||
* @see org.eclipse.cdt.internal.core.model.IBuffer#isReadOnly()
|
||||
*/
|
||||
public boolean isReadOnly() {
|
||||
//return false;
|
||||
IResource resource= getUnderlyingResource();
|
||||
return resource == null ? true : resource.isReadOnly();
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IBuffer#removeBufferChangedListener(IBufferChangedListener)
|
||||
*/
|
||||
public void removeBufferChangedListener(IBufferChangedListener listener) {
|
||||
Assert.isNotNull(listener);
|
||||
fBufferListeners.remove(listener);
|
||||
}
|
||||
/**
|
||||
* @see org.eclipse.cdt.internal.core.model.IBuffer#replace(int, int, char)
|
||||
*/
|
||||
|
@ -417,20 +374,22 @@ public class DocumentAdapter implements IBuffer, IDocumentListener {
|
|||
* @see org.eclipse.cdt.internal.core.model.IBuffer#replace(int, int, java.lang.String)
|
||||
*/
|
||||
public void replace(int position, int length, String text) {
|
||||
fReplaceCmd.replace(position, length, normalize(text));
|
||||
if (DEBUG_LINE_DELIMITERS) {
|
||||
validateLineDelimiters(text);
|
||||
}
|
||||
fReplaceCmd.replace(position, length, text);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.internal.core.model.IBuffer#save(org.eclipse.core.runtime.IProgressMonitor, boolean)
|
||||
*/
|
||||
public void save(IProgressMonitor progress, boolean force) throws CModelException {
|
||||
if (fProvider != null) {
|
||||
try {
|
||||
fProvider.saveDocumentContent(progress, fProviderKey, fDocument, force);
|
||||
} catch (CoreException e) {
|
||||
throw new CModelException(e);
|
||||
}
|
||||
}
|
||||
try {
|
||||
if (fTextFileBuffer != null)
|
||||
fTextFileBuffer.commit(progress, force);
|
||||
} catch (CoreException e) {
|
||||
throw new CModelException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -452,15 +411,64 @@ public class DocumentAdapter implements IBuffer, IDocumentListener {
|
|||
fSetCmd.set(""); //$NON-NLS-1$
|
||||
|
||||
} else {
|
||||
|
||||
// set only if different
|
||||
String newContents= normalize(contents);
|
||||
int newLength= newContents.length();
|
||||
if (DEBUG_LINE_DELIMITERS) {
|
||||
validateLineDelimiters(contents);
|
||||
}
|
||||
|
||||
int newLength= contents.length();
|
||||
if (oldLength != newLength || !contents.equals(fDocument.get()))
|
||||
fSetCmd.set(contents);
|
||||
|
||||
if (oldLength != newLength || !newContents.equals(fDocument.get()))
|
||||
fSetCmd.set(newContents);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateLineDelimiters(String contents) {
|
||||
|
||||
if (fLegalLineDelimiters == null) {
|
||||
// collect all line delimiters in the document
|
||||
HashSet existingDelimiters= new HashSet();
|
||||
|
||||
for (int i= fDocument.getNumberOfLines() - 1; i >= 0; i-- ) {
|
||||
try {
|
||||
String curr= fDocument.getLineDelimiter(i);
|
||||
if (curr != null) {
|
||||
existingDelimiters.add(curr);
|
||||
}
|
||||
} catch (BadLocationException e) {
|
||||
CUIPlugin.getDefault().log(e);
|
||||
}
|
||||
}
|
||||
if (existingDelimiters.isEmpty()) {
|
||||
return; // first insertion of a line delimiter: no test
|
||||
}
|
||||
fLegalLineDelimiters= existingDelimiters;
|
||||
|
||||
}
|
||||
|
||||
DefaultLineTracker tracker= new DefaultLineTracker();
|
||||
tracker.set(contents);
|
||||
|
||||
int lines= tracker.getNumberOfLines();
|
||||
if (lines <= 1)
|
||||
return;
|
||||
|
||||
for (int i= 0; i < lines; i++) {
|
||||
try {
|
||||
String curr= tracker.getLineDelimiter(i);
|
||||
if (curr != null && !fLegalLineDelimiters.contains(curr)) {
|
||||
StringBuffer buf= new StringBuffer("New line delimiter added to new code: "); //$NON-NLS-1$
|
||||
for (int k= 0; k < curr.length(); k++) {
|
||||
buf.append(String.valueOf((int) curr.charAt(k)));
|
||||
}
|
||||
CUIPlugin.getDefault().log(new Exception(buf.toString()));
|
||||
}
|
||||
} catch (BadLocationException e) {
|
||||
CUIPlugin.getDefault().log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IDocumentListener#documentAboutToBeChanged(DocumentEvent)
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002,2003,2004 QNX Software Systems 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:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
***********************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.editor;
|
||||
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.ui.IStorageEditorInput;
|
||||
import org.eclipse.ui.editors.text.ILocationProvider;
|
||||
|
||||
/**
|
||||
* ITranslationUnitEditorInput
|
||||
*/
|
||||
public interface ITranslationUnitEditorInput extends IStorageEditorInput, ILocationProvider {
|
||||
|
||||
ITranslationUnit getTranslationUnit();
|
||||
|
||||
}
|
|
@ -11,10 +11,12 @@ import java.util.List;
|
|||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfoProvider;
|
||||
import org.eclipse.cdt.core.resources.FileStorage;
|
||||
import org.eclipse.cdt.internal.ui.CPluginImages;
|
||||
import org.eclipse.cdt.internal.ui.dialogs.ElementListSelectionDialog;
|
||||
import org.eclipse.cdt.internal.ui.util.EditorUtility;
|
||||
|
@ -107,8 +109,11 @@ public class OpenIncludeAction extends Action {
|
|||
if (file != null) {
|
||||
EditorUtility.openInEditor(file);
|
||||
} else {
|
||||
FileStorage storage = new FileStorage(null, fileToOpen);
|
||||
EditorUtility.openInEditor(storage);
|
||||
ICProject cproject = include.getCProject();
|
||||
ITranslationUnit unit = CoreModel.getDefault().createTranslationUnitFrom(cproject, fileToOpen);
|
||||
if (unit != null) {
|
||||
EditorUtility.openInEditor(unit);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (CModelException e) {
|
||||
|
@ -160,7 +165,7 @@ public class OpenIncludeAction extends Action {
|
|||
}
|
||||
};
|
||||
|
||||
ElementListSelectionDialog dialog= new ElementListSelectionDialog(CUIPlugin.getDefault().getActiveWorkbenchShell(), renderer, false, false);
|
||||
ElementListSelectionDialog dialog= new ElementListSelectionDialog(CUIPlugin.getActiveWorkbenchShell(), renderer, false, false);
|
||||
dialog.setTitle(CUIPlugin.getResourceString(DIALOG_TITLE));
|
||||
dialog.setMessage(CUIPlugin.getResourceString(DIALOG_MESSAGE));
|
||||
dialog.setElements(filesFound);
|
||||
|
|
|
@ -88,7 +88,7 @@ public class WorkingCopyManager implements IWorkingCopyManager, IWorkingCopyMana
|
|||
* @see org.eclipse.cdt.internal.ui.editor.IWorkingCopyManagerExtension#setWorkingCopy(org.eclipse.ui.IEditorInput, org.eclipse.cdt.core.model.ITranslationUnit)
|
||||
*/
|
||||
public void setWorkingCopy(IEditorInput input, IWorkingCopy workingCopy) {
|
||||
if (fDocumentProvider.isConnected(input)) {
|
||||
if (fDocumentProvider.getDocument(input) != null) {
|
||||
if (fMap == null)
|
||||
fMap= new HashMap();
|
||||
fMap.put(input, workingCopy);
|
||||
|
|
|
@ -11,6 +11,8 @@ import org.eclipse.cdt.ui.CUIPlugin;
|
|||
import org.eclipse.core.runtime.Preferences;
|
||||
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.jface.text.IDocumentExtension3;
|
||||
import org.eclipse.jface.text.IDocumentPartitioner;
|
||||
import org.eclipse.jface.text.rules.DefaultPartitioner;
|
||||
import org.eclipse.jface.text.rules.IPartitionTokenScanner;
|
||||
|
@ -237,4 +239,33 @@ public class CTextTools {
|
|||
if (fStringScanner.affectsBehavior(event))
|
||||
fStringScanner.adaptToPreferenceChange(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the document partitioner for the given document for the given partitioning.
|
||||
*
|
||||
* @param document the document to be set up
|
||||
* @param partitioning the document partitioning
|
||||
* @since 3.0
|
||||
*/
|
||||
public void setupCDocumentPartitioner(IDocument document, String partitioning) {
|
||||
IDocumentPartitioner partitioner= createDocumentPartitioner();
|
||||
if (document instanceof IDocumentExtension3) {
|
||||
IDocumentExtension3 extension3= (IDocumentExtension3) document;
|
||||
extension3.setDocumentPartitioner(partitioning, partitioner);
|
||||
} else {
|
||||
document.setDocumentPartitioner(partitioner);
|
||||
}
|
||||
partitioner.connect(document);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the given document for the default partitioning.
|
||||
*
|
||||
* @param document the document to be set up
|
||||
* @since 3.0
|
||||
*/
|
||||
public void setupCDocument(IDocument document) {
|
||||
setupCDocumentPartitioner(document, IDocumentExtension3.DEFAULT_PARTITIONING);
|
||||
}
|
||||
|
||||
}
|
|
@ -158,7 +158,7 @@ public class EditorUtility {
|
|||
if (resource instanceof IFile) {
|
||||
return new FileEditorInput((IFile) resource);
|
||||
} else {
|
||||
return new ExternalEditorInput(getStorage(unit));
|
||||
return new ExternalEditorInput(unit, getStorage(unit));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -220,7 +220,7 @@ public class EditorUtility {
|
|||
if (cu.isWorkingCopy())
|
||||
return cu;
|
||||
|
||||
return (ITranslationUnit)cu.findSharedWorkingCopy(CUIPlugin.getBufferFactory());
|
||||
return (ITranslationUnit)cu.findSharedWorkingCopy(CUIPlugin.getDefault().getBufferFactory());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ public class ExceptionHandler {
|
|||
* @param message message to be displayed by the dialog window
|
||||
*/
|
||||
public static void handle(CoreException e, String title, String message) {
|
||||
handle(e, CUIPlugin.getDefault().getActiveWorkbenchShell(), title, message);
|
||||
handle(e, CUIPlugin.getActiveWorkbenchShell(), title, message);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -79,7 +79,7 @@ public class ExceptionHandler {
|
|||
* @param message message to be displayed by the dialog window
|
||||
*/
|
||||
public static void handle(InvocationTargetException e, String title, String message) {
|
||||
handle(e, CUIPlugin.getDefault().getActiveWorkbenchShell(), title, message);
|
||||
handle(e, CUIPlugin.getActiveWorkbenchShell(), title, message);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,20 +7,25 @@ package org.eclipse.cdt.internal.ui.util;
|
|||
|
||||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.internal.ui.editor.ITranslationUnitEditorInput;
|
||||
import org.eclipse.core.resources.IStorage;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
|
||||
import org.eclipse.ui.IEditorRegistry;
|
||||
import org.eclipse.ui.IPersistableElement;
|
||||
import org.eclipse.ui.IStorageEditorInput;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.editors.text.ILocationProvider;
|
||||
|
||||
|
||||
/**
|
||||
* An EditorInput for a JarEntryFile.
|
||||
*/
|
||||
public class ExternalEditorInput implements IStorageEditorInput {
|
||||
public class ExternalEditorInput implements ITranslationUnitEditorInput {
|
||||
|
||||
IStorage externalFile;
|
||||
private IStorage externalFile;
|
||||
private ITranslationUnit unit;
|
||||
|
||||
/*
|
||||
*/
|
||||
|
@ -45,7 +50,9 @@ public class ExternalEditorInput implements IStorageEditorInput {
|
|||
* @see IAdaptable#getAdapter(Class)
|
||||
*/
|
||||
public Object getAdapter(Class adapter) {
|
||||
return null;
|
||||
if (ILocationProvider.class.equals(adapter))
|
||||
return this;
|
||||
return Platform.getAdapterManager().getAdapter(this, adapter);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -101,4 +108,23 @@ public class ExternalEditorInput implements IStorageEditorInput {
|
|||
public ExternalEditorInput(IStorage exFile) {
|
||||
externalFile = exFile;
|
||||
}
|
||||
|
||||
public ExternalEditorInput(ITranslationUnit unit, IStorage exFile) {
|
||||
this(exFile);
|
||||
this.unit = unit;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.ui.editor.ITranslationUnitEditorInput#getTranslationUnit()
|
||||
*/
|
||||
public ITranslationUnit getTranslationUnit() {
|
||||
return unit;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.ui.editors.text.ILocationProvider#getPath(java.lang.Object)
|
||||
*/
|
||||
public IPath getPath(Object element) {
|
||||
return externalFile.getFullPath();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ import org.eclipse.cdt.internal.ui.ResourceAdapterFactory;
|
|||
import org.eclipse.cdt.internal.ui.buildconsole.BuildConsoleManager;
|
||||
import org.eclipse.cdt.internal.ui.cview.CView;
|
||||
import org.eclipse.cdt.internal.ui.editor.CDocumentProvider;
|
||||
import org.eclipse.cdt.internal.ui.editor.CustomBufferFactory;
|
||||
import org.eclipse.cdt.internal.ui.editor.SharedTextColors;
|
||||
import org.eclipse.cdt.internal.ui.editor.WorkingCopyManager;
|
||||
import org.eclipse.cdt.internal.ui.editor.asm.AsmTextTools;
|
||||
|
@ -110,15 +111,14 @@ public class CUIPlugin extends AbstractUIPlugin {
|
|||
}
|
||||
}
|
||||
|
||||
public static IBufferFactory getBufferFactory() {
|
||||
CDocumentProvider provider= CUIPlugin.getDefault().getDocumentProvider();
|
||||
if (provider != null)
|
||||
return provider.getBufferFactory();
|
||||
return null;
|
||||
public synchronized IBufferFactory getBufferFactory() {
|
||||
if (fBufferFactory == null)
|
||||
fBufferFactory= new CustomBufferFactory();
|
||||
return fBufferFactory;
|
||||
}
|
||||
|
||||
public static IWorkingCopy[] getSharedWorkingCopies() {
|
||||
return CCorePlugin.getSharedWorkingCopies(getBufferFactory());
|
||||
return CCorePlugin.getSharedWorkingCopies(getDefault().getBufferFactory());
|
||||
}
|
||||
|
||||
public static String getResourceString(String key) {
|
||||
|
@ -217,6 +217,7 @@ public class CUIPlugin extends AbstractUIPlugin {
|
|||
|
||||
private CoreModel fCoreModel;
|
||||
private CDocumentProvider fDocumentProvider;
|
||||
private IBufferFactory fBufferFactory;
|
||||
private WorkingCopyManager fWorkingCopyManager;
|
||||
private CTextTools fTextTools;
|
||||
private AsmTextTools fAsmTextTools;
|
||||
|
|
|
@ -587,7 +587,7 @@ public class NewClassWizardPage extends WizardPage implements Listener {
|
|||
|
||||
if(parentHeaderTU != null){
|
||||
String header = constructHeaderFileContent(parentHeaderTU, lineDelimiter);
|
||||
IWorkingCopy headerWC = parentHeaderTU.getSharedWorkingCopy(null, CUIPlugin.getDefault().getDocumentProvider().getBufferFactory());
|
||||
IWorkingCopy headerWC = parentHeaderTU.getSharedWorkingCopy(null, CUIPlugin.getDefault().getBufferFactory());
|
||||
headerWC.getBuffer().append(header);
|
||||
synchronized(headerWC) {
|
||||
headerWC.reconcile();
|
||||
|
@ -599,7 +599,7 @@ public class NewClassWizardPage extends WizardPage implements Listener {
|
|||
}
|
||||
if(parentBodyTU != null){
|
||||
String body = constructBodyFileContent(lineDelimiter);
|
||||
IWorkingCopy bodyWC = parentBodyTU.getSharedWorkingCopy(null, CUIPlugin.getDefault().getDocumentProvider().getBufferFactory());
|
||||
IWorkingCopy bodyWC = parentBodyTU.getSharedWorkingCopy(null, CUIPlugin.getDefault().getBufferFactory());
|
||||
bodyWC.getBuffer().append(body);
|
||||
synchronized(bodyWC){
|
||||
bodyWC.reconcile();
|
||||
|
|
Loading…
Add table
Reference in a new issue