mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
Bug 242405 - Binary file editor does not refresh when binary is rebuilt
Change-Id: I0af100959f8f61b2d2735f9d0d9cd42b6c91e590 Signed-off-by: Alena Laskavaia <elaskavaia.cdt@gmail.com> Reviewed-on: https://git.eclipse.org/r/31300 Tested-by: Hudson CI
This commit is contained in:
parent
1bf2aa825f
commit
b7ec8deec4
1 changed files with 76 additions and 20 deletions
|
@ -15,7 +15,12 @@ import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
|
import org.eclipse.core.resources.IResourceChangeEvent;
|
||||||
|
import org.eclipse.core.resources.IResourceChangeListener;
|
||||||
|
import org.eclipse.core.resources.IResourceDelta;
|
||||||
|
import org.eclipse.core.resources.IResourceDeltaVisitor;
|
||||||
import org.eclipse.core.resources.IStorage;
|
import org.eclipse.core.resources.IStorage;
|
||||||
|
import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.PlatformObject;
|
import org.eclipse.core.runtime.PlatformObject;
|
||||||
import org.eclipse.core.runtime.content.IContentType;
|
import org.eclipse.core.runtime.content.IContentType;
|
||||||
|
@ -30,6 +35,7 @@ import org.eclipse.ui.PlatformUI;
|
||||||
import org.eclipse.ui.editors.text.StorageDocumentProvider;
|
import org.eclipse.ui.editors.text.StorageDocumentProvider;
|
||||||
import org.eclipse.ui.ide.IDE;
|
import org.eclipse.ui.ide.IDE;
|
||||||
import org.eclipse.ui.ide.ResourceUtil;
|
import org.eclipse.ui.ide.ResourceUtil;
|
||||||
|
import org.eclipse.ui.part.FileEditorInput;
|
||||||
import org.eclipse.ui.texteditor.AbstractTextEditor;
|
import org.eclipse.ui.texteditor.AbstractTextEditor;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.IBinaryParser;
|
import org.eclipse.cdt.core.IBinaryParser;
|
||||||
|
@ -44,26 +50,25 @@ import org.eclipse.cdt.utils.Objdump;
|
||||||
import org.eclipse.cdt.internal.ui.util.EditorUtility;
|
import org.eclipse.cdt.internal.ui.util.EditorUtility;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A readonly editor to view binary files. This default implementation displays
|
* A readonly editor to view binary files. This default implementation displays the GNU objdump output of the
|
||||||
* the GNU objdump output of the binary as plain text. If no objdump output can be
|
* binary as plain text. If no objdump output can be obtained, the binary content is displayed.
|
||||||
* obtained, the binary content is displayed.
|
|
||||||
*/
|
*/
|
||||||
public class DefaultBinaryFileEditor extends AbstractTextEditor {
|
public class DefaultBinaryFileEditor extends AbstractTextEditor implements IResourceChangeListener {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A storage editor input for binary files.
|
* A storage editor input for binary files.
|
||||||
*/
|
*/
|
||||||
public static class BinaryFileEditorInput extends PlatformObject implements IStorageEditorInput {
|
public static class BinaryFileEditorInput extends PlatformObject implements IStorageEditorInput {
|
||||||
|
|
||||||
private final IBinary fBinary;
|
private final IBinary fBinary;
|
||||||
private IStorage fStorage;
|
private IStorage fStorage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an editor input from the given binary.
|
* Create an editor input from the given binary.
|
||||||
|
*
|
||||||
* @param binary
|
* @param binary
|
||||||
*/
|
*/
|
||||||
public BinaryFileEditorInput(IBinary binary) {
|
public BinaryFileEditorInput(IBinary binary) {
|
||||||
fBinary= binary;
|
fBinary = binary;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -79,8 +84,8 @@ public class DefaultBinaryFileEditor extends AbstractTextEditor {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ImageDescriptor getImageDescriptor() {
|
public ImageDescriptor getImageDescriptor() {
|
||||||
IFile file= (IFile)fBinary.getResource();
|
IFile file = (IFile) fBinary.getResource();
|
||||||
IContentType contentType= IDE.getContentType(file);
|
IContentType contentType = IDE.getContentType(file);
|
||||||
return PlatformUI.getWorkbench().getEditorRegistry()
|
return PlatformUI.getWorkbench().getEditorRegistry()
|
||||||
.getImageDescriptor(file.getName(), contentType);
|
.getImageDescriptor(file.getName(), contentType);
|
||||||
}
|
}
|
||||||
|
@ -115,9 +120,11 @@ public class DefaultBinaryFileEditor extends AbstractTextEditor {
|
||||||
@Override
|
@Override
|
||||||
public IStorage getStorage() throws CoreException {
|
public IStorage getStorage() throws CoreException {
|
||||||
if (fStorage == null) {
|
if (fStorage == null) {
|
||||||
IBinaryParser.IBinaryObject object= (IBinaryParser.IBinaryObject)fBinary.getAdapter(IBinaryParser.IBinaryObject.class);
|
IBinaryParser.IBinaryObject object = (IBinaryParser.IBinaryObject) fBinary
|
||||||
|
.getAdapter(IBinaryParser.IBinaryObject.class);
|
||||||
if (object != null) {
|
if (object != null) {
|
||||||
IGnuToolFactory factory= (IGnuToolFactory) object.getBinaryParser().getAdapter(IGnuToolFactory.class);
|
IGnuToolFactory factory = (IGnuToolFactory) object.getBinaryParser().getAdapter(
|
||||||
|
IGnuToolFactory.class);
|
||||||
if (factory != null) {
|
if (factory != null) {
|
||||||
Objdump objdump = factory.getObjdump(object.getPath());
|
Objdump objdump = factory.getObjdump(object.getPath());
|
||||||
if (objdump != null) {
|
if (objdump != null) {
|
||||||
|
@ -143,37 +150,45 @@ public class DefaultBinaryFileEditor extends AbstractTextEditor {
|
||||||
}
|
}
|
||||||
if (fStorage == null) {
|
if (fStorage == null) {
|
||||||
// backwards compatibility
|
// backwards compatibility
|
||||||
fStorage= EditorUtility.getStorage(fBinary);
|
fStorage = EditorUtility.getStorage(fBinary);
|
||||||
if (fStorage == null) {
|
if (fStorage == null) {
|
||||||
// fall back to binary content
|
// fall back to binary content
|
||||||
fStorage= (IFile)fBinary.getResource();
|
fStorage = (IFile) fBinary.getResource();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return fStorage;
|
return fStorage;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A storage document provider for binary files.
|
* A storage document provider for binary files.
|
||||||
*/
|
*/
|
||||||
public static class BinaryFileDocumentProvider extends StorageDocumentProvider {
|
public static class BinaryFileDocumentProvider extends StorageDocumentProvider {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @see org.eclipse.ui.editors.text.StorageDocumentProvider#createDocument(java.lang.Object)
|
* @see org.eclipse.ui.editors.text.StorageDocumentProvider#createDocument(java.lang.Object)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected IDocument createDocument(Object element) throws CoreException {
|
protected IDocument createDocument(Object element) throws CoreException {
|
||||||
IFile file= ResourceUtil.getFile(element);
|
IFile file = ResourceUtil.getFile(element);
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
ICElement cElement= CoreModel.getDefault().create(file);
|
ICElement cElement = CoreModel.getDefault().create(file);
|
||||||
if (cElement instanceof IBinary) {
|
if (cElement instanceof IBinary) {
|
||||||
element= new BinaryFileEditorInput((IBinary)cElement);
|
element = new BinaryFileEditorInput((IBinary) cElement);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return super.createDocument(element);
|
return super.createDocument(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getModificationStamp(Object element) {
|
||||||
|
if (element instanceof FileEditorInput) {
|
||||||
|
return ((FileEditorInput) element).getFile().getModificationStamp();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @see org.eclipse.ui.editors.text.StorageDocumentProvider#isModifiable(java.lang.Object)
|
* @see org.eclipse.ui.editors.text.StorageDocumentProvider#isModifiable(java.lang.Object)
|
||||||
*/
|
*/
|
||||||
|
@ -181,6 +196,7 @@ public class DefaultBinaryFileEditor extends AbstractTextEditor {
|
||||||
public boolean isModifiable(Object element) {
|
public boolean isModifiable(Object element) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @see org.eclipse.ui.editors.text.StorageDocumentProvider#isReadOnly(java.lang.Object)
|
* @see org.eclipse.ui.editors.text.StorageDocumentProvider#isReadOnly(java.lang.Object)
|
||||||
*/
|
*/
|
||||||
|
@ -188,22 +204,62 @@ public class DefaultBinaryFileEditor extends AbstractTextEditor {
|
||||||
public boolean isReadOnly(Object element) {
|
public boolean isReadOnly(Object element) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public DefaultBinaryFileEditor() {
|
public DefaultBinaryFileEditor() {
|
||||||
super();
|
super();
|
||||||
setDocumentProvider(new BinaryFileDocumentProvider());
|
setDocumentProvider(new BinaryFileDocumentProvider());
|
||||||
|
ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#createSourceViewer(org.eclipse.swt.widgets.Composite, org.eclipse.jface.text.source.IVerticalRuler, int)
|
* @see
|
||||||
|
* org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#createSourceViewer(org.eclipse.swt.widgets.Composite
|
||||||
|
* , org.eclipse.jface.text.source.IVerticalRuler, int)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int styles) {
|
protected ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int styles) {
|
||||||
ISourceViewer sourceViewer= super.createSourceViewer(parent, ruler, styles);
|
ISourceViewer sourceViewer = super.createSourceViewer(parent, ruler, styles);
|
||||||
sourceViewer.setEditable(false);
|
sourceViewer.setEditable(false);
|
||||||
return sourceViewer;
|
return sourceViewer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dispose() {
|
||||||
|
ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resourceChanged(final IResourceChangeEvent event) {
|
||||||
|
try {
|
||||||
|
if (event.getType() == IResourceChangeEvent.POST_CHANGE) {
|
||||||
|
event.getDelta().accept(new IResourceDeltaVisitor() {
|
||||||
|
@Override
|
||||||
|
public boolean visit(IResourceDelta delta) {
|
||||||
|
if (delta.getResource().getName().equals(getEditorInput().getName())) {
|
||||||
|
refresh();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (CoreException e) {
|
||||||
|
CUIPlugin.log(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void refresh() {
|
||||||
|
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
doSetInput(getEditorInput());
|
||||||
|
} catch (CoreException e) {
|
||||||
|
CUIPlugin.log(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue