1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Fix for PR 35960: the "Search for duplicate source files" option is added.

This commit is contained in:
Mikhail Khodjaiants 2003-10-17 19:23:01 +00:00
parent ab1e01699b
commit d253f76e29
14 changed files with 331 additions and 37 deletions

View file

@ -1,3 +1,12 @@
2003-10-17 Mikhail Khodjaiants
Core support of the 'Search for duplicate source files' option.
* ICSourceLocation.java
* ICSourceLocator.java
* CDirectorySourceLocation.java
* CProjectSourceLocation.java
* CSourceLocator.java
* CSourceManager.java
2003-10-17 Mikhail Khodjaiants 2003-10-17 Mikhail Khodjaiants
If the target is suspended by a line breakpoint the source manager tries to retrieve If the target is suspended by a line breakpoint the source manager tries to retrieve
the file resource from the breakpoint marker. the file resource from the breakpoint marker.

View file

@ -24,7 +24,7 @@ public interface ICSourceLocation extends IAdaptable
{ {
/** /**
* Returns an object representing the source code * Returns an object representing the source code
* for a type with the specified name, or <code>null</code> * for a file with the specified name, or <code>null</code>
* if none could be found. The source element * if none could be found. The source element
* returned is implementation specific - for example, a * returned is implementation specific - for example, a
* resource, a local file, a zip file entry, etc. * resource, a local file, a zip file entry, etc.
@ -35,7 +35,7 @@ public interface ICSourceLocation extends IAdaptable
* @exception CoreException if an exception occurs while searching for the specified source element * @exception CoreException if an exception occurs while searching for the specified source element
*/ */
Object findSourceElement( String name ) throws CoreException; Object findSourceElement( String name ) throws CoreException;
/** /**
* Returns a memento for this source location from which this * Returns a memento for this source location from which this
* source location can be reconstructed. * source location can be reconstructed.
@ -43,7 +43,7 @@ public interface ICSourceLocation extends IAdaptable
* @return a memento for this source location * @return a memento for this source location
* @exception CoreException if unable to create a memento * @exception CoreException if unable to create a memento
*/ */
public String getMemento() throws CoreException; String getMemento() throws CoreException;
/** /**
* Initializes this source location from the given memento. * Initializes this source location from the given memento.
@ -52,5 +52,19 @@ public interface ICSourceLocation extends IAdaptable
* @exception CoreException if unable to initialize this source * @exception CoreException if unable to initialize this source
* location * location
*/ */
public void initializeFrom( String memento ) throws CoreException; void initializeFrom( String memento ) throws CoreException;
/**
* Returns whether to search for all source elements, or just the first match.
*
* @return whether to search for all source elements, or just the first match
*/
boolean searchForDuplicateFiles();
/**
* Sets the value of the 'search for duplicate source files' flag.
*
* @param search - a value to set
*/
void setSearchForDuplicateFiles( boolean search );
} }

View file

@ -71,4 +71,18 @@ public interface ICSourceLocator extends ISourceLocator
* @return source element * @return source element
*/ */
Object findSourceElement( String fileName ); Object findSourceElement( String fileName );
}
/**
* Returns whether to search for all source elements, or just the first match.
*
* @return whether to search for all source elements, or just the first match
*/
boolean searchForDuplicateFiles();
/**
* Sets the value of the 'search for duplicate source files' flag.
*
* @param search - a value to set
*/
void setSearchForDuplicateFiles( boolean search );
}

View file

@ -57,6 +57,8 @@ public class CDirectorySourceLocation implements IDirectorySourceLocation
*/ */
private IPath fAssociation = null; private IPath fAssociation = null;
private boolean fSearchForDuplicateFiles = false;
/** /**
* Constructor for CDirectorySourceLocation. * Constructor for CDirectorySourceLocation.
*/ */
@ -182,12 +184,12 @@ public class CDirectorySourceLocation implements IDirectorySourceLocation
LinkedList list = new LinkedList(); LinkedList list = new LinkedList();
for ( int j = 0; j < wsFiles.length; ++j ) for ( int j = 0; j < wsFiles.length; ++j )
if ( wsFiles[j].exists() ) if ( wsFiles[j].exists() )
if ( !searchForDuplicateFileNames() ) if ( !searchForDuplicateFiles() )
return wsFiles[j]; return wsFiles[j];
else else
list.add( wsFiles[j] ); list.add( wsFiles[j] );
if ( list.size() > 0 ) if ( list.size() > 0 )
return list; return ( list.size() == 1 ) ? list.getFirst() : list;
file = filePath.toFile(); file = filePath.toFile();
if ( file.exists() ) if ( file.exists() )
@ -211,12 +213,12 @@ public class CDirectorySourceLocation implements IDirectorySourceLocation
LinkedList list = new LinkedList(); LinkedList list = new LinkedList();
for ( int j = 0; j < wsFiles.length; ++j ) for ( int j = 0; j < wsFiles.length; ++j )
if ( wsFiles[j].exists() ) if ( wsFiles[j].exists() )
if ( !searchForDuplicateFileNames() ) if ( !searchForDuplicateFiles() )
return wsFiles[j]; return wsFiles[j];
else else
list.add( wsFiles[j] ); list.add( wsFiles[j] );
if ( list.size() > 0 ) if ( list.size() > 0 )
return list; return ( list.size() == 1 ) ? list.getFirst() : list;
else else
return createExternalFileStorage( path ); return createExternalFileStorage( path );
} }
@ -368,9 +370,19 @@ public class CDirectorySourceLocation implements IDirectorySourceLocation
return prefixString.equalsIgnoreCase( pathString ); return prefixString.equalsIgnoreCase( pathString );
} }
protected boolean searchForDuplicateFileNames() /* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation#setSearchForDuplicateFiles(boolean)
*/
public void setSearchForDuplicateFiles( boolean search )
{ {
// for now fSearchForDuplicateFiles = search;
return false; }
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation#searchForDuplicateFiles()
*/
public boolean searchForDuplicateFiles()
{
return fSearchForDuplicateFiles;
} }
} }

View file

@ -62,6 +62,8 @@ public class CProjectSourceLocation implements IProjectSourceLocation
private HashSet fNotFoundCache = new HashSet( 20 ); private HashSet fNotFoundCache = new HashSet( 20 );
private boolean fGenerated = true; private boolean fGenerated = true;
private boolean fSearchForDuplicateFiles = false;
/** /**
* Constructor for CProjectSourceLocation. * Constructor for CProjectSourceLocation.
@ -162,12 +164,12 @@ public class CProjectSourceLocation implements IProjectSourceLocation
IFile[] wsFiles = CDebugCorePlugin.getWorkspace().getRoot().findFilesForLocation( path ); IFile[] wsFiles = CDebugCorePlugin.getWorkspace().getRoot().findFilesForLocation( path );
for ( int i = 0; i < wsFiles.length; ++i ) for ( int i = 0; i < wsFiles.length; ++i )
if ( wsFiles[i].getProject().equals( getProject() ) && wsFiles[i].exists() ) if ( wsFiles[i].getProject().equals( getProject() ) && wsFiles[i].exists() )
if ( !searchForDuplicateFileNames() ) if ( !searchForDuplicateFiles() )
return wsFiles[i]; return wsFiles[i];
else else
list.add( wsFiles[i] ); list.add( wsFiles[i] );
} }
return ( list.size() > 0 ) ? list : null; return ( list.size() > 0 ) ? ( ( list.size() == 1 ) ? list.getFirst() : list ) : null;
} }
private Object findFileByRelativePath( String fileName ) private Object findFileByRelativePath( String fileName )
@ -176,7 +178,7 @@ public class CProjectSourceLocation implements IProjectSourceLocation
LinkedList list = new LinkedList(); LinkedList list = new LinkedList();
for ( int i = 0; i < folders.length; ++i ) for ( int i = 0; i < folders.length; ++i )
{ {
if ( list.size() > 0 && !searchForDuplicateFileNames() ) if ( list.size() > 0 && !searchForDuplicateFiles() )
break; break;
IPath path = folders[i].getLocation().append( fileName ); IPath path = folders[i].getLocation().append( fileName );
File file = new File( path.toOSString() ); File file = new File( path.toOSString() );
@ -185,13 +187,13 @@ public class CProjectSourceLocation implements IProjectSourceLocation
IFile[] wsFiles = CDebugCorePlugin.getWorkspace().getRoot().findFilesForLocation( path ); IFile[] wsFiles = CDebugCorePlugin.getWorkspace().getRoot().findFilesForLocation( path );
for ( int j = 0; j < wsFiles.length; ++j ) for ( int j = 0; j < wsFiles.length; ++j )
if ( wsFiles[j].exists() ) if ( wsFiles[j].exists() )
if ( !searchForDuplicateFileNames() ) if ( !searchForDuplicateFiles() )
return wsFiles[j]; return wsFiles[j];
else else
list.add( wsFiles[j] ); list.add( wsFiles[j] );
} }
} }
return ( list.size() > 0 ) ? list : null; return ( list.size() > 0 ) ? ( ( list.size() == 1 ) ? list.getFirst() : list ) : null;
} }
private Object cacheLookup( String name ) private Object cacheLookup( String name )
@ -369,9 +371,21 @@ public class CProjectSourceLocation implements IProjectSourceLocation
return fFolders; return fFolders;
} }
protected boolean searchForDuplicateFileNames() /* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation#searchForDuplicateFiles()
*/
public boolean searchForDuplicateFiles()
{ {
// for now return fSearchForDuplicateFiles;
return false; }
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation#setSearchForDuplicateFiles(boolean)
*/
public void setSearchForDuplicateFiles( boolean search )
{
fCache.clear();
fNotFoundCache.clear();
fSearchForDuplicateFiles = search;
} }
} }

View file

@ -13,6 +13,7 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
@ -63,6 +64,7 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato
private static final String ATTR_CLASS = "class"; private static final String ATTR_CLASS = "class";
private static final String ATTR_MEMENTO = "memento"; private static final String ATTR_MEMENTO = "memento";
private static final String ATTR_PROJECT_NAME = "projectName"; private static final String ATTR_PROJECT_NAME = "projectName";
private static final String ATTR_DUPLICATE_FILES = "duplicateFiles";
/** /**
* The project associated with this locator. * The project associated with this locator.
@ -79,6 +81,12 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato
*/ */
private List fReferencedProjects = new ArrayList( 10 ); private List fReferencedProjects = new ArrayList( 10 );
/**
* The flag specifies whether to search for all source elements,
* or just the first match.
*/
private boolean fDuplicateFiles = false;
/** /**
* Constructor for CSourceLocator. * Constructor for CSourceLocator.
*/ */
@ -112,9 +120,10 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato
protected Object getInput( IStackFrameInfo info ) protected Object getInput( IStackFrameInfo info )
{ {
Object result = null; LinkedList list = new LinkedList();
if ( info != null ) if ( info != null )
{ {
Object result = null;
String fileName = info.getFile(); String fileName = info.getFile();
if ( fileName != null && fileName.length() > 0 ) if ( fileName != null && fileName.length() > 0 )
{ {
@ -130,11 +139,18 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato
// do nothing // do nothing
} }
if ( result != null ) if ( result != null )
break; {
if ( result instanceof List )
list.addAll( (List)result );
else
list.add( result );
if ( !searchForDuplicateFiles() )
break;
}
} }
} }
} }
return result; return ( list.size() > 0 ) ? ( ( list.size() == 1 ) ? list.getFirst() : list ) : null;
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -281,7 +297,7 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato
ICSourceLocation[] locations = getSourceLocations(); ICSourceLocation[] locations = getSourceLocations();
saveDisabledGenericSourceLocations( locations, doc, node ); saveDisabledGenericSourceLocations( locations, doc, node );
saveAdditionalSourceLocations( locations, doc, node ); saveAdditionalSourceLocations( locations, doc, node );
node.setAttribute( ATTR_DUPLICATE_FILES, new Boolean( searchForDuplicateFiles() ).toString() );
try try
{ {
return CDebugUtils.serializeDocument( doc, " " ); return CDebugUtils.serializeDocument( doc, " " );
@ -333,6 +349,9 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato
// To support old launch configuration // To support old launch configuration
addOldLocations( root, sourceLocations ); addOldLocations( root, sourceLocations );
setSourceLocations( (ICSourceLocation[])sourceLocations.toArray( new ICSourceLocation[sourceLocations.size()] ) ); setSourceLocations( (ICSourceLocation[])sourceLocations.toArray( new ICSourceLocation[sourceLocations.size()] ) );
setSearchForDuplicateFiles( Boolean.valueOf( root.getAttribute( ATTR_DUPLICATE_FILES ) ).booleanValue() );
return; return;
} }
catch( ParserConfigurationException e ) catch( ParserConfigurationException e )
@ -693,4 +712,20 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato
fReferencedProjects = newRefs; fReferencedProjects = newRefs;
setSourceLocations( (ICSourceLocation[])newLocations.toArray( new ICSourceLocation[newLocations.size()] ) ); setSourceLocations( (ICSourceLocation[])newLocations.toArray( new ICSourceLocation[newLocations.size()] ) );
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator#searchForDuplicateFiles()
*/
public boolean searchForDuplicateFiles()
{
return fDuplicateFiles;
}
public void setSearchForDuplicateFiles( boolean search )
{
fDuplicateFiles = search;
ICSourceLocation[] locations = getSourceLocations();
for ( int i = 0; i < locations.length; ++i )
locations[i].setSearchForDuplicateFiles( search );
}
} }

View file

@ -172,7 +172,7 @@ public class CSourceManager implements ICSourceLocator,
} }
return result; return result;
} }
protected ICSourceLocator getCSourceLocator() protected ICSourceLocator getCSourceLocator()
{ {
if ( getSourceLocator() instanceof ICSourceLocator ) if ( getSourceLocator() instanceof ICSourceLocator )
@ -275,4 +275,21 @@ public class CSourceManager implements ICSourceLocator,
{ {
return fDebugTarget; return fDebugTarget;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator#setSearchForDuplicateFiles(boolean)
*/
public void setSearchForDuplicateFiles( boolean search )
{
if ( getCSourceLocator() != null )
getCSourceLocator().setSearchForDuplicateFiles( search );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator#searchForDuplicateFiles()
*/
public boolean searchForDuplicateFiles()
{
return ( getCSourceLocator() != null ) ? getCSourceLocator().searchForDuplicateFiles() : false;
}
} }

View file

@ -1,3 +1,12 @@
2003-10-17 Mikhail Khodjaiants
UI support of the 'Search for duplicate source files' option.
* icons/full/obj16/prj_file_obj.gif: new
* icons/full/obj16/ext_file_obj.gif: new
* CDebugImages.java
* CUISourceLocator.java
* SourceLookupBlock.java
* SourcePropertyPage.java
2003-10-17 Mikhail Khodjaiants 2003-10-17 Mikhail Khodjaiants
* CDebugEditor.java: changed the message displayed when the source file not found. * CDebugEditor.java: changed the message displayed when the source file not found.

Binary file not shown.

After

Width:  |  Height:  |  Size: 171 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 180 B

View file

@ -88,6 +88,8 @@ public class CDebugImages
public static final String IMG_OBJS_LOADED_SHARED_LIBRARY = NAME_PREFIX + "library_syms_obj.gif"; //$NON-NLS-1$ public static final String IMG_OBJS_LOADED_SHARED_LIBRARY = NAME_PREFIX + "library_syms_obj.gif"; //$NON-NLS-1$
public static final String IMG_OBJS_SHARED_LIBRARY = NAME_PREFIX + "library_obj.gif"; //$NON-NLS-1$ public static final String IMG_OBJS_SHARED_LIBRARY = NAME_PREFIX + "library_obj.gif"; //$NON-NLS-1$
public static final String IMG_OBJS_SIGNAL = NAME_PREFIX + "signal_obj.gif"; //$NON-NLS-1$ public static final String IMG_OBJS_SIGNAL = NAME_PREFIX + "signal_obj.gif"; //$NON-NLS-1$
public static final String IMG_OBJS_WORKSPACE_SOURCE_FILE = NAME_PREFIX + "prj_file_obj.gif"; //$NON-NLS-1$
public static final String IMG_OBJS_EXTERNAL_SOURCE_FILE = NAME_PREFIX + "ext_file_obj.gif"; //$NON-NLS-1$
public static final String IMG_LCL_TYPE_NAMES = NAME_PREFIX + "tnames_co.gif"; //$NON-NLS-1$ public static final String IMG_LCL_TYPE_NAMES = NAME_PREFIX + "tnames_co.gif"; //$NON-NLS-1$
public static final String IMG_LCL_CHANGE_REGISTER_VALUE = NAME_PREFIX + "change_reg_value_co.gif"; //$NON-NLS-1$ public static final String IMG_LCL_CHANGE_REGISTER_VALUE = NAME_PREFIX + "change_reg_value_co.gif"; //$NON-NLS-1$
@ -155,6 +157,8 @@ public class CDebugImages
public static final ImageDescriptor DESC_OBJS_LOADED_SHARED_LIBRARY = createManaged( T_OBJ, IMG_OBJS_LOADED_SHARED_LIBRARY ); public static final ImageDescriptor DESC_OBJS_LOADED_SHARED_LIBRARY = createManaged( T_OBJ, IMG_OBJS_LOADED_SHARED_LIBRARY );
public static final ImageDescriptor DESC_OBJS_SHARED_LIBRARY = createManaged( T_OBJ, IMG_OBJS_SHARED_LIBRARY ); public static final ImageDescriptor DESC_OBJS_SHARED_LIBRARY = createManaged( T_OBJ, IMG_OBJS_SHARED_LIBRARY );
public static final ImageDescriptor DESC_OBJS_SIGNAL = createManaged( T_OBJ, IMG_OBJS_SIGNAL ); public static final ImageDescriptor DESC_OBJS_SIGNAL = createManaged( T_OBJ, IMG_OBJS_SIGNAL );
public static final ImageDescriptor DESC_OBJS_WORKSPACE_SOURCE_FILE = createManaged( T_OBJ, IMG_OBJS_WORKSPACE_SOURCE_FILE );
public static final ImageDescriptor DESC_OBJS_EXTERNAL_SOURCE_FILE = createManaged( T_OBJ, IMG_OBJS_EXTERNAL_SOURCE_FILE );
public static final ImageDescriptor DESC_WIZBAN_ADD_SOURCE_LOCATION = createManaged( T_WIZBAN, IMG_WIZBAN_ADD_SOURCE_LOCATION ); //$NON-NLS-1$ public static final ImageDescriptor DESC_WIZBAN_ADD_SOURCE_LOCATION = createManaged( T_WIZBAN, IMG_WIZBAN_ADD_SOURCE_LOCATION ); //$NON-NLS-1$
public static final ImageDescriptor DESC_WIZBAN_ADD_PRJ_SOURCE_LOCATION = createManaged( T_WIZBAN, IMG_WIZBAN_ADD_PRJ_SOURCE_LOCATION ); //$NON-NLS-1$ public static final ImageDescriptor DESC_WIZBAN_ADD_PRJ_SOURCE_LOCATION = createManaged( T_WIZBAN, IMG_WIZBAN_ADD_PRJ_SOURCE_LOCATION ); //$NON-NLS-1$
public static final ImageDescriptor DESC_WIZBAN_ADD_DIR_SOURCE_LOCATION = createManaged( T_WIZBAN, IMG_WIZBAN_ADD_DIR_SOURCE_LOCATION ); //$NON-NLS-1$ public static final ImageDescriptor DESC_WIZBAN_ADD_DIR_SOURCE_LOCATION = createManaged( T_WIZBAN, IMG_WIZBAN_ADD_DIR_SOURCE_LOCATION ); //$NON-NLS-1$

View file

@ -5,14 +5,23 @@
*/ */
package org.eclipse.cdt.debug.ui.sourcelookup; package org.eclipse.cdt.debug.ui.sourcelookup;
import java.util.HashMap;
import java.util.List;
import org.eclipse.cdt.core.resources.FileStorage;
import org.eclipse.cdt.debug.core.model.IStackFrameInfo; import org.eclipse.cdt.debug.core.model.IStackFrameInfo;
import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator; import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator;
import org.eclipse.cdt.debug.core.sourcelookup.ISourceMode; import org.eclipse.cdt.debug.core.sourcelookup.ISourceMode;
import org.eclipse.cdt.debug.internal.core.sourcelookup.CSourceLocator; import org.eclipse.cdt.debug.internal.core.sourcelookup.CSourceLocator;
import org.eclipse.cdt.debug.internal.core.sourcelookup.CSourceManager; import org.eclipse.cdt.debug.internal.core.sourcelookup.CSourceManager;
import org.eclipse.cdt.debug.internal.ui.CDebugImageDescriptorRegistry;
import org.eclipse.cdt.debug.internal.ui.CDebugImages;
import org.eclipse.cdt.debug.internal.ui.dialogfields.SelectionButtonDialogField;
import org.eclipse.cdt.debug.internal.ui.editors.FileNotFoundElement; import org.eclipse.cdt.debug.internal.ui.editors.FileNotFoundElement;
import org.eclipse.cdt.debug.internal.ui.editors.NoSymbolOrSourceElement; import org.eclipse.cdt.debug.internal.ui.editors.NoSymbolOrSourceElement;
import org.eclipse.cdt.debug.ui.CDebugUIPlugin; import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
import org.eclipse.cdt.utils.ui.controls.ControlFactory;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResourceChangeListener; import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
@ -22,6 +31,14 @@ import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.core.model.IPersistableSourceLocator; import org.eclipse.debug.core.model.IPersistableSourceLocator;
import org.eclipse.debug.core.model.IStackFrame; import org.eclipse.debug.core.model.IStackFrame;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.dialogs.ListDialog;
/** /**
* *
@ -32,6 +49,62 @@ import org.eclipse.debug.core.model.IStackFrame;
*/ */
public class CUISourceLocator implements IAdaptable public class CUISourceLocator implements IAdaptable
{ {
public class SourceSelectionDialog extends ListDialog
{
private SelectionButtonDialogField fAlwaysUseThisFileButton = new SelectionButtonDialogField( SWT.CHECK );
public SourceSelectionDialog( Shell parent )
{
super( parent );
}
/* (non-Javadoc)
* @see org.eclipse.ui.dialogs.ListDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
*/
protected Control createDialogArea( Composite parent )
{
Composite comp = ControlFactory.createComposite( parent, 1 );
super.createDialogArea( comp );
Composite comp1 = ControlFactory.createComposite( comp, 1 );
fAlwaysUseThisFileButton.setLabelText( "Always map to the selection" );
fAlwaysUseThisFileButton.doFillIntoGrid( comp1, 1 );
return comp;
}
public boolean alwaysMapToSelection()
{
return fAlwaysUseThisFileButton.isSelected();
}
}
public class SourceElementLabelProvider extends LabelProvider
{
protected CDebugImageDescriptorRegistry fDebugImageRegistry = CDebugUIPlugin.getImageDescriptorRegistry();
public SourceElementLabelProvider()
{
super();
}
public String getText(Object element)
{
if ( element instanceof IFile )
return ((IFile)element).getFullPath().toString();
if ( element instanceof FileStorage )
return ((FileStorage)element).getFullPath().toOSString();
return super.getText(element);
}
public Image getImage( Object element )
{
if ( element instanceof IFile )
return fDebugImageRegistry.get( CDebugImages.DESC_OBJS_WORKSPACE_SOURCE_FILE );
if ( element instanceof FileStorage )
return fDebugImageRegistry.get( CDebugImages.DESC_OBJS_EXTERNAL_SOURCE_FILE );
return super.getImage( element );
}
}
/** /**
* The project being debugged. * The project being debugged.
*/ */
@ -41,7 +114,10 @@ public class CUISourceLocator implements IAdaptable
* Underlying source locator. * Underlying source locator.
*/ */
private CSourceManager fSourceLocator; private CSourceManager fSourceLocator;
private HashMap fFramesToSource = null;
private HashMap fNamesToSource = null;
/** /**
* Constructor for CUISourceLocator. * Constructor for CUISourceLocator.
*/ */
@ -53,7 +129,26 @@ public class CUISourceLocator implements IAdaptable
public Object getSourceElement( IStackFrame stackFrame ) public Object getSourceElement( IStackFrame stackFrame )
{ {
Object res = fSourceLocator.getSourceElement( stackFrame ); Object res = cacheLookup( stackFrame );
if ( res == null )
{
res = fSourceLocator.getSourceElement( stackFrame );
if ( res instanceof List )
{
List list = (List)res;
if ( list.size() != 0 )
{
SourceSelectionDialog dialog = createSourceSelectionDialog( list );
dialog.open();
Object[] objs = dialog.getResult();
res = ( objs != null && objs.length > 0 ) ? objs[0] : null;
if ( res != null )
cacheSourceElement( stackFrame, res, dialog.alwaysMapToSelection() );
}
else
res = null;
}
}
if ( res == null ) if ( res == null )
{ {
IStackFrameInfo frameInfo = (IStackFrameInfo)stackFrame.getAdapter( IStackFrameInfo.class ); IStackFrameInfo frameInfo = (IStackFrameInfo)stackFrame.getAdapter( IStackFrameInfo.class );
@ -104,4 +199,60 @@ public class CUISourceLocator implements IAdaptable
CDebugUIPlugin.errorDialog( e.getMessage(), (IStatus)null ); CDebugUIPlugin.errorDialog( e.getMessage(), (IStatus)null );
} }
} }
private SourceSelectionDialog createSourceSelectionDialog( List list )
{
SourceSelectionDialog dialog = new SourceSelectionDialog( CDebugUIPlugin.getActiveWorkbenchShell() );
dialog.setInput( list.toArray() );
dialog.setContentProvider( new ArrayContentProvider() );
dialog.setLabelProvider( new SourceElementLabelProvider() );
dialog.setTitle( "Selection needed" );
dialog.setMessage( "Debugger has found multiple files with the same name.\nPlease select one associated with the selected stack frame." );
dialog.setInitialSelections( new Object[] { list.get( 0 ) } );
return dialog;
}
private void cacheSourceElement( IStackFrame frame, Object sourceElement, boolean alwaysMapToSelection )
{
if ( alwaysMapToSelection )
{
String name = getFileName( frame );
if ( name != null )
{
if ( fNamesToSource == null )
fNamesToSource = new HashMap();
fNamesToSource.put( name, sourceElement );
}
}
else
{
if ( fFramesToSource == null )
fFramesToSource = new HashMap();
fFramesToSource.put( frame, sourceElement );
}
}
private Object cacheLookup( IStackFrame frame )
{
String name = getFileName( frame );
if ( name != null && fNamesToSource != null )
{
Object result = fNamesToSource.get( name );
if ( result != null )
return result;
}
return ( fFramesToSource != null ) ? fFramesToSource.get( frame ) : null;
}
private String getFileName( IStackFrame frame )
{
IStackFrameInfo frameInfo = (IStackFrameInfo)frame.getAdapter( IStackFrameInfo.class );
if ( frameInfo != null )
{
String name = frameInfo.getFile();
if ( name != null && name.trim().length() > 0 )
return name.trim();
}
return null;
}
} }

View file

@ -25,6 +25,7 @@ import org.eclipse.cdt.debug.internal.ui.dialogfields.IDialogFieldListener;
import org.eclipse.cdt.debug.internal.ui.dialogfields.IListAdapter; import org.eclipse.cdt.debug.internal.ui.dialogfields.IListAdapter;
import org.eclipse.cdt.debug.internal.ui.dialogfields.LayoutUtil; import org.eclipse.cdt.debug.internal.ui.dialogfields.LayoutUtil;
import org.eclipse.cdt.debug.internal.ui.dialogfields.ListDialogField; import org.eclipse.cdt.debug.internal.ui.dialogfields.ListDialogField;
import org.eclipse.cdt.debug.internal.ui.dialogfields.SelectionButtonDialogField;
import org.eclipse.cdt.debug.internal.ui.dialogfields.Separator; import org.eclipse.cdt.debug.internal.ui.dialogfields.Separator;
import org.eclipse.cdt.debug.internal.ui.wizards.AddSourceLocationWizard; import org.eclipse.cdt.debug.internal.ui.wizards.AddSourceLocationWizard;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
@ -158,7 +159,7 @@ public class SourceLookupBlock
private Shell fShell = null; private Shell fShell = null;
private CheckedListDialogField fGeneratedSourceListField; private CheckedListDialogField fGeneratedSourceListField;
private SourceListDialogField fAddedSourceListField; private SourceListDialogField fAddedSourceListField;
// private SelectionButtonDialogField fSearchForDuplicateFiles; private SelectionButtonDialogField fSearchForDuplicateFiles;
private ILaunchConfigurationDialog fLaunchConfigurationDialog = null; private ILaunchConfigurationDialog fLaunchConfigurationDialog = null;
private boolean fIsDirty = false; private boolean fIsDirty = false;
private ICSourceLocator fLocator = null; private ICSourceLocator fLocator = null;
@ -228,10 +229,17 @@ public class SourceLookupBlock
fAddedSourceListField.setUpButtonIndex( 2 ); fAddedSourceListField.setUpButtonIndex( 2 );
fAddedSourceListField.setDownButtonIndex( 3 ); fAddedSourceListField.setDownButtonIndex( 3 );
fAddedSourceListField.setRemoveButtonIndex( 5 ); fAddedSourceListField.setRemoveButtonIndex( 5 );
/*
fSearchForDuplicateFiles = new SelectionButtonDialogField( SWT.CHECK ); fSearchForDuplicateFiles = new SelectionButtonDialogField( SWT.CHECK );
fSearchForDuplicateFiles.setLabelText( "Search for duplicate files" ); fSearchForDuplicateFiles.setLabelText( "Search for duplicate source files" );
*/ fSearchForDuplicateFiles.setDialogFieldListener(
new IDialogFieldListener()
{
public void dialogFieldChanged( DialogField field )
{
doCheckStateChanged();
}
} );
} }
public void createControl( Composite parent ) public void createControl( Composite parent )
@ -277,9 +285,9 @@ public class SourceLookupBlock
viewer.setColumnProperties( new String[]{ CP_LOCATION, CP_ASSOCIATION } ); viewer.setColumnProperties( new String[]{ CP_LOCATION, CP_ASSOCIATION } );
viewer.setCellModifier( createCellModifier() ); viewer.setCellModifier( createCellModifier() );
new Separator().doFillIntoGrid( fControl, 3, converter.convertHeightInCharsToPixels( 1 ) ); // new Separator().doFillIntoGrid( fControl, 3, converter.convertHeightInCharsToPixels( 1 ) );
// fSearchForDuplicateFiles.doFillIntoGrid( fControl, 3 ); fSearchForDuplicateFiles.doFillIntoGrid( fControl, 3 );
} }
private ICellModifier createCellModifier() private ICellModifier createCellModifier()
@ -333,6 +341,7 @@ public class SourceLookupBlock
ICSourceLocation[] locations = fLocator.getSourceLocations(); ICSourceLocation[] locations = fLocator.getSourceLocations();
initializeGeneratedLocations( fLocator.getProject(), locations ); initializeGeneratedLocations( fLocator.getProject(), locations );
resetAdditionalLocations( locations ); resetAdditionalLocations( locations );
fSearchForDuplicateFiles.setSelection( fLocator.searchForDuplicateFiles() );
} }
} }
@ -491,6 +500,7 @@ public class SourceLookupBlock
locations = CSourceLocator.getDefaultSourceLocations( getProject() ); locations = CSourceLocator.getDefaultSourceLocations( getProject() );
resetGeneratedLocations( locations ); resetGeneratedLocations( locations );
resetAdditionalLocations( locations ); resetAdditionalLocations( locations );
fSearchForDuplicateFiles.setSelection( false );
} }
public IProject getProject() public IProject getProject()
@ -521,4 +531,9 @@ public class SourceLookupBlock
return locations[i]; return locations[i];
return null; return null;
} }
public boolean searchForDuplicateFiles()
{
return ( fSearchForDuplicateFiles != null ) ? fSearchForDuplicateFiles.isSelected() : false;
}
} }

