Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKen Ryall2006-12-12 15:05:20 +0000
committerKen Ryall2006-12-12 15:05:20 +0000
commitdf1ef579efb146e7b42a31f69ed7abde67e4cf65 (patch)
treed21ff46afcb23d195cf42129d702406a49a32dfc
parent29dfe7938f106e7ef7d4aabf6b8b972a75190844 (diff)
downloadorg.eclipse.cdt-df1ef579efb146e7b42a31f69ed7abde67e4cf65.tar.gz
org.eclipse.cdt-df1ef579efb146e7b42a31f69ed7abde67e4cf65.tar.xz
org.eclipse.cdt-df1ef579efb146e7b42a31f69ed7abde67e4cf65.zip
Support for CSourceNotFoundEditor, bug 167305.
-rw-r--r--debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLookupParticipant.java12
-rw-r--r--debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceNotFoundElement.java64
-rw-r--r--debug/org.eclipse.cdt.debug.ui/plugin.xml10
-rw-r--r--debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDebugModelPresentation.java13
-rw-r--r--debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/sourcelookup/CSourceNotFoundEditor.java194
-rw-r--r--debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/sourcelookup/CSourceNotFoundEditorInput.java27
-rw-r--r--debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/sourcelookup/SourceLookupUIMessages.properties3
7 files changed, 317 insertions, 6 deletions
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLookupParticipant.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLookupParticipant.java
index acde0284b1e..dbf4e0e07e2 100644
--- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLookupParticipant.java
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLookupParticipant.java
@@ -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)
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceNotFoundElement.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceNotFoundElement.java
new file mode 100644
index 00000000000..1140de86f17
--- /dev/null
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceNotFoundElement.java
@@ -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 "";
+ }
+
+
+}
diff --git a/debug/org.eclipse.cdt.debug.ui/plugin.xml b/debug/org.eclipse.cdt.debug.ui/plugin.xml
index 4bedb761aee..79dc3225fdd 100644
--- a/debug/org.eclipse.cdt.debug.ui/plugin.xml
+++ b/debug/org.eclipse.cdt.debug.ui/plugin.xml
@@ -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>
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDebugModelPresentation.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDebugModelPresentation.java
index b7db0cddc5e..90e2f3dd049 100644
--- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDebugModelPresentation.java
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDebugModelPresentation.java
@@ -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 ) {
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/sourcelookup/CSourceNotFoundEditor.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/sourcelookup/CSourceNotFoundEditor.java
new file mode 100644
index 00000000000..1eca74f79ca
--- /dev/null
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/sourcelookup/CSourceNotFoundEditor.java
@@ -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();
+
+ }
+ }
+ }
+
+}
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/sourcelookup/CSourceNotFoundEditorInput.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/sourcelookup/CSourceNotFoundEditorInput.java
new file mode 100644
index 00000000000..9eb10838550
--- /dev/null
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/sourcelookup/CSourceNotFoundEditorInput.java
@@ -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);
+ }
+
+}
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/sourcelookup/SourceLookupUIMessages.properties b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/sourcelookup/SourceLookupUIMessages.properties
index fc54dc90a36..59ff2d83948 100644
--- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/sourcelookup/SourceLookupUIMessages.properties
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/sourcelookup/SourceLookupUIMessages.properties
@@ -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... \ No newline at end of file

Back to the top