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

Added persistency to the source locator.

This commit is contained in:
Mikhail Khodjaiants 2003-02-18 19:35:24 +00:00
parent fcdfb49342
commit acf0c44f7a
4 changed files with 131 additions and 11 deletions

View file

@ -1,6 +1,7 @@
2003-02-18 Mikhail Khodjaiants 2003-02-18 Mikhail Khodjaiants
Added persistency to the source locator. Added persistency to the source locator.
* CUISourceLocator.java * CUISourceLocator.java
* SourceLookupBlock.java
* SourcePropertyPage.java * SourcePropertyPage.java
2003-02-14 Mikhail Khodjaiants 2003-02-14 Mikhail Khodjaiants

View file

@ -16,9 +16,15 @@ import org.eclipse.cdt.debug.internal.ui.wizards.AddDirectorySourceLocationWizar
import org.eclipse.cdt.debug.internal.ui.wizards.AddSourceLocationWizard; import org.eclipse.cdt.debug.internal.ui.wizards.AddSourceLocationWizard;
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;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Path;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
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.dialogs.Dialog; import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.window.Window; import org.eclipse.jface.window.Window;
@ -213,7 +219,7 @@ public class CUISourceLocator implements IAdaptable
IStackFrameInfo frameInfo = (IStackFrameInfo)stackFrame.getAdapter( IStackFrameInfo.class ); IStackFrameInfo frameInfo = (IStackFrameInfo)stackFrame.getAdapter( IStackFrameInfo.class );
if ( frameInfo != null && frameInfo.getFile() != null && frameInfo.getFile().length() > 0 ) if ( frameInfo != null && frameInfo.getFile() != null && frameInfo.getFile().length() > 0 )
{ {
showDebugSourcePage( frameInfo.getFile() ); showDebugSourcePage( stackFrame.getLaunch(), frameInfo.getFile() );
if ( fNewLocationAttached ) if ( fNewLocationAttached )
{ {
res = fSourceLocator.getSourceElement( stackFrame ); res = fSourceLocator.getSourceElement( stackFrame );
@ -229,7 +235,7 @@ public class CUISourceLocator implements IAdaptable
* @param frameInfo the frame information for which source * @param frameInfo the frame information for which source
* could not be located * could not be located
*/ */
private void showDebugSourcePage( final String fileName ) private void showDebugSourcePage( final ILaunch launch, final String fileName )
{ {
Runnable prompter = new Runnable() Runnable prompter = new Runnable()
{ {
@ -238,7 +244,7 @@ public class CUISourceLocator implements IAdaptable
SourceLookupDialog dialog = new SourceLookupDialog( CDebugUIPlugin.getActiveWorkbenchShell(), fileName ); SourceLookupDialog dialog = new SourceLookupDialog( CDebugUIPlugin.getActiveWorkbenchShell(), fileName );
if ( dialog.open() == SourceLookupDialog.ATTACH ) if ( dialog.open() == SourceLookupDialog.ATTACH )
{ {
attachSourceLocation( fileName ); attachSourceLocation( launch, fileName );
} }
fAllowedToAsk = !dialog.isNotAskAgain(); fAllowedToAsk = !dialog.isNotAskAgain();
} }
@ -246,7 +252,7 @@ public class CUISourceLocator implements IAdaptable
CDebugUIPlugin.getStandardDisplay().syncExec( prompter ); CDebugUIPlugin.getStandardDisplay().syncExec( prompter );
} }
protected void attachSourceLocation( String fileName ) protected void attachSourceLocation( ILaunch launch, String fileName )
{ {
IPath path = new Path( fileName ); IPath path = new Path( fileName );
INewSourceLocationWizard wizard = null; INewSourceLocationWizard wizard = null;
@ -263,6 +269,11 @@ public class CUISourceLocator implements IAdaptable
if ( dialog.open() == Window.OK ) if ( dialog.open() == Window.OK )
{ {
fSourceLocator.addSourceLocation( wizard.getSourceLocation() ); fSourceLocator.addSourceLocation( wizard.getSourceLocation() );
if ( launch.getSourceLocator() instanceof IPersistableSourceLocator )
{
ILaunchConfiguration configuration = launch.getLaunchConfiguration();
saveChanges( configuration, (IPersistableSourceLocator)launch.getSourceLocator() );
}
fNewLocationAttached = true; fNewLocationAttached = true;
} }
} }
@ -281,4 +292,23 @@ public class CUISourceLocator implements IAdaptable
} }
return null; return null;
} }
public IProject getProject()
{
return fProject;
}
protected void saveChanges( ILaunchConfiguration configuration, IPersistableSourceLocator locator )
{
try
{
ILaunchConfigurationWorkingCopy copy = configuration.copy( configuration.getName() );
copy.setAttribute( ILaunchConfiguration.ATTR_SOURCE_LOCATOR_MEMENTO, locator.getMemento() );
copy.doSave();
}
catch( CoreException e )
{
CDebugUIPlugin.errorDialog( e.getMessage(), (IStatus)null );
}
}
} }

View file

@ -15,7 +15,9 @@ 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.wizards.AddSourceLocationWizard; import org.eclipse.cdt.debug.internal.ui.wizards.AddSourceLocationWizard;
import org.eclipse.debug.ui.ILaunchConfigurationDialog;
import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.window.Window; import org.eclipse.jface.window.Window;
import org.eclipse.jface.wizard.WizardDialog; import org.eclipse.jface.wizard.WizardDialog;
@ -35,6 +37,20 @@ import org.eclipse.swt.widgets.Shell;
*/ */
public class SourceLookupBlock public class SourceLookupBlock
{ {
private class SourceListDialogField extends ListDialogField
{
public SourceListDialogField( IListAdapter adapter, String[] buttonLabels, ILabelProvider lprovider )
{
super( adapter, buttonLabels, lprovider );
}
protected boolean managedButtonPressed( int index )
{
super.managedButtonPressed( index );
return false;
}
}
private class SourceLookupAdapter implements IListAdapter private class SourceLookupAdapter implements IListAdapter
{ {
public void customButtonPressed( DialogField field, int index ) public void customButtonPressed( DialogField field, int index )
@ -79,7 +95,9 @@ public class SourceLookupBlock
private Composite fControl = null; private Composite fControl = null;
private Shell fShell = null; private Shell fShell = null;
private ListDialogField fSourceListField; private SourceListDialogField fSourceListField;
private ILaunchConfigurationDialog fLaunchConfigurationDialog = null;
private boolean fIsDirty = false;
/** /**
* Constructor for SourceLookupBlock. * Constructor for SourceLookupBlock.
@ -98,7 +116,7 @@ public class SourceLookupBlock
SourceLookupAdapter adapter = new SourceLookupAdapter(); SourceLookupAdapter adapter = new SourceLookupAdapter();
fSourceListField = new ListDialogField( adapter, buttonLabels, new SourceLookupLabelProvider() ); fSourceListField = new SourceListDialogField( adapter, buttonLabels, new SourceLookupLabelProvider() );
fSourceListField.setLabelText( "Source Locations" ); fSourceListField.setLabelText( "Source Locations" );
fSourceListField.setUpButtonIndex( 2 ); fSourceListField.setUpButtonIndex( 2 );
fSourceListField.setDownButtonIndex( 3 ); fSourceListField.setDownButtonIndex( 3 );
@ -130,7 +148,7 @@ public class SourceLookupBlock
return fControl; return fControl;
} }
protected void initialize( ICSourceLocation[] locations ) public void initialize( ICSourceLocation[] locations )
{ {
fSourceListField.removeAllElements(); fSourceListField.removeAllElements();
for ( int i = 0; i < locations.length; ++i ) for ( int i = 0; i < locations.length; ++i )
@ -144,9 +162,17 @@ public class SourceLookupBlock
switch( index ) switch( index )
{ {
case 0: // Add... case 0: // Add...
addSourceLocation(); if ( addSourceLocation() )
fIsDirty = true;
break;
case 2:
case 3:
case 5:
fIsDirty = true;
break; break;
} }
if ( isDirty() )
updateLaunchConfigurationDialog();
} }
protected void doSelectionChanged() protected void doSelectionChanged()
@ -158,13 +184,39 @@ public class SourceLookupBlock
return (ICSourceLocation[])fSourceListField.getElements().toArray( new ICSourceLocation[fSourceListField.getElements().size()] ); return (ICSourceLocation[])fSourceListField.getElements().toArray( new ICSourceLocation[fSourceListField.getElements().size()] );
} }
private void addSourceLocation() private boolean addSourceLocation()
{ {
AddSourceLocationWizard wizard = new AddSourceLocationWizard( getSourceLocations() ); AddSourceLocationWizard wizard = new AddSourceLocationWizard( getSourceLocations() );
WizardDialog dialog = new WizardDialog( fControl.getShell(), wizard ); WizardDialog dialog = new WizardDialog( fControl.getShell(), wizard );
if ( dialog.open() == Window.OK ) if ( dialog.open() == Window.OK )
{ {
fSourceListField.addElement( wizard.getSourceLocation() ); fSourceListField.addElement( wizard.getSourceLocation() );
return true;
}
return false;
}
private void updateLaunchConfigurationDialog()
{
if ( getLaunchConfigurationDialog() != null )
{
getLaunchConfigurationDialog().updateMessage();
getLaunchConfigurationDialog().updateButtons();
} }
} }
public ILaunchConfigurationDialog getLaunchConfigurationDialog()
{
return fLaunchConfigurationDialog;
}
public void setLaunchConfigurationDialog( ILaunchConfigurationDialog launchConfigurationDialog )
{
fLaunchConfigurationDialog = launchConfigurationDialog;
}
public boolean isDirty()
{
return fIsDirty;
}
} }

View file

@ -8,7 +8,14 @@ package org.eclipse.cdt.debug.ui.sourcelookup;
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.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.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.core.model.IPersistableSourceLocator;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Control;
@ -96,11 +103,22 @@ public class SourcePropertyPage extends PropertyPage
*/ */
public boolean performOk() public boolean performOk()
{ {
setSourceLocations( fBlock.getSourceLocations() ); if ( fBlock.isDirty() )
{
try
{
setSourceLocations( fBlock.getSourceLocations() );
}
catch( DebugException e )
{
CDebugUIPlugin.errorDialog( e.getMessage(), (IStatus)null );
return false;
}
}
return true; return true;
} }
private void setSourceLocations( ICSourceLocation[] locations ) private void setSourceLocations( ICSourceLocation[] locations ) throws DebugException
{ {
ICDebugTarget target = getDebugTarget(); ICDebugTarget target = getDebugTarget();
if ( target != null ) if ( target != null )
@ -111,8 +129,27 @@ public class SourcePropertyPage extends PropertyPage
if ( locator != null ) if ( locator != null )
{ {
locator.setSourceLocations( locations ); locator.setSourceLocations( locations );
if ( target.getLaunch().getSourceLocator() instanceof IPersistableSourceLocator )
{
ILaunchConfiguration configuration = target.getLaunch().getLaunchConfiguration();
saveChanges( configuration, (IPersistableSourceLocator)target.getLaunch().getSourceLocator() );
}
} }
} }
} }
} }
protected void saveChanges( ILaunchConfiguration configuration, IPersistableSourceLocator locator )
{
try
{
ILaunchConfigurationWorkingCopy copy = configuration.copy( configuration.getName() );
copy.setAttribute( ILaunchConfiguration.ATTR_SOURCE_LOCATOR_MEMENTO, locator.getMemento() );
copy.doSave();
}
catch( CoreException e )
{
CDebugUIPlugin.errorDialog( e.getMessage(), (IStatus)null );
}
}
} }