mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-09 10:46:02 +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,22 +50,21 @@ 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) {
|
||||||
|
@ -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) {
|
||||||
|
@ -152,7 +159,6 @@ public class DefaultBinaryFileEditor extends AbstractTextEditor {
|
||||||
}
|
}
|
||||||
return fStorage;
|
return fStorage;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -174,6 +180,15 @@ public class DefaultBinaryFileEditor extends AbstractTextEditor {
|
||||||
}
|
}
|
||||||
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)
|
||||||
*/
|
*/
|
||||||
|
@ -194,10 +210,13 @@ public class DefaultBinaryFileEditor extends AbstractTextEditor {
|
||||||
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) {
|
||||||
|
@ -206,4 +225,41 @@ public class DefaultBinaryFileEditor extends AbstractTextEditor {
|
||||||
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