mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-09 02:36:01 +02:00
Fix for 115984: Elf editor ExternalEditorInput too limited
This commit is contained in:
parent
fbe4e146c8
commit
1933dd95cd
5 changed files with 247 additions and 38 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2000, 2006 QNX Software Systems and others.
|
* Copyright (c) 2000, 2007 QNX Software Systems and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -7,6 +7,7 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX Software Systems - Initial API and implementation
|
* QNX Software Systems - Initial API and implementation
|
||||||
|
* Anton Leherbauer (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.utils.coff.parser;
|
package org.eclipse.cdt.utils.coff.parser;
|
||||||
|
|
||||||
|
@ -81,13 +82,12 @@ public class CygwinPEParser extends PEParser {
|
||||||
* @see org.eclipse.core.runtime.PlatformObject#getAdapter(java.lang.Class)
|
* @see org.eclipse.core.runtime.PlatformObject#getAdapter(java.lang.Class)
|
||||||
*/
|
*/
|
||||||
public Object getAdapter(Class adapter) {
|
public Object getAdapter(Class adapter) {
|
||||||
if (adapter.equals(ICygwinToolsFactroy.class)) {
|
if (adapter.isAssignableFrom(ICygwinToolsFactroy.class)) {
|
||||||
if (toolFactory == null) {
|
if (toolFactory == null) {
|
||||||
toolFactory = createToolFactory();
|
toolFactory = createToolFactory();
|
||||||
}
|
}
|
||||||
return toolFactory;
|
return toolFactory;
|
||||||
}
|
}
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return super.getAdapter(adapter);
|
return super.getAdapter(adapter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,7 +142,7 @@ ColoringPreferencePage.name=Syntax Coloring
|
||||||
FoldingPreferencePage.name=Folding
|
FoldingPreferencePage.name=Folding
|
||||||
HoverPreferencePage.name=Hovers
|
HoverPreferencePage.name=Hovers
|
||||||
|
|
||||||
Editors.DefaultTextEditor = Default Text Editor
|
DefaultBinaryFileEditor.name = Default Binary File Editor
|
||||||
AsmEditor.name = Assembly Editor
|
AsmEditor.name = Assembly Editor
|
||||||
|
|
||||||
# Task Action
|
# Task Action
|
||||||
|
|
|
@ -551,6 +551,16 @@
|
||||||
icon="icons/obj16/c_file_obj.gif"
|
icon="icons/obj16/c_file_obj.gif"
|
||||||
name="%ExternalSearchEditor.name"
|
name="%ExternalSearchEditor.name"
|
||||||
id="org.eclipse.cdt.ui.editor.ExternalSearchEditor"/>
|
id="org.eclipse.cdt.ui.editor.ExternalSearchEditor"/>
|
||||||
|
<editor
|
||||||
|
class="org.eclipse.cdt.internal.ui.editor.DefaultBinaryFileEditor"
|
||||||
|
default="false"
|
||||||
|
icon="icons/obj16/bin_obj.gif"
|
||||||
|
id="org.eclipse.cdt.ui.binaryEditor"
|
||||||
|
name="%DefaultBinaryFileEditor.name">
|
||||||
|
<contentTypeBinding
|
||||||
|
contentTypeId="org.eclipse.cdt.core.binaryFile">
|
||||||
|
</contentTypeBinding>
|
||||||
|
</editor>
|
||||||
|
|
||||||
</extension>
|
</extension>
|
||||||
<extension
|
<extension
|
||||||
|
|
|
@ -0,0 +1,181 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2007 Wind River Systems, Inc. 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
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Anton Leherbauer (Wind River Systems) - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
package org.eclipse.cdt.internal.ui.editor;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.eclipse.core.resources.IFile;
|
||||||
|
import org.eclipse.core.resources.IStorage;
|
||||||
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
import org.eclipse.core.runtime.PlatformObject;
|
||||||
|
import org.eclipse.core.runtime.content.IContentType;
|
||||||
|
import org.eclipse.jface.resource.ImageDescriptor;
|
||||||
|
import org.eclipse.jface.text.IDocument;
|
||||||
|
import org.eclipse.jface.text.source.ISourceViewer;
|
||||||
|
import org.eclipse.jface.text.source.IVerticalRuler;
|
||||||
|
import org.eclipse.swt.widgets.Composite;
|
||||||
|
import org.eclipse.ui.IPersistableElement;
|
||||||
|
import org.eclipse.ui.IStorageEditorInput;
|
||||||
|
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.texteditor.AbstractTextEditor;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.IBinaryParser;
|
||||||
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
|
import org.eclipse.cdt.core.model.IBinary;
|
||||||
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
|
import org.eclipse.cdt.core.resources.FileStorage;
|
||||||
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
|
import org.eclipse.cdt.utils.IGnuToolFactory;
|
||||||
|
import org.eclipse.cdt.utils.Objdump;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An (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 {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.eclipse.ui.IEditorInput#exists()
|
||||||
|
*/
|
||||||
|
public boolean exists() {
|
||||||
|
return fBinary.exists();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.eclipse.ui.IEditorInput#getImageDescriptor()
|
||||||
|
*/
|
||||||
|
public ImageDescriptor getImageDescriptor() {
|
||||||
|
IFile file= (IFile)fBinary.getResource();
|
||||||
|
IContentType contentType= IDE.getContentType(file);
|
||||||
|
return PlatformUI.getWorkbench().getEditorRegistry()
|
||||||
|
.getImageDescriptor(file.getName(), contentType);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.eclipse.ui.IEditorInput#getName()
|
||||||
|
*/
|
||||||
|
public String getName() {
|
||||||
|
return fBinary.getElementName();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.eclipse.ui.IEditorInput#getPersistable()
|
||||||
|
*/
|
||||||
|
public IPersistableElement getPersistable() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.eclipse.ui.IEditorInput#getToolTipText()
|
||||||
|
*/
|
||||||
|
public String getToolTipText() {
|
||||||
|
return fBinary.getResource().getFullPath().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.eclipse.ui.IStorageEditorInput#getStorage()
|
||||||
|
*/
|
||||||
|
public IStorage getStorage() throws CoreException {
|
||||||
|
if (fStorage == null) {
|
||||||
|
IBinaryParser.IBinaryObject object= (IBinaryParser.IBinaryObject)fBinary.getAdapter(IBinaryParser.IBinaryObject.class);
|
||||||
|
if (object != null) {
|
||||||
|
IGnuToolFactory factory= (IGnuToolFactory) object.getBinaryParser().getAdapter(IGnuToolFactory.class);
|
||||||
|
if (factory != null) {
|
||||||
|
Objdump objdump= factory.getObjdump(object.getPath());
|
||||||
|
if (objdump != null) {
|
||||||
|
try {
|
||||||
|
fStorage= new FileStorage(new ByteArrayInputStream(objdump.getOutput()), object.getPath());
|
||||||
|
} catch (IOException exc) {
|
||||||
|
CUIPlugin.getDefault().log(exc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (fStorage == null) {
|
||||||
|
// fall back to binary content
|
||||||
|
fStorage= (IFile)fBinary.getResource();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return fStorage;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A storage docment provider for binary files.
|
||||||
|
*/
|
||||||
|
public static class BinaryFileDocumentProvider extends StorageDocumentProvider {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.eclipse.ui.editors.text.StorageDocumentProvider#createDocument(java.lang.Object)
|
||||||
|
*/
|
||||||
|
protected IDocument createDocument(Object element) throws CoreException {
|
||||||
|
IFile file= ResourceUtil.getFile(element);
|
||||||
|
if (file != null) {
|
||||||
|
ICElement cElement= CoreModel.getDefault().create(file);
|
||||||
|
if (cElement instanceof IBinary) {
|
||||||
|
element= new BinaryFileEditorInput((IBinary)cElement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return super.createDocument(element);
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* @see org.eclipse.ui.editors.text.StorageDocumentProvider#isModifiable(java.lang.Object)
|
||||||
|
*/
|
||||||
|
public boolean isModifiable(Object element) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* @see org.eclipse.ui.editors.text.StorageDocumentProvider#isReadOnly(java.lang.Object)
|
||||||
|
*/
|
||||||
|
public boolean isReadOnly(Object element) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public DefaultBinaryFileEditor() {
|
||||||
|
super();
|
||||||
|
setDocumentProvider(new BinaryFileDocumentProvider());
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#createSourceViewer(org.eclipse.swt.widgets.Composite, org.eclipse.jface.text.source.IVerticalRuler, int)
|
||||||
|
*/
|
||||||
|
protected ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int styles) {
|
||||||
|
ISourceViewer sourceViewer= super.createSourceViewer(parent, ruler, styles);
|
||||||
|
sourceViewer.setEditable(false);
|
||||||
|
return sourceViewer;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -28,6 +28,7 @@ import org.eclipse.core.resources.IResource;
|
||||||
import org.eclipse.core.resources.IStorage;
|
import org.eclipse.core.resources.IStorage;
|
||||||
import org.eclipse.core.resources.IWorkspaceRoot;
|
import org.eclipse.core.resources.IWorkspaceRoot;
|
||||||
import org.eclipse.core.resources.ResourcesPlugin;
|
import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
import org.eclipse.core.runtime.Platform;
|
import org.eclipse.core.runtime.Platform;
|
||||||
|
@ -44,6 +45,8 @@ import org.eclipse.ui.IWorkbenchPage;
|
||||||
import org.eclipse.ui.PartInitException;
|
import org.eclipse.ui.PartInitException;
|
||||||
import org.eclipse.ui.PlatformUI;
|
import org.eclipse.ui.PlatformUI;
|
||||||
import org.eclipse.ui.editors.text.EditorsUI;
|
import org.eclipse.ui.editors.text.EditorsUI;
|
||||||
|
import org.eclipse.ui.ide.IDE;
|
||||||
|
import org.eclipse.ui.ide.ResourceUtil;
|
||||||
import org.eclipse.ui.part.FileEditorInput;
|
import org.eclipse.ui.part.FileEditorInput;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
|
@ -231,9 +234,12 @@ public class EditorUtility {
|
||||||
}
|
}
|
||||||
return new ExternalEditorInput(unit, new FileStorage(unit.getPath()));
|
return new ExternalEditorInput(unit, new FileStorage(unit.getPath()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (element instanceof IBinary) {
|
if (element instanceof IBinary) {
|
||||||
return new ExternalEditorInput(getStorage((IBinary)element), (IPath)null);
|
IResource resource= element.getResource();
|
||||||
|
if (resource instanceof IFile) {
|
||||||
|
return new FileEditorInput((IFile)resource);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
element= element.getParent();
|
element= element.getParent();
|
||||||
|
@ -411,12 +417,13 @@ public class EditorUtility {
|
||||||
* @return a valid editor id, never <code>null</code>
|
* @return a valid editor id, never <code>null</code>
|
||||||
*/
|
*/
|
||||||
public static String getEditorID(String name) {
|
public static String getEditorID(String name) {
|
||||||
IEditorRegistry registry = PlatformUI.getWorkbench().getEditorRegistry();
|
try {
|
||||||
if (registry != null) {
|
IEditorDescriptor descriptor = IDE.getEditorDescriptor(name);
|
||||||
IEditorDescriptor descriptor = registry.getDefaultEditor(name);
|
|
||||||
if (descriptor != null) {
|
if (descriptor != null) {
|
||||||
return descriptor.getId();
|
return descriptor.getId();
|
||||||
}
|
}
|
||||||
|
} catch (PartInitException exc) {
|
||||||
|
// ignore
|
||||||
}
|
}
|
||||||
return DEFAULT_TEXT_EDITOR_ID;
|
return DEFAULT_TEXT_EDITOR_ID;
|
||||||
}
|
}
|
||||||
|
@ -433,47 +440,58 @@ public class EditorUtility {
|
||||||
* @return a valid editor id, never <code>null</code>
|
* @return a valid editor id, never <code>null</code>
|
||||||
*/
|
*/
|
||||||
public static String getEditorID(IEditorInput input, Object inputObject) {
|
public static String getEditorID(IEditorInput input, Object inputObject) {
|
||||||
|
ICElement cElement= null;
|
||||||
ITranslationUnit tunit = null;
|
if (input instanceof IFileEditorInput) {
|
||||||
if (inputObject instanceof ITranslationUnit) {
|
|
||||||
tunit= (ITranslationUnit)inputObject;
|
|
||||||
} else if (input instanceof IFileEditorInput) {
|
|
||||||
IFileEditorInput editorInput = (IFileEditorInput)input;
|
IFileEditorInput editorInput = (IFileEditorInput)input;
|
||||||
IFile file = editorInput.getFile();
|
IFile file = editorInput.getFile();
|
||||||
ICElement celement = CoreModel.getDefault().create(file);
|
// Try file specific editor.
|
||||||
if (celement instanceof ITranslationUnit) {
|
try {
|
||||||
tunit = (ITranslationUnit)celement;
|
String editorID = file.getPersistentProperty(IDE.EDITOR_KEY);
|
||||||
|
if (editorID != null) {
|
||||||
|
IEditorRegistry registry = PlatformUI.getWorkbench().getEditorRegistry();
|
||||||
|
IEditorDescriptor desc = registry.findEditor(editorID);
|
||||||
|
if (desc != null) {
|
||||||
|
return editorID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (CoreException e) {
|
||||||
|
// do nothing
|
||||||
}
|
}
|
||||||
|
cElement = CoreModel.getDefault().create(file);
|
||||||
} else if (input instanceof ITranslationUnitEditorInput) {
|
} else if (input instanceof ITranslationUnitEditorInput) {
|
||||||
ITranslationUnitEditorInput editorInput = (ITranslationUnitEditorInput)input;
|
ITranslationUnitEditorInput editorInput = (ITranslationUnitEditorInput)input;
|
||||||
tunit = editorInput.getTranslationUnit();
|
cElement = editorInput.getTranslationUnit();
|
||||||
|
} else if (inputObject instanceof ICElement) {
|
||||||
|
cElement= (ICElement)inputObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tunit != null) {
|
// Choose an editor based on the content type
|
||||||
// Choose an editor based on the content type
|
IContentType contentType= null;
|
||||||
String contentTypeId= tunit.getContentTypeId();
|
if (cElement instanceof ITranslationUnit) {
|
||||||
|
String contentTypeId= ((ITranslationUnit)cElement).getContentTypeId();
|
||||||
if (contentTypeId != null) {
|
if (contentTypeId != null) {
|
||||||
IContentType contentType= Platform.getContentTypeManager().getContentType(contentTypeId);
|
contentType= Platform.getContentTypeManager().getContentType(contentTypeId);
|
||||||
IEditorRegistry registry = PlatformUI.getWorkbench().getEditorRegistry();
|
}
|
||||||
IEditorDescriptor desc= registry.getDefaultEditor(input.getName(), contentType);
|
}
|
||||||
if (desc != null) {
|
if (contentType == null) {
|
||||||
return desc.getId();
|
IProject project= null;
|
||||||
|
if (cElement != null) {
|
||||||
|
project= cElement.getCProject().getProject();
|
||||||
|
} else {
|
||||||
|
IFile file= ResourceUtil.getFile(input);
|
||||||
|
if (file != null) {
|
||||||
|
project= file.getProject();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Choose an editor based on the language (obsolete?)
|
contentType= CCorePlugin.getContentType(project, input.getName());
|
||||||
if (tunit.isCLanguage()) {
|
}
|
||||||
return CUIPlugin.EDITOR_ID;
|
IEditorRegistry registry = PlatformUI.getWorkbench().getEditorRegistry();
|
||||||
} else if (tunit.isCXXLanguage()) {
|
IEditorDescriptor desc= registry.getDefaultEditor(input.getName(), contentType);
|
||||||
return CUIPlugin.EDITOR_ID;
|
if (desc != null) {
|
||||||
} else if (tunit.isASMLanguage()) {
|
return desc.getId();
|
||||||
return "org.eclipse.cdt.ui.editor.asm.AsmEditor"; //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Choose an editor based on filename/extension
|
return DEFAULT_TEXT_EDITOR_ID;
|
||||||
String editorId = getEditorID(input.getName());
|
|
||||||
|
|
||||||
return editorId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue