diff --git a/debug/org.eclipse.cdt.debug.core/ChangeLog b/debug/org.eclipse.cdt.debug.core/ChangeLog index 71416382bcc..13ec9fee511 100644 --- a/debug/org.eclipse.cdt.debug.core/ChangeLog +++ b/debug/org.eclipse.cdt.debug.core/ChangeLog @@ -1,3 +1,14 @@ +2005-04-25 Mikhail Khodjaiants + Added the new source container type (CDirectorySourceContainer) to provide + the UI support for the subfolders search. + + CDirectorySourceContainer.java + + CDirectorySourceContainerType.java + * CSourceLookupDirector.java + * SourceUtils.java + * InternalSourceLookupMessages.properties + * plugin.properties + * plugin.xml + 2005-04-25 Alain Magloire Changes to the CDI interface. + cdi/org/eclipse/cdt/debug/core/cdi/ICDIAddressLocation.java diff --git a/debug/org.eclipse.cdt.debug.core/plugin.properties b/debug/org.eclipse.cdt.debug.core/plugin.properties index 9081fdc6313..e850ada9d4d 100644 --- a/debug/org.eclipse.cdt.debug.core/plugin.properties +++ b/debug/org.eclipse.cdt.debug.core/plugin.properties @@ -21,4 +21,6 @@ cWatchpoints.name=C/C++ Watchpoints containerName.mapping=Path Mapping containerDescription.mapping=A path mapping. containerName.mapEntry=Path Map Entry -containerDescription.mapEntry=An entry in a path mapping. \ No newline at end of file +containerDescription.mapEntry=An entry in a path mapping. +containerName.directory=Directory +containerDescription.directory=A directory in the local file system diff --git a/debug/org.eclipse.cdt.debug.core/plugin.xml b/debug/org.eclipse.cdt.debug.core/plugin.xml index 6743a70ff96..11ed8c34fe2 100644 --- a/debug/org.eclipse.cdt.debug.core/plugin.xml +++ b/debug/org.eclipse.cdt.debug.core/plugin.xml @@ -171,6 +171,11 @@ description="%containerDescription.mapEntry" id="org.eclipse.cdt.debug.core.containerType.mapEntry" name="%containerName.mapEntry"/> + diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/CDirectorySourceContainer.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/CDirectorySourceContainer.java new file mode 100644 index 00000000000..147af70c78c --- /dev/null +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/CDirectorySourceContainer.java @@ -0,0 +1,178 @@ +/********************************************************************** + * Copyright (c) 2004 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + ***********************************************************************/ +package org.eclipse.cdt.debug.core.sourcelookup; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import org.eclipse.cdt.debug.core.CDebugCorePlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.debug.core.sourcelookup.ISourceContainer; +import org.eclipse.debug.core.sourcelookup.ISourceContainerType; +import org.eclipse.debug.core.sourcelookup.containers.CompositeSourceContainer; +import org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage; + +/** + * It is not supposed to subclass DirectorySourceContainer, but we need to use + * the different browser. + */ +public class CDirectorySourceContainer extends CompositeSourceContainer { + + /** + * Unique identifier for the CDT directory source container type + * (value org.eclipse.cdt.debug.core.containerType.directory). + */ + public static final String TYPE_ID = CDebugCorePlugin.getUniqueIdentifier() + ".containerType.directory"; //$NON-NLS-1$ + + // root directory + private File fDirectory; + // whether to search subfolders + private boolean fSubfolders = false; + + /** + * Consutructs an external folder container for the + * directory identified by the given path. + * + * @param dirPath path to a directory in the local file system + * @param subfolders whether folders within the root directory + * should be searched for source elements + */ + public CDirectorySourceContainer( IPath dirPath, boolean subfolders ) { + this( dirPath.toFile(), subfolders ); + } + + /** + * Consutructs an external folder container for the + * directory identified by the given file. + * + * @param dir a directory in the local file system + * @param subfolders whether folders within the root directory + * should be searched for source elements + */ + public CDirectorySourceContainer( File dir, boolean subfolders ) { + fDirectory = dir; + fSubfolders = subfolders; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.core.sourcelookup.ISourceContainer#getName() + */ + public String getName() { + return fDirectory.getName(); + } + + /** + * Returns the root directory in the local file system associated + * with this source container. + * + * @return the root directory in the local file system associated + * with this source container + */ + public File getDirectory() { + return fDirectory; + } + + public boolean searchSubfolders() { + return fSubfolders; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.core.sourcelookup.ISourceContainer#getType() + */ + public ISourceContainerType getType() { + return getSourceContainerType( TYPE_ID ); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.core.sourcelookup.ISourceContainer#findSourceElements(java.lang.String) + */ + public Object[] findSourceElements( String name ) throws CoreException { + ArrayList sources = new ArrayList(); + File directory = getDirectory(); + File file = new File( directory, name ); + if ( file.exists() && file.isFile() ) { + sources.add( new LocalFileStorage( file ) ); + } + // check subfolders + if ( (isFindDuplicates() && fSubfolders) || (sources.isEmpty() && fSubfolders) ) { + ISourceContainer[] containers = getSourceContainers(); + for( int i = 0; i < containers.length; i++ ) { + Object[] objects = containers[i].findSourceElements( name ); + if ( objects == null || objects.length == 0 ) { + continue; + } + if ( isFindDuplicates() ) { + for( int j = 0; j < objects.length; j++ ) + sources.add( objects[j] ); + } + else { + sources.add( objects[0] ); + break; + } + } + } + if ( sources.isEmpty() ) + return EMPTY; + return sources.toArray(); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.core.sourcelookup.ISourceContainer#isComposite() + */ + public boolean isComposite() { + return fSubfolders; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + public boolean equals( Object obj ) { + if ( obj instanceof CDirectorySourceContainer ) { + CDirectorySourceContainer container = (CDirectorySourceContainer)obj; + return container.getDirectory().equals( getDirectory() ); + } + return false; + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + public int hashCode() { + return getDirectory().hashCode(); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.core.sourcelookup.containers.CompositeSourceContainer#createSourceContainers() + */ + protected ISourceContainer[] createSourceContainers() throws CoreException { + if ( isComposite() ) { + String[] files = fDirectory.list(); + if ( files != null ) { + List dirs = new ArrayList(); + for( int i = 0; i < files.length; i++ ) { + String name = files[i]; + File file = new File( getDirectory(), name ); + if ( file.exists() && file.isDirectory() ) { + dirs.add( new CDirectorySourceContainer( file, true ) ); + } + } + ISourceContainer[] containers = (ISourceContainer[])dirs.toArray( new ISourceContainer[dirs.size()] ); + for( int i = 0; i < containers.length; i++ ) { + ISourceContainer container = containers[i]; + container.init( getDirector() ); + } + return containers; + } + } + return new ISourceContainer[0]; + } +} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CDirectorySourceContainerType.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CDirectorySourceContainerType.java new file mode 100644 index 00000000000..381716eb93b --- /dev/null +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CDirectorySourceContainerType.java @@ -0,0 +1,65 @@ +/********************************************************************** + * Copyright (c) 2004 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + ***********************************************************************/ +package org.eclipse.cdt.debug.internal.core.sourcelookup; + +import org.eclipse.cdt.debug.core.sourcelookup.CDirectorySourceContainer; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.Path; +import org.eclipse.debug.core.sourcelookup.ISourceContainer; +import org.eclipse.debug.core.sourcelookup.containers.AbstractSourceContainerTypeDelegate; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +/** + * See CDirectorySourceContainer. + */ +public class CDirectorySourceContainerType extends AbstractSourceContainerTypeDelegate { + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.core.sourcelookup.ISourceContainerType#createSourceContainer(java.lang.String) + */ + public ISourceContainer createSourceContainer( String memento ) throws CoreException { + Node node = parseDocument( memento ); + if ( node.getNodeType() == Node.ELEMENT_NODE ) { + Element element = (Element)node; + if ( "directory".equals( element.getNodeName() ) ) { //$NON-NLS-1$ + String string = element.getAttribute( "path" ); //$NON-NLS-1$ + if ( string == null || string.length() == 0 ) { + abort( InternalSourceLookupMessages.getString( "CDirectorySourceContainerType.0" ), null ); //$NON-NLS-1$ + } + String nest = element.getAttribute( "nest" ); //$NON-NLS-1$ + boolean nested = "true".equals( nest ); //$NON-NLS-1$ + return new CDirectorySourceContainer( new Path( string ), nested ); + } + abort( InternalSourceLookupMessages.getString( "CDirectorySourceContainerType.1" ), null ); //$NON-NLS-1$ + } + abort( InternalSourceLookupMessages.getString( "CDirectorySourceContainerType.2" ), null ); //$NON-NLS-1$ + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.core.sourcelookup.ISourceContainerType#getMemento(org.eclipse.debug.internal.core.sourcelookup.ISourceContainer) + */ + public String getMemento( ISourceContainer container ) throws CoreException { + CDirectorySourceContainer folder = (CDirectorySourceContainer)container; + Document document = newDocument(); + Element element = document.createElement( "directory" ); //$NON-NLS-1$ + element.setAttribute( "path", folder.getDirectory().getAbsolutePath() ); //$NON-NLS-1$ + String nest = "false"; //$NON-NLS-1$ + if ( folder.isComposite() ) { + nest = "true"; //$NON-NLS-1$ + } + element.setAttribute( "nest", nest ); //$NON-NLS-1$ + document.appendChild( element ); + return serializeDocument( document ); + } +} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLookupDirector.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLookupDirector.java index 44cd297cf41..032bafce2bc 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLookupDirector.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLookupDirector.java @@ -12,6 +12,7 @@ package org.eclipse.cdt.debug.internal.core.sourcelookup; import java.util.HashSet; import java.util.Set; +import org.eclipse.cdt.debug.core.sourcelookup.CDirectorySourceContainer; import org.eclipse.cdt.debug.core.sourcelookup.MappingSourceContainer; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; @@ -20,7 +21,6 @@ import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupDirector; import org.eclipse.debug.core.sourcelookup.ISourceContainer; import org.eclipse.debug.core.sourcelookup.ISourceContainerType; import org.eclipse.debug.core.sourcelookup.ISourceLookupParticipant; -import org.eclipse.debug.core.sourcelookup.containers.DirectorySourceContainer; import org.eclipse.debug.core.sourcelookup.containers.FolderSourceContainer; import org.eclipse.debug.core.sourcelookup.containers.ProjectSourceContainer; import org.eclipse.debug.core.sourcelookup.containers.WorkspaceSourceContainer; @@ -30,15 +30,15 @@ import org.eclipse.debug.core.sourcelookup.containers.WorkspaceSourceContainer; */ public class CSourceLookupDirector extends AbstractSourceLookupDirector { - private static Set fFilteredTypes; + private static Set fSupportedTypes; static { - fFilteredTypes = new HashSet(); - fFilteredTypes.add( WorkspaceSourceContainer.TYPE_ID ); - fFilteredTypes.add( ProjectSourceContainer.TYPE_ID ); - fFilteredTypes.add( FolderSourceContainer.TYPE_ID ); - fFilteredTypes.add( DirectorySourceContainer.TYPE_ID ); - fFilteredTypes.add( MappingSourceContainer.TYPE_ID ); + fSupportedTypes = new HashSet(); + fSupportedTypes.add( WorkspaceSourceContainer.TYPE_ID ); + fSupportedTypes.add( ProjectSourceContainer.TYPE_ID ); + fSupportedTypes.add( FolderSourceContainer.TYPE_ID ); + fSupportedTypes.add( CDirectorySourceContainer.TYPE_ID ); + fSupportedTypes.add( MappingSourceContainer.TYPE_ID ); } /* (non-Javadoc) @@ -51,7 +51,7 @@ public class CSourceLookupDirector extends AbstractSourceLookupDirector { * @see org.eclipse.debug.core.sourcelookup.ISourceLookupDirector#supportsSourceContainerType(org.eclipse.debug.core.sourcelookup.ISourceContainerType) */ public boolean supportsSourceContainerType( ISourceContainerType type ) { - return fFilteredTypes.contains( type.getId() ); + return fSupportedTypes.contains( type.getId() ); } public boolean contains( IProject project ) { diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/InternalSourceLookupMessages.properties b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/InternalSourceLookupMessages.properties index 64993e5d1fb..8df38c1db21 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/InternalSourceLookupMessages.properties +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/InternalSourceLookupMessages.properties @@ -13,6 +13,9 @@ CDirectorySourceLocation.0=Unable to create memento for C/C++ directory source l CDirectorySourceLocation.1=Unable to initialize source location - missing directory path. CDirectorySourceLocation.2=Unable to initialize source location - invalid directory path {0}. CDirectorySourceLocation.3=Exception occurred initializing source location. +CDirectorySourceContainerType.0=Unable to restore directory source lookup entry - missing path attribute. +CDirectorySourceContainerType.1=Unable to restore directory source lookup entry - expecting directory element. +CDirectorySourceContainerType.2=Unable to restore directory source lookup entry - invalid memento. CProjectSourceLocation.0=Unable to create memento for C/C++ project source location {0}. CProjectSourceLocation.1=Unable to initialize source location - missing project name CProjectSourceLocation.2=Exception occurred initializing source location. diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/SourceUtils.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/SourceUtils.java index 63a8047a867..9e692f92a12 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/SourceUtils.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/SourceUtils.java @@ -22,6 +22,7 @@ import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.TransformerException; import org.eclipse.cdt.debug.core.CDebugCorePlugin; import org.eclipse.cdt.debug.core.CDebugUtils; +import org.eclipse.cdt.debug.core.sourcelookup.CDirectorySourceContainer; import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation; import org.eclipse.cdt.debug.core.sourcelookup.IDirectorySourceLocation; import org.eclipse.cdt.debug.core.sourcelookup.IProjectSourceLocation; @@ -31,7 +32,6 @@ import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.debug.core.sourcelookup.ISourceContainer; -import org.eclipse.debug.core.sourcelookup.containers.DirectorySourceContainer; import org.eclipse.debug.core.sourcelookup.containers.ProjectSourceContainer; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -181,7 +181,7 @@ public class SourceUtils { containers.add( mapping ); } - containers.add( new DirectorySourceContainer( d.getDirectory(), d.searchSubfolders() ) ); + containers.add( new CDirectorySourceContainer( d.getDirectory(), d.searchSubfolders() ) ); } } return (ISourceContainer[])containers.toArray( new ISourceContainer[containers.size()] ); diff --git a/debug/org.eclipse.cdt.debug.ui/ChangeLog b/debug/org.eclipse.cdt.debug.ui/ChangeLog index 44c759da5e5..5a058d0f517 100644 --- a/debug/org.eclipse.cdt.debug.ui/ChangeLog +++ b/debug/org.eclipse.cdt.debug.ui/ChangeLog @@ -1,3 +1,13 @@ +2005-04-25 Mikhail Khodjaiants + Added the new source container type (CDirectorySourceContainer) to provide + the UI support for the subfolders search. + * ICDebugHelpContextIds.java + + CDirectorySourceContainerBrowser.java + + CDirectorySourceContainerDialog.java + * SourceContainerWorkbenchAdapter.java + * SourceLookupUIMessages.properties + * plugin.xml + 2005-04-22 Mikhail Khodjaiants Initalize the particiapants of the source lookup director when converting from an old memento. diff --git a/debug/org.eclipse.cdt.debug.ui/plugin.xml b/debug/org.eclipse.cdt.debug.ui/plugin.xml index 65dd734d88a..4ed51419fff 100644 --- a/debug/org.eclipse.cdt.debug.ui/plugin.xml +++ b/debug/org.eclipse.cdt.debug.ui/plugin.xml @@ -1145,6 +1145,11 @@ adaptableType="org.eclipse.debug.core.sourcelookup.containers.ProjectSourceContainer" class="org.eclipse.cdt.debug.internal.ui.sourcelookup.SourceContainerAdapterFactory"> + + + @@ -1199,6 +1204,11 @@ containerTypeID="org.eclipse.cdt.debug.core.containerType.mapEntry" icon="icons/obj16/mapentry_obj.gif" id="org.eclipse.cdt.debug.ui.sourceContainerPresentation.mapEntry"/> + diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/ICDebugHelpContextIds.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/ICDebugHelpContextIds.java index d06781259bd..4bc6d720ac1 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/ICDebugHelpContextIds.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/ICDebugHelpContextIds.java @@ -67,4 +67,5 @@ public interface ICDebugHelpContextIds public static final String SOURCE_PATH_MAPPING_DIALOG = PREFIX + "source_path_mapping_dialog_context"; //$NON-NLS-1$ public static final String SOURCE_PATH_MAP_ENTRY_DIALOG = PREFIX + "source_path_map_entry_dialog_context"; //$NON-NLS-1$ public static final String ADD_SOURCE_CONTAINER_DIALOG = PREFIX + "add_source_container_dialog"; //$NON-NLS-1$ + public static final String ADD_DIRECTORY_CONTAINER_DIALOG = PREFIX + "add_directory_container_dialog"; //$NON-NLS-1$ } diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/sourcelookup/CDirectorySourceContainerBrowser.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/sourcelookup/CDirectorySourceContainerBrowser.java new file mode 100644 index 00000000000..5c873716b64 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/sourcelookup/CDirectorySourceContainerBrowser.java @@ -0,0 +1,42 @@ +/********************************************************************** + * Copyright (c) 2004 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + ***********************************************************************/ +package org.eclipse.cdt.debug.internal.ui.sourcelookup; + +import org.eclipse.cdt.debug.core.sourcelookup.CDirectorySourceContainer; +import org.eclipse.debug.core.sourcelookup.ISourceContainer; +import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector; +import org.eclipse.debug.ui.sourcelookup.AbstractSourceContainerBrowser; +import org.eclipse.jface.window.Window; +import org.eclipse.swt.widgets.Shell; + +/** + * The browser for adding and editing a directory source container. + */ +public class CDirectorySourceContainerBrowser extends AbstractSourceContainerBrowser { + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.sourcelookup.AbstractSourceContainerBrowser#addSourceContainers(org.eclipse.swt.widgets.Shell, org.eclipse.debug.core.sourcelookup.ISourceLookupDirector) + */ + public ISourceContainer[] addSourceContainers( Shell shell, ISourceLookupDirector director ) { + CDirectorySourceContainerDialog dialog = new CDirectorySourceContainerDialog( shell ); + if ( dialog.open() == Window.OK ) { + return new ISourceContainer[] { new CDirectorySourceContainer( dialog.getDirectory(), dialog.isSearchSubfolders() ) }; + } + return new ISourceContainer[0]; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.sourcelookup.AbstractSourceContainerBrowser#canAddSourceContainers(org.eclipse.debug.core.sourcelookup.ISourceLookupDirector) + */ + public boolean canAddSourceContainers( ISourceLookupDirector director ) { + return true; + } +} diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/sourcelookup/CDirectorySourceContainerDialog.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/sourcelookup/CDirectorySourceContainerDialog.java new file mode 100644 index 00000000000..93fc0390778 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/sourcelookup/CDirectorySourceContainerDialog.java @@ -0,0 +1,158 @@ +/********************************************************************** + * Copyright (c) 2004 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + ***********************************************************************/ +package org.eclipse.cdt.debug.internal.ui.sourcelookup; + +import java.io.File; +import org.eclipse.cdt.debug.internal.ui.ICDebugHelpContextIds; +import org.eclipse.cdt.debug.internal.ui.PixelConverter; +import org.eclipse.cdt.debug.internal.ui.dialogfields.DialogField; +import org.eclipse.cdt.debug.internal.ui.dialogfields.IDialogFieldListener; +import org.eclipse.cdt.debug.internal.ui.dialogfields.IStringButtonAdapter; +import org.eclipse.cdt.debug.internal.ui.dialogfields.LayoutUtil; +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.StringButtonDialogField; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.TitleAreaDialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.DirectoryDialog; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.PlatformUI; + +/** + * The dialog for selecting the local file system for which a source + * container will be created. + */ +public class CDirectorySourceContainerDialog extends TitleAreaDialog { + + private StringButtonDialogField fDirectoryField; + private SelectionButtonDialogField fSubfoldersField; + private File fDirectory; + private boolean fSearchSubfolders; + + /** + * Constructor for CDirectorySourceContainerDialog. + */ + public CDirectorySourceContainerDialog( Shell parentShell ) { + this( parentShell, new File( "" ), false ); //$NON-NLS-1$ + } + + /** + * Constructor for CDirectorySourceContainerDialog. + */ + public CDirectorySourceContainerDialog( Shell parentShell, File directory, boolean searchSubfolders ) { + super( parentShell ); + fDirectory = directory; + fSearchSubfolders = searchSubfolders; + fDirectoryField = new StringButtonDialogField( + new IStringButtonAdapter() { + + public void changeControlPressed( DialogField field ) { + browse(); + } + } ); + fDirectoryField.setLabelText( SourceLookupUIMessages.getString( "CDirectorySourceContainerDialog.0" ) ); //$NON-NLS-1$ + fDirectoryField.setButtonLabel( SourceLookupUIMessages.getString( "CDirectorySourceContainerDialog.1" ) ); //$NON-NLS-1$ + fDirectoryField.setDialogFieldListener( + new IDialogFieldListener() { + + public void dialogFieldChanged( DialogField field ) { + // TODO Auto-generated method stub + + } + } ); + + fSubfoldersField = new SelectionButtonDialogField( SWT.CHECK ); + fSubfoldersField.setLabelText( SourceLookupUIMessages.getString( "CDirectorySourceContainerDialog.2" ) ); //$NON-NLS-1$ + } + + /* (non-Javadoc) + * @see org.eclipse.jface.dialogs.TitleAreaDialog#createDialogArea(org.eclipse.swt.widgets.Composite) + */ + protected Control createDialogArea( Composite parent ) { + setTitle( SourceLookupUIMessages.getString( "CDirectorySourceContainerDialog.3" ) ); //$NON-NLS-1$ + Font font = parent.getFont(); + Composite composite = new Composite( parent, SWT.NONE ); + GridLayout layout = new GridLayout(); + layout.numColumns = Math.max( fDirectoryField.getNumberOfControls(), fSubfoldersField.getNumberOfControls() ); + layout.marginHeight = convertVerticalDLUsToPixels( IDialogConstants.VERTICAL_MARGIN ); + layout.marginWidth = convertHorizontalDLUsToPixels( IDialogConstants.HORIZONTAL_MARGIN ); +// layout.verticalSpacing = convertVerticalDLUsToPixels( IDialogConstants.VERTICAL_SPACING ); +// layout.horizontalSpacing = convertHorizontalDLUsToPixels( IDialogConstants.HORIZONTAL_SPACING ); + composite.setLayout( layout ); + GridData data = new GridData( GridData.FILL_BOTH ); + composite.setLayoutData( data ); + composite.setFont( font ); + + Dialog.applyDialogFont( composite ); + PlatformUI.getWorkbench().getHelpSystem().setHelp( getShell(), ICDebugHelpContextIds.ADD_DIRECTORY_CONTAINER_DIALOG ); + + PixelConverter converter = new PixelConverter( composite ); + fDirectoryField.doFillIntoGrid( composite, layout.numColumns ); + LayoutUtil.setHorizontalGrabbing( fDirectoryField.getTextControl( null ) ); + + new Separator().doFillIntoGrid( composite, layout.numColumns, converter.convertHeightInCharsToPixels( 1 ) ); + + fSubfoldersField.doFillIntoGrid( composite, layout.numColumns ); + + initialize(); + + setMessage( null ); + return super.createDialogArea( parent ); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) + */ + protected void configureShell( Shell newShell ) { + newShell.setText( SourceLookupUIMessages.getString( "CDirectorySourceContainerDialog.4" ) ); //$NON-NLS-1$ + super.configureShell( newShell ); + } + + protected void browse() { + String last = fDirectoryField.getText(); + DirectoryDialog dialog = new DirectoryDialog( getShell(), SWT.SINGLE ); + dialog.setFilterPath( last ); + String result = dialog.open(); + if ( result == null ) { + return; + } + fDirectoryField.setText( result ); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.dialogs.Dialog#okPressed() + */ + protected void okPressed() { + fDirectory = new File( fDirectoryField.getText() ); + fSearchSubfolders = fSubfoldersField.isSelected(); + super.okPressed(); + } + + public File getDirectory() { + return fDirectory; + } + + public boolean isSearchSubfolders() { + return fSearchSubfolders; + } + + private void initialize() { + fDirectoryField.setText( getDirectory().getPath() ); + fSubfoldersField.setSelection( isSearchSubfolders() ); + } +} diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/sourcelookup/SourceContainerWorkbenchAdapter.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/sourcelookup/SourceContainerWorkbenchAdapter.java index 47942de407d..dca50e9b6a9 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/sourcelookup/SourceContainerWorkbenchAdapter.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/sourcelookup/SourceContainerWorkbenchAdapter.java @@ -10,13 +10,17 @@ ***********************************************************************/ package org.eclipse.cdt.debug.internal.ui.sourcelookup; +import java.io.File; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.debug.core.sourcelookup.CDirectorySourceContainer; import org.eclipse.cdt.debug.core.sourcelookup.MappingSourceContainer; import org.eclipse.cdt.debug.internal.core.sourcelookup.MapEntrySourceContainer; import org.eclipse.cdt.debug.internal.ui.CDebugImages; import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; import org.eclipse.debug.core.sourcelookup.containers.ProjectSourceContainer; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.ui.model.IWorkbenchAdapter; @@ -64,6 +68,12 @@ public class SourceContainerWorkbenchAdapter implements IWorkbenchAdapter { * @see org.eclipse.ui.model.IWorkbenchAdapter#getLabel(java.lang.Object) */ public String getLabel( Object o ) { + if ( o instanceof CDirectorySourceContainer ) { + CDirectorySourceContainer container = (CDirectorySourceContainer)o; + File file = container.getDirectory(); + IPath path = new Path( file.getAbsolutePath() ); + return getQualifiedName( path ); + } if ( o instanceof MappingSourceContainer ) { return SourceLookupUIMessages.getString( "SourceContainerWorkbenchAdapter.0" ) + ((MappingSourceContainer)o).getName(); //$NON-NLS-1$ } @@ -79,4 +89,24 @@ public class SourceContainerWorkbenchAdapter implements IWorkbenchAdapter { public Object getParent( Object o ) { return null; } + + public String getQualifiedName( IPath path ) { + StringBuffer buffer = new StringBuffer(); + String[] segments = path.segments(); + if ( segments.length > 0 ) { + buffer.append( path.lastSegment() ); + if ( segments.length > 1 ) { + buffer.append( " - " ); //$NON-NLS-1$ + if ( path.getDevice() != null ) { + buffer.append( path.getDevice() ); + } + for( int i = 0; i < segments.length - 1; i++ ) { + buffer.append( File.separatorChar ); + buffer.append( segments[i] ); + } + } + return buffer.toString(); + } + return ""; //$NON-NLS-1$ + } } 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 0338d993b41..bd84047dece 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 @@ -24,3 +24,8 @@ PathMappingDialog.16=Path Mappings RemoveAction.0=Re&move SourceContainerWorkbenchAdapter.0=Path Mapping: UpAction.0=U&p +CDirectorySourceContainerDialog.0=&Directory: +CDirectorySourceContainerDialog.1=&Browse... +CDirectorySourceContainerDialog.2=Search sub&folders +CDirectorySourceContainerDialog.3=Choose directory to add: +CDirectorySourceContainerDialog.4=Directory Selection