mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-21 07:55:24 +02:00
Accommodate archive files in Default Binary File Editor
This commit is contained in:
parent
0a8734fb12
commit
d4c444eaeb
4 changed files with 31 additions and 22 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2000, 2011 QNX Software Systems and others.
|
* Copyright (c) 2000, 2023 QNX Software Systems and others.
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials
|
* This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License 2.0
|
* are made available under the terms of the Eclipse Public License 2.0
|
||||||
|
@ -11,6 +11,7 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX Software Systems - Initial API and implementation
|
* QNX Software Systems - Initial API and implementation
|
||||||
* Anton Leherbauer (Wind River Systems)
|
* Anton Leherbauer (Wind River Systems)
|
||||||
|
* John Dallaway - Adapt for IBinaryFile (#413)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.model;
|
package org.eclipse.cdt.internal.core.model;
|
||||||
|
|
||||||
|
@ -88,7 +89,7 @@ public class Archive extends Openable implements IArchive {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> T getAdapter(Class<T> adapter) {
|
public <T> T getAdapter(Class<T> adapter) {
|
||||||
if (IBinaryArchive.class.equals(adapter)) {
|
if (adapter.isAssignableFrom(IBinaryArchive.class)) {
|
||||||
return adapter.cast(getBinaryArchive());
|
return adapter.cast(getBinaryArchive());
|
||||||
}
|
}
|
||||||
return super.getAdapter(adapter);
|
return super.getAdapter(adapter);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2000, 2016 QNX Software Systems and others.
|
* Copyright (c) 2000, 2023 QNX Software Systems and others.
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials
|
* This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License 2.0
|
* are made available under the terms of the Eclipse Public License 2.0
|
||||||
|
@ -12,6 +12,7 @@
|
||||||
* QNX Software Systems - Initial API and implementation
|
* QNX Software Systems - Initial API and implementation
|
||||||
* Markus Schorn (Wind River Systems)
|
* Markus Schorn (Wind River Systems)
|
||||||
* Anton Leherbauer (Wind River Systems)
|
* Anton Leherbauer (Wind River Systems)
|
||||||
|
* John Dallaway - Adapt for IBinaryFile (#413)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.model;
|
package org.eclipse.cdt.internal.core.model;
|
||||||
|
|
||||||
|
@ -214,7 +215,7 @@ public class Binary extends Openable implements IBinary {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> T getAdapter(Class<T> adapter) {
|
public <T> T getAdapter(Class<T> adapter) {
|
||||||
if (IBinaryObject.class.equals(adapter)) {
|
if (adapter.isAssignableFrom(IBinaryObject.class)) {
|
||||||
return adapter.cast(getBinaryObject());
|
return adapter.cast(getBinaryObject());
|
||||||
}
|
}
|
||||||
return super.getAdapter(adapter);
|
return super.getAdapter(adapter);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2007, 2015 Wind River Systems, Inc. and others.
|
* Copyright (c) 2007, 2023 Wind River Systems, Inc. and others.
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials
|
* This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License 2.0
|
* are made available under the terms of the Eclipse Public License 2.0
|
||||||
|
@ -10,6 +10,7 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Anton Leherbauer (Wind River Systems) - initial API and implementation
|
* Anton Leherbauer (Wind River Systems) - initial API and implementation
|
||||||
|
* John Dallaway - support both IArchive and IBinary as input (#413)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.ui.editor;
|
package org.eclipse.cdt.internal.ui.editor;
|
||||||
|
@ -19,6 +20,7 @@ import java.io.IOException;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.IBinaryParser;
|
import org.eclipse.cdt.core.IBinaryParser;
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
|
import org.eclipse.cdt.core.model.IArchive;
|
||||||
import org.eclipse.cdt.core.model.IBinary;
|
import org.eclipse.cdt.core.model.IBinary;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
import org.eclipse.cdt.core.resources.FileStorage;
|
import org.eclipse.cdt.core.resources.FileStorage;
|
||||||
|
@ -60,7 +62,7 @@ public class DefaultBinaryFileEditor extends AbstractTextEditor implements IReso
|
||||||
* 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 ICElement fBinary;
|
||||||
private IStorage fStorage;
|
private IStorage fStorage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -68,7 +70,7 @@ public class DefaultBinaryFileEditor extends AbstractTextEditor implements IReso
|
||||||
*
|
*
|
||||||
* @param binary
|
* @param binary
|
||||||
*/
|
*/
|
||||||
public BinaryFileEditorInput(IBinary binary) {
|
public BinaryFileEditorInput(ICElement binary) {
|
||||||
fBinary = binary;
|
fBinary = binary;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,11 +122,11 @@ public class DefaultBinaryFileEditor extends AbstractTextEditor implements IReso
|
||||||
@Override
|
@Override
|
||||||
public IStorage getStorage() throws CoreException {
|
public IStorage getStorage() throws CoreException {
|
||||||
if (fStorage == null) {
|
if (fStorage == null) {
|
||||||
IBinaryParser.IBinaryObject object = fBinary.getAdapter(IBinaryParser.IBinaryObject.class);
|
IBinaryParser.IBinaryFile file = fBinary.getAdapter(IBinaryParser.IBinaryFile.class);
|
||||||
if (object != null) {
|
if (file != null) {
|
||||||
IGnuToolFactory factory = object.getBinaryParser().getAdapter(IGnuToolFactory.class);
|
IGnuToolFactory factory = file.getBinaryParser().getAdapter(IGnuToolFactory.class);
|
||||||
if (factory != null) {
|
if (factory != null) {
|
||||||
Objdump objdump = factory.getObjdump(object.getPath());
|
Objdump objdump = factory.getObjdump(file.getPath());
|
||||||
if (objdump != null) {
|
if (objdump != null) {
|
||||||
try {
|
try {
|
||||||
// limit editor to X MB, if more - users should use objdump in command
|
// limit editor to X MB, if more - users should use objdump in command
|
||||||
|
@ -139,7 +141,7 @@ public class DefaultBinaryFileEditor extends AbstractTextEditor implements IReso
|
||||||
System.arraycopy(message.getBytes(), 0, output, limitBytes - message.length(),
|
System.arraycopy(message.getBytes(), 0, output, limitBytes - message.length(),
|
||||||
message.length());
|
message.length());
|
||||||
}
|
}
|
||||||
fStorage = new FileStorage(new ByteArrayInputStream(output), object.getPath());
|
fStorage = new FileStorage(new ByteArrayInputStream(output), file.getPath());
|
||||||
} catch (IOException exc) {
|
} catch (IOException exc) {
|
||||||
CUIPlugin.log(exc);
|
CUIPlugin.log(exc);
|
||||||
}
|
}
|
||||||
|
@ -172,8 +174,8 @@ public class DefaultBinaryFileEditor extends AbstractTextEditor implements IReso
|
||||||
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 IArchive || cElement instanceof IBinary) {
|
||||||
element = new BinaryFileEditorInput((IBinary) cElement);
|
element = new BinaryFileEditorInput(cElement);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return super.createDocument(element);
|
return super.createDocument(element);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2000, 2020 QNX Software Systems and others.
|
* Copyright (c) 2000, 2023 QNX Software Systems and others.
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials
|
* This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License 2.0
|
* are made available under the terms of the Eclipse Public License 2.0
|
||||||
|
@ -15,6 +15,7 @@
|
||||||
* Anton Leherbauer (Wind River Systems)
|
* Anton Leherbauer (Wind River Systems)
|
||||||
* Ed Swartz (Nokia)
|
* Ed Swartz (Nokia)
|
||||||
* Alexander Fedorov (ArSysOp) - Bug 561993 - Remove dependency to com.ibm.icu from CDT UI
|
* Alexander Fedorov (ArSysOp) - Bug 561993 - Remove dependency to com.ibm.icu from CDT UI
|
||||||
|
* John Dallaway - Support both IArchive and IBinary storage requests (#413)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.util;
|
package org.eclipse.cdt.internal.ui.util;
|
||||||
|
|
||||||
|
@ -36,6 +37,7 @@ import org.eclipse.cdt.core.model.IBuffer;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
import org.eclipse.cdt.core.model.ICProject;
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
import org.eclipse.cdt.core.model.IIncludeReference;
|
import org.eclipse.cdt.core.model.IIncludeReference;
|
||||||
|
import org.eclipse.cdt.core.model.IOpenable;
|
||||||
import org.eclipse.cdt.core.model.ISourceRange;
|
import org.eclipse.cdt.core.model.ISourceRange;
|
||||||
import org.eclipse.cdt.core.model.ISourceReference;
|
import org.eclipse.cdt.core.model.ISourceReference;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
|
@ -751,15 +753,18 @@ public class EditorUtility {
|
||||||
new String[] { modifierString, newModifierString });
|
new String[] { modifierString, newModifierString });
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IStorage getStorage(IBinary bin) {
|
public static IStorage getStorage(ICElement element) {
|
||||||
IStorage store = null;
|
IStorage store = null;
|
||||||
try {
|
if (element instanceof IOpenable openable) {
|
||||||
IBuffer buffer = bin.getBuffer();
|
try {
|
||||||
if (buffer != null) {
|
IBuffer buffer = openable.getBuffer();
|
||||||
store = new FileStorage(new ByteArrayInputStream(buffer.getContents().getBytes()), bin.getPath());
|
if (buffer != null) {
|
||||||
|
store = new FileStorage(new ByteArrayInputStream(buffer.getContents().getBytes()),
|
||||||
|
element.getPath());
|
||||||
|
}
|
||||||
|
} catch (CModelException e) {
|
||||||
|
// nothing;
|
||||||
}
|
}
|
||||||
} catch (CModelException e) {
|
|
||||||
// nothing;
|
|
||||||
}
|
}
|
||||||
return store;
|
return store;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue