1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-05 16:56:04 +02:00

Support for CSourceNotFoundEditor, bug 167305.

This commit is contained in:
Ken Ryall 2006-12-12 15:05:20 +00:00
parent 29dfe7938f
commit df1ef579ef
7 changed files with 317 additions and 6 deletions

View file

@ -8,21 +8,18 @@
* Contributors:
* QNX Software Systems - Initial API and implementation
* Nokia - Added support for AbsoluteSourceContainer( 159833 )
* Nokia - Added support for CSourceNotFoundElement ( 167305 )
*******************************************************************************/
package org.eclipse.cdt.debug.internal.core.sourcelookup;
import java.io.File;
import org.eclipse.cdt.debug.core.model.ICStackFrame;
import org.eclipse.cdt.debug.core.sourcelookup.ISourceLookupChangeListener;
import org.eclipse.cdt.debug.internal.core.ListenerList;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.Path;
import org.eclipse.debug.core.model.IDebugElement;
import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupParticipant;
import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector;
import org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage;
/**
* A source lookup participant that searches for C/C++ source code.
@ -78,7 +75,10 @@ public class CSourceLookupParticipant extends AbstractSourceLookupParticipant {
else if ( object instanceof String ) {
name = (String)object;
}
return super.findSourceElements( object );
Object[] foundElements = super.findSourceElements( object );
if (foundElements.length == 0 && (object instanceof IDebugElement))
foundElements = new Object[] { new CSourceNotFoundElement( (IDebugElement) object ) };
return foundElements;
}
/* (non-Javadoc)

View file

@ -0,0 +1,64 @@
/*******************************************************************************
* Copyright (c) 2006 Nokia 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:
* Nokia - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.debug.internal.core.sourcelookup;
import org.eclipse.cdt.debug.core.model.ICStackFrame;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.model.IDebugElement;
import org.eclipse.debug.core.model.IDebugTarget;
/**
* Wrapper for debug elements that have missing source, for example a stack frame
* whose source file can not be located. Used to enable the CSourceNotFoundEditor
* that will let you find the missing file.
*
*/
public class CSourceNotFoundElement implements IDebugElement{
private IDebugElement element;
public IDebugElement getElement() {
return element;
}
public CSourceNotFoundElement(IDebugElement element)
{
this.element = element;
}
public IDebugTarget getDebugTarget() {
return element.getDebugTarget();
}
public ILaunch getLaunch() {
return element.getLaunch();
}
public String getModelIdentifier() {
return element.getModelIdentifier();
}
public Object getAdapter(Class adapter) {
return element.getAdapter(adapter);
}
public String getFile() {
ICStackFrame frame = (ICStackFrame)((IAdaptable)element).getAdapter( ICStackFrame.class );
if ( frame != null ) {
return frame.getFile().trim();
}
return "";
}
}

View file

@ -1241,5 +1241,15 @@
id="org.eclipse.cdt.ui.import"
name="%importCPPCategory.name"/>
</extension>
<!-- Source Not Found Editor -->
<extension
point="org.eclipse.ui.editors">
<editor
name="C/C++ Source Not Found Editor"
icon="$nl$/icons/obj16/c_app.gif"
class="org.eclipse.cdt.debug.internal.ui.sourcelookup.CSourceNotFoundEditor"
id="org.eclipse.cdt.debug.internal.ui.sourcelookup.CSourceNotFoundEditor">
</editor>
</extension>
</plugin>

View file

@ -7,12 +7,14 @@
*
* Contributors:
* QNX Software Systems - Initial API and implementation
* Nokia - Added support for CSourceNotFoundElement ( 167305 )
*******************************************************************************/
package org.eclipse.cdt.debug.internal.ui;
import java.io.File;
import java.text.MessageFormat;
import java.util.HashMap;
import org.eclipse.cdt.core.IAddress;
import org.eclipse.cdt.core.resources.FileStorage;
import org.eclipse.cdt.debug.core.CDebugUtils;
@ -43,6 +45,8 @@ import org.eclipse.cdt.debug.core.model.ICVariable;
import org.eclipse.cdt.debug.core.model.ICWatchpoint;
import org.eclipse.cdt.debug.core.model.IDummyStackFrame;
import org.eclipse.cdt.debug.core.model.IEnableDisableTarget;
import org.eclipse.cdt.debug.internal.core.sourcelookup.CSourceNotFoundElement;
import org.eclipse.cdt.debug.internal.ui.sourcelookup.CSourceNotFoundEditorInput;
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
import org.eclipse.cdt.internal.ui.util.ExternalEditorInput;
import org.eclipse.cdt.ui.CUIPlugin;
@ -163,6 +167,10 @@ public class CDebugModelPresentation extends LabelProvider implements IDebugMode
if ( element instanceof FileStorage || element instanceof LocalFileStorage ) {
return new ExternalEditorInput( (IStorage)element );
}
if (element instanceof CSourceNotFoundElement)
{
return new CSourceNotFoundEditorInput((CSourceNotFoundElement) element);
}
return null;
}
@ -170,6 +178,8 @@ public class CDebugModelPresentation extends LabelProvider implements IDebugMode
* @see org.eclipse.debug.ui.ISourcePresentation#getEditorId(org.eclipse.ui.IEditorInput, java.lang.Object)
*/
public String getEditorId( IEditorInput input, Object element ) {
if (element instanceof CSourceNotFoundElement)
return "org.eclipse.cdt.debug.internal.ui.sourcelookup.CSourceNotFoundEditor";
String id = null;
if ( input != null ) {
IEditorRegistry registry = PlatformUI.getWorkbench().getEditorRegistry();
@ -369,6 +379,9 @@ public class CDebugModelPresentation extends LabelProvider implements IDebugMode
label.append( getStackFrameText( (IStackFrame)element, showQualified ) );
return label.toString();
}
if ( element instanceof CSourceNotFoundElement ) {
return getBaseText(((CSourceNotFoundElement)element).getElement());
}
if ( element instanceof IMarker ) {
IBreakpoint breakpoint = getBreakpoint( (IMarker)element );
if ( breakpoint != null ) {

View file

@ -0,0 +1,194 @@
/*******************************************************************************
* Copyright (c) 2006 Nokia 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:
* Nokia - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.sourcelookup;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import org.eclipse.cdt.debug.core.sourcelookup.MappingSourceContainer;
import org.eclipse.cdt.debug.internal.core.sourcelookup.CSourceNotFoundElement;
import org.eclipse.cdt.debug.internal.core.sourcelookup.MapEntrySourceContainer;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.core.model.IDebugElement;
import org.eclipse.debug.core.model.ISourceLocator;
import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupDirector;
import org.eclipse.debug.core.sourcelookup.ISourceContainer;
import org.eclipse.debug.internal.ui.sourcelookup.SourceLookupManager;
import org.eclipse.debug.ui.sourcelookup.CommonSourceNotFoundEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
/**
* Editor that lets you select a replacement for the missing source file
* and modifies the source locator accordingly.
*
*/
public class CSourceNotFoundEditor extends CommonSourceNotFoundEditor {
public final String foundMappingsContainerName = "Found Mappings"; //$NON-NLS-1$
private String missingFile;
private ILaunch launch;
private IDebugElement context;
public CSourceNotFoundEditor() {
super();
}
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
super.init(site, input);
Object artifact = this.getArtifact();
if (artifact instanceof CSourceNotFoundElement)
{
CSourceNotFoundElement element = (CSourceNotFoundElement) artifact;
missingFile = element.getFile();
launch = element.getLaunch();
context = element.getElement();
}
else
missingFile = ""; //$NON-NLS-1$
}
protected String getText() {
if (missingFile.length() > 0) {
return MessageFormat.format(SourceLookupUIMessages.getString( "CSourceNotFoundEditor.0" ), new String[] { missingFile }); //$NON-NLS-1$
}
return super.getText();
}
protected void createButtons(Composite parent) {
if (missingFile.length() > 0) {
GridData data;
Button button = new Button(parent, SWT.PUSH);
data = new GridData();
data.grabExcessHorizontalSpace = false;
data.grabExcessVerticalSpace = false;
button.setLayoutData(data);
button.setText(SourceLookupUIMessages.getString( "CSourceNotFoundEditor.1" )); //$NON-NLS-1$
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent evt) {
locateFile();
}
});
}
super.createButtons(parent);
}
private void addSourceMapping(IPath missingPath, IPath newSourcePath) throws CoreException {
String memento = null;
String type = null;
ILaunchConfigurationWorkingCopy configuration = launch.getLaunchConfiguration().getWorkingCopy();
memento = configuration.getAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_MEMENTO, (String) null);
type = configuration.getAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_ID, (String) null);
if (type == null) {
type = configuration.getType().getSourceLocatorId();
}
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
ISourceLocator locator = launchManager.newSourceLocator(type);
if (locator instanceof AbstractSourceLookupDirector) {
AbstractSourceLookupDirector director = (AbstractSourceLookupDirector) locator;
if (memento == null) {
director.initializeDefaults(configuration);
} else {
director.initializeFromMemento(memento, configuration);
}
ArrayList containerList = new ArrayList(Arrays.asList(director.getSourceContainers()));
boolean hasFoundMappings = false;
MappingSourceContainer foundMappings = null;
for (Iterator iter = containerList.iterator(); iter.hasNext() && !hasFoundMappings;) {
ISourceContainer container = (ISourceContainer) iter.next();
if (container instanceof MappingSourceContainer)
{
hasFoundMappings = container.getName().equals(foundMappingsContainerName);
if (hasFoundMappings)
foundMappings = (MappingSourceContainer) container;
}
}
if (!hasFoundMappings) {
foundMappings = new MappingSourceContainer(foundMappingsContainerName);
foundMappings.init(director);
containerList.add(foundMappings);
director.setSourceContainers((ISourceContainer[]) containerList.toArray(new ISourceContainer[containerList.size()]));
}
foundMappings.addMapEntry(new MapEntrySourceContainer(missingPath, newSourcePath));
configuration.setAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_MEMENTO, director.getMemento());
configuration.setAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_ID, director.getId());
configuration.doSave();
}
}
protected void locateFile() {
FileDialog dialog = new FileDialog(getEditorSite().getShell(), SWT.NONE);
Path missingPath = new Path(missingFile);
dialog.setFilterNames(new String[] {missingPath.lastSegment()});
dialog.setFilterExtensions(new String[] {missingPath.getFileExtension()});
String res = dialog.open();
if (res != null) {
Path newPath = new Path(res);
if (newPath.lastSegment().equalsIgnoreCase(missingPath.lastSegment()))
{
if (missingPath.segmentCount() > 1)
{
int missingPathSegCount = missingPath.segmentCount() - 2;
int newPathSegCount = newPath.segmentCount() - 2;
while (missingPathSegCount >= 0 && newPathSegCount >= 0)
{
if (!newPath.segment(newPathSegCount).equalsIgnoreCase(missingPath.segment(missingPathSegCount)))
break;
newPathSegCount--;
missingPathSegCount--;
}
IPath compPath = missingPath.removeLastSegments(missingPath.segmentCount() - missingPathSegCount - 1);
IPath newSourcePath = newPath.removeLastSegments(newPath.segmentCount() - newPathSegCount - 1);
try {
addSourceMapping(compPath, newSourcePath);
} catch (CoreException e) {}
}
IWorkbenchPage page = getEditorSite().getPage();
SourceLookupManager.getDefault().displaySource(context, page, true);
closeEditor();
}
}
}
}