View file

@ -7,7 +7,6 @@ package org.eclipse.cdt.debug.ui.sourcelookup;
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
import org.eclipse.cdt.debug.core.model.ICDebugTarget; import org.eclipse.cdt.debug.core.model.ICDebugTarget;
import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation;
import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator; import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator;
import org.eclipse.cdt.debug.ui.CDebugUIPlugin; import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
@ -107,7 +106,7 @@ public class SourcePropertyPage extends PropertyPage
{ {
try try
{ {
setSourceLocations( fBlock.getSourceLocations() ); setAttributes( fBlock );
} }
catch( DebugException e ) catch( DebugException e )
{ {
@ -118,7 +117,7 @@ public class SourcePropertyPage extends PropertyPage
return true; return true;
} }
private void setSourceLocations( ICSourceLocation[] locations ) throws DebugException private void setAttributes( SourceLookupBlock block ) throws DebugException
{ {
ICDebugTarget target = getDebugTarget(); ICDebugTarget target = getDebugTarget();
if ( target != null ) if ( target != null )
@ -128,7 +127,8 @@ public class SourcePropertyPage extends PropertyPage
ICSourceLocator locator = (ICSourceLocator)((IAdaptable)target.getLaunch().getSourceLocator()).getAdapter( ICSourceLocator.class ); ICSourceLocator locator = (ICSourceLocator)((IAdaptable)target.getLaunch().getSourceLocator()).getAdapter( ICSourceLocator.class );
if ( locator != null ) if ( locator != null )
{ {
locator.setSourceLocations( locations ); locator.setSourceLocations( block.getSourceLocations() );
locator.setSearchForDuplicateFiles( block.searchForDuplicateFiles() );
if ( target.getLaunch().getSourceLocator() instanceof IPersistableSourceLocator ) if ( target.getLaunch().getSourceLocator() instanceof IPersistableSourceLocator )
{ {
ILaunchConfiguration configuration = target.getLaunch().getLaunchConfiguration(); ILaunchConfiguration configuration = target.getLaunch().getLaunchConfiguration();