[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[cdt-patch] Added the "Search subfolders" option for directory search locations
|
Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.ui/ChangeLog,v
retrieving revision 1.191
diff -u -r1.191 ChangeLog
--- ChangeLog 17 Oct 2003 19:22:54 -0000 1.191
+++ ChangeLog 20 Oct 2003 22:38:08 -0000
@@ -1,3 +1,8 @@
+2003-10-20 Mikhail Khodjaiants
+ Implementation of the "Search subfolders" option for directory source locations.
+ * AddDirectorySourceLocationBlock.java
+ * SourceLookupBlock.java
+
2003-10-17 Mikhail Khodjaiants
UI support of the 'Search for duplicate source files' option.
* icons/full/obj16/prj_file_obj.gif: new
Index: src/org/eclipse/cdt/debug/internal/ui/wizards/AddDirectorySourceLocationBlock.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/wizards/AddDirectorySourceLocationBlock.java,v
retrieving revision 1.2
diff -u -r1.2 AddDirectorySourceLocationBlock.java
--- src/org/eclipse/cdt/debug/internal/ui/wizards/AddDirectorySourceLocationBlock.java 17 Jul 2003 20:24:00 -0000 1.2
+++ src/org/eclipse/cdt/debug/internal/ui/wizards/AddDirectorySourceLocationBlock.java 20 Oct 2003 22:38:12 -0000
@@ -37,6 +37,7 @@
private Text fLocationText = null;
private Text fAssociationText = null;
private Button fAssocitedCheckButton = null;
+ private Button fSearchSubfoldersButton = null;
private Shell fShell = null;
private IPath fInitialAssosciationPath = null;
@@ -59,6 +60,7 @@
createLocationControls( fControl );
createAssociationControls( fControl );
+ createSearchSubfoldersButton( fControl );
setInitialAssociationPath();
}
@@ -146,6 +148,16 @@
fAssociationText.setText( "" );
}
+ protected void createSearchSubfoldersButton( Composite parent )
+ {
+ Composite composite = new Composite( parent, SWT.NONE );
+ composite.setLayout( new GridLayout() );
+ GridData data = new GridData( GridData.FILL_BOTH );
+ composite.setLayoutData( data );
+ fSearchSubfoldersButton = new Button( composite, SWT.CHECK );
+ fSearchSubfoldersButton.setText( "Search sub&folders" );
+ }
+
protected Button createButton( Composite parent, String label )
{
Button button = new Button( parent, SWT.PUSH );
@@ -172,12 +184,17 @@
return "";
}
+ public boolean searchSubfolders()
+ {
+ return ( fSearchSubfoldersButton != null ) ? fSearchSubfoldersButton.getSelection() : false;
+ }
+
public IDirectorySourceLocation getSourceLocation()
{
if ( isLocationPathValid() )
{
Path association = ( isAssociationPathValid() ) ? new Path( getAssociationPath() ) : null;
- return SourceLocationFactory.createDirectorySourceLocation( new Path( getLocationPath() ), association );
+ return SourceLocationFactory.createDirectorySourceLocation( new Path( getLocationPath() ), association, searchSubfolders() );
}
return null;
}
Index: src/org/eclipse/cdt/debug/ui/sourcelookup/SourceLookupBlock.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/sourcelookup/SourceLookupBlock.java,v
retrieving revision 1.13
diff -u -r1.13 SourceLookupBlock.java
--- src/org/eclipse/cdt/debug/ui/sourcelookup/SourceLookupBlock.java 17 Oct 2003 19:22:54 -0000 1.13
+++ src/org/eclipse/cdt/debug/ui/sourcelookup/SourceLookupBlock.java 20 Oct 2003 22:38:12 -0000
@@ -36,6 +36,7 @@
import org.eclipse.jface.viewers.CheckStateChangedEvent;
import org.eclipse.jface.viewers.CheckboxTableViewer;
import org.eclipse.jface.viewers.ColumnWeightData;
+import org.eclipse.jface.viewers.ComboBoxCellEditor;
import org.eclipse.jface.viewers.ICellModifier;
import org.eclipse.jface.viewers.ICheckStateListener;
import org.eclipse.jface.viewers.ILabelProvider;
@@ -94,13 +95,16 @@
table.setHeaderVisible( true );
new TableColumn( table, SWT.NULL );
- tableLayout.addColumnData( new ColumnWeightData( 1, true ) );
+ tableLayout.addColumnData( new ColumnWeightData( 2, true ) );
+ new TableColumn( table, SWT.NULL );
+ tableLayout.addColumnData( new ColumnWeightData( 2, true ) );
new TableColumn( table, SWT.NULL );
tableLayout.addColumnData( new ColumnWeightData( 1, true ) );
TableColumn[] columns = table.getColumns();
columns[0].setText( "Location" );
columns[1].setText( "Association" );
+ columns[2].setText( "Search subfolders" );
return viewer;
}
@@ -147,13 +151,23 @@
return ((IDirectorySourceLocation)element).getAssociation().toOSString();
}
}
+ else if ( columnIndex == 2 )
+ {
+ if ( element instanceof IDirectorySourceLocation )
+ return ( ((IDirectorySourceLocation)element).searchSubfolders() ) ? YES_VALUE : NO_VALUE;
+ }
return "";
}
}
+ // String constants
+ protected static final String YES_VALUE = "yes";
+ protected static final String NO_VALUE = "no";
+
// Column properties
private static final String CP_LOCATION = "location";
private static final String CP_ASSOCIATION = "association";
+ private static final String CP_SEARCH_SUBFOLDERS = "searchSubfolders";
private Composite fControl = null;
private Shell fShell = null;
@@ -280,9 +294,10 @@
TableViewer viewer = fAddedSourceListField.getTableViewer();
Table table = viewer.getTable();
- CellEditor cellEditor = new TextCellEditor( table );
- viewer.setCellEditors( new CellEditor[]{ null, cellEditor } );
- viewer.setColumnProperties( new String[]{ CP_LOCATION, CP_ASSOCIATION } );
+ CellEditor textCellEditor = new TextCellEditor( table );
+ CellEditor comboCellEditor = new ComboBoxCellEditor( table, new String[]{ YES_VALUE, NO_VALUE } );
+ viewer.setCellEditors( new CellEditor[]{ null, textCellEditor, comboCellEditor } );
+ viewer.setColumnProperties( new String[]{ CP_LOCATION, CP_ASSOCIATION, CP_SEARCH_SUBFOLDERS } );
viewer.setCellModifier( createCellModifier() );
// new Separator().doFillIntoGrid( fControl, 3, converter.convertHeightInCharsToPixels( 1 ) );
@@ -296,7 +311,7 @@
{
public boolean canModify( Object element, String property )
{
- return ( element instanceof CDirectorySourceLocation && property.equals( CP_ASSOCIATION ) );
+ return ( element instanceof CDirectorySourceLocation && ( property.equals( CP_ASSOCIATION ) || property.equals( CP_SEARCH_SUBFOLDERS ) ) );
}
public Object getValue( Object element, String property )
@@ -306,20 +321,35 @@
return ( ((CDirectorySourceLocation)element).getAssociation() != null ) ?
((CDirectorySourceLocation)element).getAssociation().toOSString() : "";
}
+ if ( element instanceof CDirectorySourceLocation && property.equals( CP_SEARCH_SUBFOLDERS ) )
+ {
+ return ( ((CDirectorySourceLocation)element).searchSubfolders() ) ? new Integer( 0 ) : new Integer( 1 );
+ }
return null;
}
public void modify( Object element, String property, Object value )
{
Object entry = getSelection();
- if ( entry instanceof CDirectorySourceLocation &&
- property.equals( CP_ASSOCIATION ) &&
- value instanceof String )
+ if ( entry instanceof CDirectorySourceLocation )
{
- Path association = new Path( (String)value );
- if ( association.isValidPath( (String)value ) )
+ boolean changed = false;
+ if ( property.equals( CP_ASSOCIATION ) && value instanceof String )
+ {
+ Path association = new Path( (String)value );
+ if ( association.isValidPath( (String)value ) )
+ {
+ ((CDirectorySourceLocation)entry).setAssociation( association );
+ changed = true;
+ }
+ }
+ if ( property.equals( CP_SEARCH_SUBFOLDERS ) && value instanceof Integer )
+ {
+ ((CDirectorySourceLocation)entry).setSearchSubfolders( ((Integer)value).intValue() == 0 );
+ changed = true;
+ }
+ if ( changed )
{
- ((CDirectorySourceLocation)entry).setAssociation( association );
getAddedSourceListField().refresh();
updateLaunchConfigurationDialog();
}
Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.core/ChangeLog,v
retrieving revision 1.266
diff -u -r1.266 ChangeLog
--- ChangeLog 20 Oct 2003 22:29:41 -0000 1.266
+++ ChangeLog 20 Oct 2003 22:37:41 -0000
@@ -1,4 +1,10 @@
2003-10-20 Mikhail Khodjaiants
+ Core support of the "Search subfolders" option for directory source locations.
+ * IDirectorySourceLocation.java
+ * SourceLocationFactory.java
+ * CDirectorySourceLocation.java
+
+2003-10-20 Mikhail Khodjaiants
Do not interrupt the initialization of all additional source locations
if the initialization of one fails.
* CSourceLocator.java
Index: src/org/eclipse/cdt/debug/core/sourcelookup/IDirectorySourceLocation.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/IDirectorySourceLocation.java,v
retrieving revision 1.1
diff -u -r1.1 IDirectorySourceLocation.java
--- src/org/eclipse/cdt/debug/core/sourcelookup/IDirectorySourceLocation.java 29 Dec 2002 23:55:53 -0000 1.1
+++ src/org/eclipse/cdt/debug/core/sourcelookup/IDirectorySourceLocation.java 20 Oct 2003 22:37:44 -0000
@@ -16,5 +16,8 @@
public interface IDirectorySourceLocation extends ICSourceLocation
{
IPath getDirectory();
+
IPath getAssociation();
+
+ boolean searchSubfolders();
}
Index: src/org/eclipse/cdt/debug/core/sourcelookup/SourceLocationFactory.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/SourceLocationFactory.java,v
retrieving revision 1.1
diff -u -r1.1 SourceLocationFactory.java
--- src/org/eclipse/cdt/debug/core/sourcelookup/SourceLocationFactory.java 17 Jul 2003 20:24:01 -0000 1.1
+++ src/org/eclipse/cdt/debug/core/sourcelookup/SourceLocationFactory.java 20 Oct 2003 22:37:44 -0000
@@ -28,13 +28,8 @@
return new CProjectSourceLocation( project, generated );
}
- public static IDirectorySourceLocation createDirectorySourceLocation( IPath directory )
+ public static IDirectorySourceLocation createDirectorySourceLocation( IPath directory, IPath association, boolean searchSubfolders )
{
- return new CDirectorySourceLocation( directory );
- }
-
- public static IDirectorySourceLocation createDirectorySourceLocation( IPath directory, IPath association )
- {
- return new CDirectorySourceLocation( directory, association );
+ return new CDirectorySourceLocation( directory, association, searchSubfolders );
}
}
Index: src/org/eclipse/cdt/debug/internal/core/sourcelookup/CDirectorySourceLocation.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CDirectorySourceLocation.java,v
retrieving revision 1.15
diff -u -r1.15 CDirectorySourceLocation.java
--- src/org/eclipse/cdt/debug/internal/core/sourcelookup/CDirectorySourceLocation.java 17 Oct 2003 19:23:01 -0000 1.15
+++ src/org/eclipse/cdt/debug/internal/core/sourcelookup/CDirectorySourceLocation.java 20 Oct 2003 22:37:44 -0000
@@ -6,10 +6,14 @@
package org.eclipse.cdt.debug.internal.core.sourcelookup;
import java.io.File;
+import java.io.FileFilter;
import java.io.IOException;
import java.io.StringReader;
import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.LinkedList;
+import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -46,6 +50,7 @@
private static final String ELEMENT_NAME = "cDirectorySourceLocation";
private static final String ATTR_DIRECTORY = "directory";
private static final String ATTR_ASSOCIATION = "association";
+ private static final String ATTR_SEARCH_SUBFOLDERS = "searchSubfolders";
/**
* The root directory of this source location
@@ -59,6 +64,10 @@
private boolean fSearchForDuplicateFiles = false;
+ private boolean fSearchSubfolders = false;
+
+ private File[] fFolders = null;
+
/**
* Constructor for CDirectorySourceLocation.
*/
@@ -69,18 +78,11 @@
/**
* Constructor for CDirectorySourceLocation.
*/
- public CDirectorySourceLocation( IPath directory )
- {
- setDirectory( directory );
- }
-
- /**
- * Constructor for CDirectorySourceLocation.
- */
- public CDirectorySourceLocation( IPath directory, IPath association )
+ public CDirectorySourceLocation( IPath directory, IPath association, boolean searchSubfolders )
{
setDirectory( directory );
setAssociation( association );
+ setSearchSubfolders( searchSubfolders );
}
/* (non-Javadoc)
@@ -163,8 +165,40 @@
File file = new File( name );
if ( !file.isAbsolute() )
return null;
+ File[] folders = getFolders();
+ if ( folders != null )
+ {
+ LinkedList list = new LinkedList();
+ for ( int i = 0; i < folders.length; ++i )
+ {
+ Object result = findFileByAbsolutePath( folders[i], name );
+ if ( result instanceof List )
+ {
+ if ( searchForDuplicateFiles() )
+ list.addAll( (List)result );
+ else
+ return list.getFirst();
+ }
+ else if ( result != null )
+ {
+ if ( searchForDuplicateFiles() )
+ list.add( result );
+ else
+ return result;
+ }
+ }
+ return list;
+ }
+ return null;
+ }
+
+ private Object findFileByAbsolutePath( File folder, String name )
+ {
+ File file = new File( name );
+ if ( !file.isAbsolute() )
+ return null;
IPath filePath = new Path( name );
- IPath path = getDirectory();
+ IPath path = new Path( folder.getAbsolutePath() );
IPath association = getAssociation();
if ( isPrefix( path, filePath ) )
{
@@ -201,27 +235,53 @@
private Object findFileByRelativePath( String fileName )
{
- IPath path = getDirectory();
- if ( path != null )
+ File[] folders = getFolders();
+ if ( folders != null )
{
- path = path.append( fileName );
- File file = path.toFile();
- if ( file.exists() )
+ LinkedList list = new LinkedList();
+ for ( int i = 0; i < folders.length; ++i )
{
- path = new Path( file.getAbsolutePath() ); // can't use getCanonicalPath because of links
- IFile[] wsFiles = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation( path );
- LinkedList list = new LinkedList();
- for ( int j = 0; j < wsFiles.length; ++j )
- if ( wsFiles[j].exists() )
- if ( !searchForDuplicateFiles() )
- return wsFiles[j];
- else
- list.add( wsFiles[j] );
- if ( list.size() > 0 )
- return ( list.size() == 1 ) ? list.getFirst() : list;
- else
- return createExternalFileStorage( path );
+ Object result = findFileByRelativePath( folders[i], fileName );
+ if ( result instanceof List )
+ {
+ if ( searchForDuplicateFiles() )
+ list.addAll( (List)result );
+ else
+ return list.getFirst();
+ }
+ else if ( result != null )
+ {
+ if ( searchForDuplicateFiles() )
+ list.add( result );
+ else
+ return result;
+ }
}
+ return list;
+ }
+ return null;
+ }
+
+ private Object findFileByRelativePath( File folder, String fileName )
+ {
+ IPath path = new Path( folder.getAbsolutePath() );
+ path = path.append( fileName );
+ File file = path.toFile();
+ if ( file.exists() )
+ {
+ path = new Path( file.getAbsolutePath() );
+ IFile[] wsFiles = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation( path );
+ LinkedList list = new LinkedList();
+ for ( int j = 0; j < wsFiles.length; ++j )
+ if ( wsFiles[j].exists() )
+ if ( !searchForDuplicateFiles() )
+ return wsFiles[j];
+ else
+ list.add( wsFiles[j] );
+ if ( list.size() > 0 )
+ return ( list.size() == 1 ) ? list.getFirst() : list;
+ else
+ return createExternalFileStorage( path );
}
return null;
}
@@ -242,6 +302,7 @@
node.setAttribute( ATTR_DIRECTORY, getDirectory().toOSString() );
if ( getAssociation() != null )
node.setAttribute( ATTR_ASSOCIATION, getAssociation().toOSString() );
+ node.setAttribute( ATTR_SEARCH_SUBFOLDERS, new Boolean( searchSubfolders() ).toString() );
try
{
return CDebugUtils.serializeDocument( doc, " " );
@@ -276,7 +337,7 @@
else
{
IPath path = new Path( dir );
- if ( path.isValidPath( dir ) && path.toFile().isDirectory() )
+ if ( path.isValidPath( dir ) && path.toFile().isDirectory() && path.toFile().exists() )
{
setDirectory( path );
}
@@ -302,6 +363,7 @@
setAssociation( null );
}
}
+ setSearchSubfolders( Boolean.valueOf( root.getAttribute( ATTR_SEARCH_SUBFOLDERS ) ).booleanValue() );
return;
}
catch( ParserConfigurationException e )
@@ -384,5 +446,60 @@
public boolean searchForDuplicateFiles()
{
return fSearchForDuplicateFiles;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.debug.core.sourcelookup.IDirectorySourceLocation#searchSubfolders()
+ */
+ public boolean searchSubfolders()
+ {
+ return fSearchSubfolders;
+ }
+
+ public void setSearchSubfolders( boolean search )
+ {
+ fSearchSubfolders = search;
+ }
+
+ protected File[] getFolders()
+ {
+ if ( fFolders == null )
+ initializeFolders();
+ return fFolders;
+ }
+
+ protected void resetFolders()
+ {
+ fFolders = null;
+ }
+
+ private void initializeFolders()
+ {
+ if ( getDirectory() != null )
+ {
+ ArrayList list = new ArrayList();
+ File root = getDirectory().toFile();
+ list.add( root );
+ if ( searchSubfolders() )
+ list.addAll( getFileFolders( root ) );
+ fFolders = (File[])list.toArray( new File[list.size()] );
+ }
+ }
+
+ private List getFileFolders( File file )
+ {
+ ArrayList list = new ArrayList();
+ File[] folders = file.listFiles(
+ new FileFilter()
+ {
+ public boolean accept( File pathname )
+ {
+ return pathname.isDirectory();
+ }
+ } );
+ list.addAll( Arrays.asList( folders ) );
+ for ( int i = 0; i < folders.length; ++i )
+ list.addAll( getFileFolders( folders[i] ) );
+ return list;
}
}