View file

@ -0,0 +1,27 @@
/*******************************************************************************
* Copyright (c) 2006 Nokia 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:
* Nokia - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.sourcelookup;
import org.eclipse.cdt.debug.internal.core.sourcelookup.CSourceNotFoundElement;
import org.eclipse.debug.ui.sourcelookup.CommonSourceNotFoundEditorInput;
public class CSourceNotFoundEditorInput extends CommonSourceNotFoundEditorInput {
public CSourceNotFoundElement getElement() {
return (CSourceNotFoundElement) getArtifact();
}
public CSourceNotFoundEditorInput(CSourceNotFoundElement artifact) {
super(artifact);
}
}

View file

@ -7,6 +7,7 @@
#
# Contributors:
# QNX Software Systems - initial API and implementation
# Nokia - Added support for CSourceNotFoundElement ( 167305 )
###############################################################################
AddContainerAction.0=&Add...
AddSourceContainerDialog.0=Add Source
@ -34,3 +35,5 @@ PathMappingDialog.16=Path Mappings
RemoveAction.0=Re&move
SourceContainerWorkbenchAdapter.0=Path Mapping:
UpAction.0=U&p
CSourceNotFoundEditor.0=Can''t find a source file at \"{0}\" \nLocate the file or edit the source lookup path to include its location.
CSourceNotFoundEditor.1=Locate File...