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 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.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.PlatformObject;
|
||||
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.ide.IDE;
|
||||
import org.eclipse.ui.ide.ResourceUtil;
|
||||
import org.eclipse.ui.part.FileEditorInput;
|
||||
import org.eclipse.ui.texteditor.AbstractTextEditor;
|
||||
|
||||
import org.eclipse.cdt.core.IBinaryParser;
|
||||
|
@ -44,26 +50,25 @@ import org.eclipse.cdt.utils.Objdump;
|
|||
import org.eclipse.cdt.internal.ui.util.EditorUtility;
|
||||
|
||||
/**
|
||||
* A readonly editor to view binary files. This default implementation displays
|
||||
* the GNU objdump output of the binary as plain text. If no objdump output can be
|
||||
* obtained, the binary content is displayed.
|
||||
* A readonly editor to view binary files. This default implementation displays the GNU objdump output of the
|
||||
* binary as plain text. If no objdump output can be 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.
|
||||
*/
|
||||
public static class BinaryFileEditorInput extends PlatformObject implements IStorageEditorInput {
|
||||
|
||||
private final IBinary fBinary;
|
||||
private IStorage fStorage;
|
||||
|
||||
/**
|
||||
* Create an editor input from the given binary.
|
||||
*
|
||||
* @param binary
|
||||
*/
|
||||
public BinaryFileEditorInput(IBinary binary) {
|
||||
fBinary= binary;
|
||||
fBinary = binary;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -79,8 +84,8 @@ public class DefaultBinaryFileEditor extends AbstractTextEditor {
|
|||
*/
|
||||
@Override
|
||||
public ImageDescriptor getImageDescriptor() {
|
||||
IFile file= (IFile)fBinary.getResource();
|
||||
IContentType contentType= IDE.getContentType(file);
|
||||
IFile file = (IFile) fBinary.getResource();
|
||||
IContentType contentType = IDE.getContentType(file);
|
||||
return PlatformUI.getWorkbench().getEditorRegistry()
|
||||
.getImageDescriptor(file.getName(), contentType);
|
||||
}
|
||||
|
@ -115,9 +120,11 @@ public class DefaultBinaryFileEditor extends AbstractTextEditor {
|
|||
@Override
|
||||
public IStorage getStorage() throws CoreException {
|
||||
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) {
|
||||
IGnuToolFactory factory= (IGnuToolFactory) object.getBinaryParser().getAdapter(IGnuToolFactory.class);
|
||||
IGnuToolFactory factory = (IGnuToolFactory) object.getBinaryParser().getAdapter(
|
||||
IGnuToolFactory.class);
|
||||
if (factory != null) {
|
||||
Objdump objdump = factory.getObjdump(object.getPath());
|
||||
if (objdump != null) {
|
||||
|
@ -143,16 +150,15 @@ public class DefaultBinaryFileEditor extends AbstractTextEditor {
|
|||
}
|
||||
if (fStorage == null) {
|
||||
// backwards compatibility
|
||||
fStorage= EditorUtility.getStorage(fBinary);
|
||||
fStorage = EditorUtility.getStorage(fBinary);
|
||||
if (fStorage == null) {
|
||||
// fall back to binary content
|
||||
fStorage= (IFile)fBinary.getResource();
|
||||
fStorage = (IFile) fBinary.getResource();
|
||||
}
|
||||
}
|
||||
}
|
||||
return fStorage;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -165,15 +171,24 @@ public class DefaultBinaryFileEditor extends AbstractTextEditor {
|
|||
*/
|
||||
@Override
|
||||
protected IDocument createDocument(Object element) throws CoreException {
|
||||
IFile file= ResourceUtil.getFile(element);
|
||||
IFile file = ResourceUtil.getFile(element);
|
||||
if (file != null) {
|
||||
ICElement cElement= CoreModel.getDefault().create(file);
|
||||
ICElement cElement = CoreModel.getDefault().create(file);
|
||||
if (cElement instanceof IBinary) {
|
||||
element= new BinaryFileEditorInput((IBinary)cElement);
|
||||
element = new BinaryFileEditorInput((IBinary) cElement);
|
||||
}
|
||||
}
|
||||
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)
|
||||
*/
|
||||
|
@ -181,6 +196,7 @@ public class DefaultBinaryFileEditor extends AbstractTextEditor {
|
|||
public boolean isModifiable(Object element) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.ui.editors.text.StorageDocumentProvider#isReadOnly(java.lang.Object)
|
||||
*/
|
||||
|
@ -194,16 +210,56 @@ public class DefaultBinaryFileEditor extends AbstractTextEditor {
|
|||
public DefaultBinaryFileEditor() {
|
||||
super();
|
||||
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
|
||||
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);
|
||||
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