diff options
Diffstat (limited to 'debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/preferences')
3 files changed, 127 insertions, 164 deletions
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/preferences/CDebugPreferencePage.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/preferences/CDebugPreferencePage.java index e8a220bd7c6..cbc865f945b 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/preferences/CDebugPreferencePage.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/preferences/CDebugPreferencePage.java @@ -20,10 +20,8 @@ import org.eclipse.cdt.debug.ui.CDebugUIPlugin; import org.eclipse.cdt.utils.ui.controls.ControlFactory; import org.eclipse.debug.ui.IDebugUIConstants; import org.eclipse.debug.ui.IDebugView; -import org.eclipse.jface.dialogs.DialogPage; import org.eclipse.jface.preference.ColorFieldEditor; import org.eclipse.jface.preference.FieldEditor; -import org.eclipse.jface.preference.IPreferencePage; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.IntegerFieldEditor; import org.eclipse.jface.preference.PreferenceConverter; @@ -186,8 +184,8 @@ public class CDebugPreferencePage extends PreferencePage implements IWorkbenchPr PreferenceConverter.setDefault( store, IInternalCDebugUIConstants.DISASSEMBLY_SOURCE_LINE_COLOR, IInternalCDebugUIConstants.DEFAULT_DISASSEMBLY_SOURCE_LINE_RGB ); } - /** - * @see DialogPage#dispose() + /* (non-Javadoc) + * @see org.eclipse.jface.dialogs.IDialogPage#dispose() */ public void dispose() { super.dispose(); @@ -274,8 +272,8 @@ public class CDebugPreferencePage extends PreferencePage implements IWorkbenchPr label.setLayoutData( gd ); } - /** - * @see IPreferencePage#performOk() Also, notifies interested listeners + /* (non-Javadoc) + * @see org.eclipse.jface.preference.IPreferencePage#performOk() */ public boolean performOk() { storeValues(); diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/preferences/PreferenceMessages.properties b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/preferences/PreferenceMessages.properties index 40296cbbc26..16ec1a7249c 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/preferences/PreferenceMessages.properties +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/preferences/PreferenceMessages.properties @@ -22,6 +22,5 @@ CDebugPreferencePage.10=Default register format: CDebugPreferencePage.11=Disassembly options CDebugPreferencePage.12=Maximum number of displayed instructions: CDebugPreferencePage.13=The valid value range is [{0},{1}]. -SourcePreferencePage.0=Common source lookup settings. -SourcePreferencePage.1=Source Locations -SourcePreferencePage.2=Search for duplicate source files +SourcePreferencePage.0=Common source lookup path settings. +SourcePreferencePage.0=S&ource Lookup Path: diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/preferences/SourcePreferencePage.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/preferences/SourcePreferencePage.java index d7a411d5eb5..968d39720a3 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/preferences/SourcePreferencePage.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/preferences/SourcePreferencePage.java @@ -1,90 +1,115 @@ /********************************************************************** * Copyright (c) 2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials + * 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: + * + * Contributors: * QNX Software Systems - Initial API and implementation - ***********************************************************************/ -package org.eclipse.cdt.debug.internal.ui.preferences; + ***********************************************************************/ +package org.eclipse.cdt.debug.internal.ui.preferences; -import java.util.Arrays; -import java.util.Observable; -import java.util.Observer; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; import org.eclipse.cdt.debug.core.CDebugCorePlugin; -import org.eclipse.cdt.debug.core.ICDebugConstants; -import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation; 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.IListAdapter; -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.wizards.AddSourceLocationWizard; -import org.eclipse.cdt.debug.ui.CDebugUIPlugin; -import org.eclipse.cdt.debug.ui.sourcelookup.SourceListDialogField; +import org.eclipse.cdt.debug.internal.ui.sourcelookup.AddContainerAction; +import org.eclipse.cdt.debug.internal.ui.sourcelookup.DownAction; +import org.eclipse.cdt.debug.internal.ui.sourcelookup.EditContainerAction; +import org.eclipse.cdt.debug.internal.ui.sourcelookup.RemoveAction; +import org.eclipse.cdt.debug.internal.ui.sourcelookup.SourceContainerAction; +import org.eclipse.cdt.debug.internal.ui.sourcelookup.SourceContainerViewer; +import org.eclipse.cdt.debug.internal.ui.sourcelookup.UpAction; +import org.eclipse.debug.core.sourcelookup.ISourceContainer; +import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.preference.PreferencePage; -import org.eclipse.jface.resource.JFaceResources; -import org.eclipse.jface.window.Window; -import org.eclipse.jface.wizard.WizardDialog; import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.FontMetrics; +import org.eclipse.swt.graphics.GC; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; /** - * The "Source Code Locations" preference page. + * The "Source Lookup Path" preference page. */ -public class SourcePreferencePage extends PreferencePage implements IWorkbenchPreferencePage, Observer { +public class SourcePreferencePage extends PreferencePage implements IWorkbenchPreferencePage { + private SourceContainerViewer fPathViewer; + private List fActions = new ArrayList(6); private IWorkbench fWorkbench; + private AddContainerAction fAddAction; + private EditContainerAction fEditAction; - private SourceListDialogField fSourceListField; - - private SelectionButtonDialogField fSearchForDuplicateFiles; - - private boolean fChanged = false; - - public SourcePreferencePage() { - super(); - setPreferenceStore( CDebugUIPlugin.getDefault().getPreferenceStore() ); - setDescription( PreferenceMessages.getString( "SourcePreferencePage.0" ) ); //$NON-NLS-1$ - } - - /* - * (non-Javadoc) - * + /* (non-Javadoc) * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite) */ protected Control createContents( Composite parent ) { - getWorkbench().getHelpSystem().setHelp( getControl(), ICDebugHelpContextIds.SOURCE_PREFERENCE_PAGE ); - fSourceListField = createSourceListField(); - fSearchForDuplicateFiles = createSearchForDuplicateFilesButton(); - Composite control = new Composite( parent, SWT.NONE ); - GridLayout layout = new GridLayout(); - layout.numColumns = 2; - layout.marginWidth = 5; - layout.marginHeight = 5; - control.setLayout( layout ); - GridData data = new GridData(); - data.verticalAlignment = GridData.FILL; - data.horizontalAlignment = GridData.FILL; - control.setLayoutData( data ); - control.setFont( JFaceResources.getDialogFont() ); - PixelConverter converter = new PixelConverter( control ); - fSourceListField.doFillIntoGrid( control, 3 ); - LayoutUtil.setHorizontalSpan( fSourceListField.getLabelControl( null ), 2 ); - LayoutUtil.setWidthHint( fSourceListField.getLabelControl( null ), converter.convertWidthInCharsToPixels( 40 ) ); - LayoutUtil.setHorizontalGrabbing( fSourceListField.getListControl( null ) ); - fSearchForDuplicateFiles.doFillIntoGrid( control, 3 ); - setValues(); - return control; + Font font = parent.getFont(); + Composite comp = new Composite( parent, SWT.NONE ); + GridLayout topLayout = new GridLayout(); + topLayout.numColumns = 2; + comp.setLayout( topLayout ); + GridData gd = new GridData( GridData.FILL_BOTH ); + comp.setLayoutData( gd ); + Label viewerLabel = new Label( comp, SWT.LEFT ); + viewerLabel.setText( PreferenceMessages.getString( "SourcePreferencePage.0" ) ); //$NON-NLS-1$ + gd = new GridData( GridData.HORIZONTAL_ALIGN_FILL ); + gd.horizontalSpan = 2; + viewerLabel.setLayoutData( gd ); + viewerLabel.setFont( font ); + fPathViewer = new SourceContainerViewer( comp ); + gd = new GridData( GridData.FILL_BOTH ); + fPathViewer.getControl().setLayoutData( gd ); + fPathViewer.getControl().setFont( font ); + Composite pathButtonComp = new Composite( comp, SWT.NONE ); + GridLayout pathButtonLayout = new GridLayout(); + pathButtonLayout.marginHeight = 0; + pathButtonLayout.marginWidth = 0; + pathButtonComp.setLayout( pathButtonLayout ); + gd = new GridData( GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_FILL ); + pathButtonComp.setLayoutData( gd ); + pathButtonComp.setFont( font ); + createVerticalSpacer( comp, 2 ); + GC gc = new GC( parent ); + gc.setFont( parent.getFont() ); + FontMetrics fontMetrics = gc.getFontMetrics(); + gc.dispose(); + fAddAction = new AddContainerAction(); + Button button = createPushButton( pathButtonComp, fAddAction.getText(), fontMetrics ); + fAddAction.setButton( button ); + addAction( fAddAction ); + fEditAction = new EditContainerAction(); + button = createPushButton( pathButtonComp, fEditAction.getText(), fontMetrics ); + fEditAction.setButton( button ); + addAction( fEditAction ); + SourceContainerAction action = new RemoveAction(); + button = createPushButton( pathButtonComp, action.getText(), fontMetrics ); + action.setButton( button ); + addAction( action ); + action = new UpAction(); + button = createPushButton( pathButtonComp, action.getText(), fontMetrics ); + action.setButton( button ); + addAction( action ); + action = new DownAction(); + button = createPushButton( pathButtonComp, action.getText(), fontMetrics ); + action.setButton( button ); + addAction( action ); + retargetActions( fPathViewer ); + Dialog.applyDialogFont( comp ); + getWorkbench().getHelpSystem().setHelp( comp, ICDebugHelpContextIds.SOURCE_PREFERENCE_PAGE ); + initialize(); + return comp; } /* @@ -96,125 +121,66 @@ public class SourcePreferencePage extends PreferencePage implements IWorkbenchPr fWorkbench = workbench; } - /* - * (non-Javadoc) - * - * @see java.util.Observer#update(java.util.Observable, java.lang.Object) - */ - public void update( Observable o, Object arg ) { - setChanged( true ); - } - - private SourceListDialogField createSourceListField() { - SourceListDialogField field = new SourceListDialogField( PreferenceMessages.getString( "SourcePreferencePage.1" ), //$NON-NLS-1$ - new IListAdapter() { - - public void customButtonPressed( DialogField f, int index ) { - sourceButtonPressed( index ); - } - - public void selectionChanged( DialogField f ) { - } - } ); - field.addObserver( this ); - return field; - } - - private SelectionButtonDialogField createSearchForDuplicateFilesButton() { - SelectionButtonDialogField button = new SelectionButtonDialogField( SWT.CHECK ); - button.setLabelText( PreferenceMessages.getString( "SourcePreferencePage.2" ) ); //$NON-NLS-1$ - button.setDialogFieldListener( new IDialogFieldListener() { - - public void dialogFieldChanged( DialogField field ) { - setChanged( true ); - } - } ); + private Button createPushButton( Composite parent, String label, FontMetrics fontMetrics ) { + Button button = new Button( parent, SWT.PUSH ); + button.setFont( parent.getFont() ); + button.setText( label ); + GridData gd = getButtonGridData( button, fontMetrics ); + button.setLayoutData( gd ); return button; } - protected void sourceButtonPressed( int index ) { - switch( index ) { - case 0: // Add... - if ( addSourceLocation() ) - setChanged( true ); - break; - case 2: // Up - case 3: // Down - case 5: // Remove - setChanged( true ); - break; - } + private GridData getButtonGridData( Button button, FontMetrics fontMetrics ) { + GridData gd = new GridData( GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING ); + int widthHint = Dialog.convertHorizontalDLUsToPixels( fontMetrics, IDialogConstants.BUTTON_WIDTH ); + gd.widthHint = Math.max( widthHint, button.computeSize( SWT.DEFAULT, SWT.DEFAULT, true ).x ); + return gd; } - protected boolean isChanged() { - return fChanged; + private IWorkbench getWorkbench() { + return fWorkbench; } - protected void setChanged( boolean changed ) { - fChanged = changed; + private void addAction( SourceContainerAction action ) { + fActions.add( action ); } - private boolean addSourceLocation() { - AddSourceLocationWizard wizard = new AddSourceLocationWizard( getSourceLocations() ); - WizardDialog dialog = new WizardDialog( getShell(), wizard ); - if ( dialog.open() == Window.OK ) { - fSourceListField.addElement( wizard.getSourceLocation() ); - return true; + private void retargetActions( SourceContainerViewer viewer ) { + Iterator actions = fActions.iterator(); + while( actions.hasNext() ) { + SourceContainerAction action = (SourceContainerAction)actions.next(); + action.setViewer( viewer ); } - return false; } - public ICSourceLocation[] getSourceLocations() { - return (fSourceListField != null) ? fSourceListField.getSourceLocations() : new ICSourceLocation[0]; + private void createVerticalSpacer( Composite comp, int colSpan ) { + Label label = new Label( comp, SWT.NONE ); + GridData gd = new GridData(); + gd.horizontalSpan = colSpan; + label.setLayoutData( gd ); } - public void setSourceLocations( ICSourceLocation[] locations ) { - if ( fSourceListField != null ) - fSourceListField.setElements( Arrays.asList( locations ) ); + private void initialize() { + ISourceLookupDirector director = CDebugCorePlugin.getDefault().getCommonSourceLookupDirector(); + fPathViewer.setEntries( director.getSourceContainers() ); + fAddAction.setSourceLookupDirector( director ); + fEditAction.setSourceLookupDirector( director ); } - /* - * (non-Javadoc) - * + /* (non-Javadoc) * @see org.eclipse.jface.preference.PreferencePage#performDefaults() */ protected void performDefaults() { - setSourceLocations( new ICSourceLocation[0] ); - setSearchForDuplicateFiles( false ); + fPathViewer.setEntries( new ISourceContainer[0] ); super.performDefaults(); } - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.preference.IPreferencePage#performOk() + /* (non-Javadoc) + * @see org.eclipse.jface.preference.PreferencePage#performOk() */ public boolean performOk() { - storeValues(); + CDebugCorePlugin.getDefault().getCommonSourceLookupDirector().setSourceContainers( fPathViewer.getEntries() ); CDebugCorePlugin.getDefault().savePluginPreferences(); return true; } - - private boolean searchForDuplicateFiles() { - return (fSearchForDuplicateFiles != null) ? fSearchForDuplicateFiles.isSelected() : false; - } - - private void setSearchForDuplicateFiles( boolean search ) { - if ( fSearchForDuplicateFiles != null ) - fSearchForDuplicateFiles.setSelection( search ); - } - - private void setValues() { - setSourceLocations( CDebugCorePlugin.getDefault().getCommonSourceLocations() ); - setSearchForDuplicateFiles( CDebugCorePlugin.getDefault().getPluginPreferences().getBoolean( ICDebugConstants.PREF_SEARCH_DUPLICATE_FILES ) ); - } - - private void storeValues() { - CDebugCorePlugin.getDefault().saveCommonSourceLocations( getSourceLocations() ); - CDebugCorePlugin.getDefault().getPluginPreferences().setValue( ICDebugConstants.PREF_SEARCH_DUPLICATE_FILES, searchForDuplicateFiles() ); - } - - private IWorkbench getWorkbench() { - return fWorkbench; - } } |