mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 09:46:02 +02:00
Fix for 227463: Syntax coloring error on insertion/deletion
This commit is contained in:
parent
390aa48830
commit
835e96be68
5 changed files with 105 additions and 59 deletions
|
@ -72,6 +72,7 @@ import org.eclipse.cdt.ui.PreferenceConstants;
|
|||
import org.eclipse.cdt.ui.text.ICPartitions;
|
||||
|
||||
import org.eclipse.cdt.internal.core.model.IBufferFactory;
|
||||
import org.eclipse.cdt.internal.core.model.TranslationUnit;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.text.IProblemRequestorExtension;
|
||||
import org.eclipse.cdt.internal.ui.text.spelling.CoreSpellingProblem;
|
||||
|
@ -787,12 +788,10 @@ public class CDocumentProvider extends TextFileDocumentProvider {
|
|||
}
|
||||
if (element == null) {
|
||||
// not in a source folder?
|
||||
final IPath location= file.getLocation();
|
||||
if (location != null) {
|
||||
ICProject cproject= CoreModel.getDefault().create(file.getProject());
|
||||
if (cproject != null) {
|
||||
return CoreModel.getDefault().createTranslationUnitFrom(cproject, location);
|
||||
}
|
||||
ICProject cproject= CoreModel.getDefault().create(file.getProject());
|
||||
if (cproject != null) {
|
||||
String contentTypeId= CoreModel.getRegistedContentTypeId(file.getProject(), file.getName());
|
||||
return new TranslationUnit(cproject, file, contentTypeId);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -195,7 +195,6 @@ import org.eclipse.cdt.internal.ui.actions.GoToNextPreviousMemberAction;
|
|||
import org.eclipse.cdt.internal.ui.actions.GotoNextBookmarkAction;
|
||||
import org.eclipse.cdt.internal.ui.actions.IndentAction;
|
||||
import org.eclipse.cdt.internal.ui.actions.RemoveBlockCommentAction;
|
||||
import org.eclipse.cdt.internal.ui.actions.SelectionConverter;
|
||||
import org.eclipse.cdt.internal.ui.dnd.TextEditorDropAdapter;
|
||||
import org.eclipse.cdt.internal.ui.dnd.TextViewerDragAdapter;
|
||||
import org.eclipse.cdt.internal.ui.search.OccurrencesFinder;
|
||||
|
@ -1405,12 +1404,9 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
|
|||
}
|
||||
else if (required == IShowInSource.class) {
|
||||
ICElement ce= null;
|
||||
try {
|
||||
ce= SelectionConverter.getElementAtOffset(this);
|
||||
if (ce instanceof ITranslationUnit) {
|
||||
ce = null;
|
||||
}
|
||||
} catch (CModelException ex) {
|
||||
ce= getElementAt(getSourceViewer().getSelectedRange().x, false);
|
||||
if (ce instanceof ITranslationUnit) {
|
||||
ce = null;
|
||||
}
|
||||
final ISelection selection= ce != null ? new StructuredSelection(ce) : null;
|
||||
return new IShowInSource() {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2002, 2007 QNX Software Systems and others.
|
||||
* Copyright (c) 2002, 2008 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -12,14 +12,18 @@
|
|||
|
||||
package org.eclipse.cdt.internal.ui.editor;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
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.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.ui.CUIPlugin;
|
||||
|
||||
import org.eclipse.cdt.internal.core.model.IBufferFactory;
|
||||
|
||||
|
@ -55,6 +59,16 @@ public class CustomBufferFactory implements IBufferFactory {
|
|||
return new DocumentAdapter(owner, location);
|
||||
}
|
||||
|
||||
// URI
|
||||
URI locationUri= original.getLocationURI();
|
||||
if (locationUri != null) {
|
||||
try {
|
||||
return new DocumentAdapter(owner, locationUri);
|
||||
} catch (CoreException exc) {
|
||||
CUIPlugin.log(exc);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return DocumentAdapter.NULL;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2002, 2007 IBM Corporation and others.
|
||||
* Copyright (c) 2002, 2008 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -12,25 +12,23 @@
|
|||
package org.eclipse.cdt.internal.ui.editor;
|
||||
|
||||
|
||||
import java.net.URI;
|
||||
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.filebuffers.LocationKind;
|
||||
import org.eclipse.core.filesystem.EFS;
|
||||
import org.eclipse.core.filesystem.IFileStore;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.ResourceAttributes;
|
||||
import org.eclipse.core.runtime.Assert;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
|
@ -42,9 +40,15 @@ import org.eclipse.jface.text.DocumentEvent;
|
|||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.jface.text.IDocumentListener;
|
||||
import org.eclipse.jface.text.ISynchronizable;
|
||||
import org.eclipse.core.runtime.Assert;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
|
||||
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;
|
||||
|
||||
|
||||
/**
|
||||
* Adapts <code>IDocument</code> to <code>IBuffer</code>. Uses the
|
||||
|
@ -186,6 +190,8 @@ public class DocumentAdapter implements IBuffer, IDocumentListener {
|
|||
final private IPath fLocation;
|
||||
final private LocationKind fLocationKind;
|
||||
|
||||
private IFileStore fFileStore;
|
||||
|
||||
|
||||
public DocumentAdapter(IOpenable owner, IFile file) {
|
||||
fOwner= owner;
|
||||
|
@ -204,17 +210,35 @@ public class DocumentAdapter implements IBuffer, IDocumentListener {
|
|||
initialize();
|
||||
}
|
||||
|
||||
public DocumentAdapter(IOpenable owner, URI locationUri) throws CoreException {
|
||||
fOwner= owner;
|
||||
fFileStore= EFS.getStore(locationUri);
|
||||
|
||||
fLocation= null;
|
||||
fLocationKind= null;
|
||||
|
||||
initialize();
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();
|
||||
try {
|
||||
manager.connect(fLocation, fLocationKind, new NullProgressMonitor());
|
||||
fTextFileBuffer= manager.getTextFileBuffer(fLocation, fLocationKind);
|
||||
if (fLocation != null) {
|
||||
manager.connect(fLocation, fLocationKind, new NullProgressMonitor());
|
||||
fTextFileBuffer= manager.getTextFileBuffer(fLocation, fLocationKind);
|
||||
} else {
|
||||
manager.connectFileStore(fFileStore, new NullProgressMonitor());
|
||||
fTextFileBuffer= manager.getFileStoreTextFileBuffer(fFileStore);
|
||||
}
|
||||
fDocument= fTextFileBuffer.getDocument();
|
||||
} catch (CoreException x) {
|
||||
fStatus= x.getStatus();
|
||||
fDocument= manager.createEmptyDocument(fLocation, fLocationKind);
|
||||
if (fDocument instanceof ISynchronizable)
|
||||
if (fLocation != null) {
|
||||
fDocument= manager.createEmptyDocument(fLocation, fLocationKind);
|
||||
}
|
||||
if (fDocument instanceof ISynchronizable) {
|
||||
((ISynchronizable)fDocument).setLockObject(new Object());
|
||||
}
|
||||
}
|
||||
fDocument.addPrenotifiedDocumentListener(this);
|
||||
}
|
||||
|
@ -290,7 +314,11 @@ public class DocumentAdapter implements IBuffer, IDocumentListener {
|
|||
if (fTextFileBuffer != null) {
|
||||
ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();
|
||||
try {
|
||||
manager.disconnect(fLocation, fLocationKind, new NullProgressMonitor());
|
||||
if (fLocation != null) {
|
||||
manager.disconnect(fLocation, fLocationKind, new NullProgressMonitor());
|
||||
} else {
|
||||
manager.disconnectFileStore(fFileStore, new NullProgressMonitor());
|
||||
}
|
||||
} catch (CoreException x) {
|
||||
// ignore
|
||||
}
|
||||
|
|
|
@ -57,14 +57,23 @@ public class CNavigatorLinkHelper implements ILinkHelper {
|
|||
*/
|
||||
public IStructuredSelection findSelection(IEditorInput input) {
|
||||
IWorkingCopyManager mgr= CUIPlugin.getDefault().getWorkingCopyManager();
|
||||
ICElement element= mgr.getWorkingCopy(input);
|
||||
Object element= mgr.getWorkingCopy(input);
|
||||
if (element == null) {
|
||||
IFile file = ResourceUtil.getFile(input);
|
||||
if (file != null && CoreModel.hasCNature(file.getProject())) {
|
||||
element= CoreModel.getDefault().create(file);
|
||||
}
|
||||
} else {
|
||||
element= ((IWorkingCopy) element).getOriginalElement();
|
||||
ITranslationUnit tUnit= ((IWorkingCopy) element).getOriginalElement();
|
||||
IFile file= (IFile) tUnit.getResource();
|
||||
if (file != null) {
|
||||
element= CoreModel.getDefault().create(file);
|
||||
if (element == null) {
|
||||
element= file;
|
||||
}
|
||||
} else {
|
||||
element= tUnit;
|
||||
}
|
||||
}
|
||||
return (element != null) ? new StructuredSelection(element) : StructuredSelection.EMPTY;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue