Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] The UI part of the prompting source locator

? src/org/eclipse/cdt/debug/ui/sourcelookup
? src/org/eclipse/cdt/debug/ui/sourcelookup
? src/org/eclipse/cdt/debug/ui/sourcelookup
Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.ui/ChangeLog,v
retrieving revision 1.54
diff -u -r1.54 ChangeLog
--- ChangeLog 17 Dec 2002 02:46:01 -0000 1.54
+++ ChangeLog 17 Dec 2002 19:59:49 -0000
@@ -1,3 +1,10 @@
+2002-12-17 Mikhail Khodjaiants
+ The UI part of the prompting source locator.
+ * AttachSourceLocationBlock.java
+ * AttachSourceLocationDialog.java
+ * CUISourceLocator.java
+ * plugin.xml

 2002-12-16 Mikhail Khodjaiants
  New formating actions for variables, registers, and expressions
  * VariableFormatActionDelegate.java
Index: plugin.xml
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.ui/plugin.xml,v
retrieving revision 1.38
diff -u -r1.38 plugin.xml
--- plugin.xml 17 Dec 2002 02:46:01 -0000 1.38
+++ plugin.xml 17 Dec 2002 19:59:50 -0000
@@ -668,14 +668,6 @@
       </textHover>
    </extension>
    <extension
-         point="org.eclipse.debug.core.sourceLocators">
-      <sourceLocator
-            name="Prompting C/C++ Source Locator"
-            class="org.eclipse.cdt.debug.ui.CUISourceLocator"
-            id="org.eclipse.cdt.debug.ui.cSourceLocator">
-      </sourceLocator>
-   </extension>
-   <extension
          point="org.eclipse.debug.core.statusHandlers">
       <statusHandler
             plugin="org.eclipse.cdt.debug.core"
Index: src/org/eclipse/cdt/debug/ui/AttachSourceLocationBlock.java
===================================================================
RCS file: src/org/eclipse/cdt/debug/ui/AttachSourceLocationBlock.java
diff -N src/org/eclipse/cdt/debug/ui/AttachSourceLocationBlock.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/debug/ui/AttachSourceLocationBlock.java 17 Dec 2002 19:59:50 -0000
@@ -0,0 +1,200 @@
+/*
+ *(c) Copyright QNX Software Systems Ltd. 2002.
+ * All Rights Reserved.
+ *
+ */
+package org.eclipse.cdt.debug.ui.sourcelookup;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+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.DirectoryDialog;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * Enter type comment.
+ *
+ * @since: Dec 12, 2002
+ */
+public class AttachSourceLocationBlock
+{
+ private Composite fControl = null;
+ private Text fLocationText = null;
+ private Text fAssociationText = null;
+ private Button fAssocitedCheckButton = null;
+ private FontMetrics fFontMetrics;
+ private Shell fShell = null;
+
+ /**
+  * Constructor for AttachSourceLocationBlock.
+  */
+ public AttachSourceLocationBlock()
+ {
+ }

+ public void createControl( Composite parent )
+ {
+  fShell = parent.getShell();
+  fControl = new Composite( parent, SWT.NONE );
+  fControl.setLayout( new GridLayout() );
+  fControl.setLayoutData( new GridData( GridData.FILL_BOTH ) );
+  fControl.setFont( JFaceResources.getDialogFont() ); 
+  initializeDialogUnits( fControl );
+
+  createLocationControls( fControl );
+  createAssociationControls( fControl );
+ }

+ public void setInitialLocationPath( IPath path )
+ {
+  if ( path != null )
+  {
+   fLocationText.setText( path.toOSString() );
+  }
+ }
+
+ public void setInitialAssociationPath( IPath path )
+ {
+  if ( path != null )
+  {
+   fAssocitedCheckButton.setSelection( true );
+   fAssociationText.setText( path.toOSString() );
+  }
+ }

+ public Control getControl()
+ {
+  return fControl;
+ }
+
+ protected void createLocationControls( Composite parent )
+ {
+  Label label = new Label( parent, SWT.NONE );
+  label.setText( "Select location directory:" );
+  label.setLayoutData( new GridData( GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL ) );
+  Composite composite = new Composite( parent, SWT.NONE );
+  composite.setLayout( new GridLayout( 2, false ) );
+  GridData data = "" GridData( GridData.FILL_BOTH );
+  data.widthHint = Dialog.convertWidthInCharsToPixels( fFontMetrics, 70 );
+  composite.setLayoutData( data );
+  fLocationText = new Text( composite, SWT.SINGLE | SWT.BORDER );
+  fLocationText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL ) );
+  Button button = createButton( composite, "&Browse..." );
+  button.addSelectionListener( new SelectionAdapter()
+           {
+            /* (non-Javadoc)
+             * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(SelectionEvent)
+             */
+            public void widgetSelected( SelectionEvent e )
+            {
+             selectLocation();
+            }
+           } );
+ }
+
+ protected void selectLocation()
+ {
+  DirectoryDialog dialog = new DirectoryDialog( fShell );
+  dialog.setMessage( "Select Location Directory" );
+  String result = dialog.open();
+  if ( result != null )
+  {
+   fLocationText.setText( result );
+  }
+ }
+
+ protected void createAssociationControls( Composite parent )
+ {
+  Composite composite = new Composite( parent, SWT.NONE );
+  composite.setLayout( new GridLayout() );
+  GridData data = "" GridData( GridData.FILL_BOTH );
+  composite.setLayoutData( data );
+  fAssocitedCheckButton = new Button( composite, SWT.CHECK );
+  fAssocitedCheckButton.setText( "&Associate with" );
+  fAssociationText = new Text( composite, SWT.SINGLE | SWT.BORDER );
+  fAssociationText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+  fAssocitedCheckButton.addSelectionListener( new SelectionAdapter()
+              {
+               /* (non-Javadoc)
+                * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(SelectionEvent)
+                */
+               public void widgetSelected(SelectionEvent e)
+               {
+                associationSelectionChanged();
+               }
+
+              } );
+ }
+
+ protected void associationSelectionChanged()
+ {
+  boolean checked = fAssocitedCheckButton.getSelection();
+  fAssociationText.setEnabled( checked );
+  if ( !checked )
+   fAssociationText.setText( "" );
+ }
+
+ protected Button createButton( Composite parent, String label )
+ {
+  Button button = new Button( parent, SWT.PUSH );
+  button.setText( label );
+  GridData data = "" GridData( GridData.END );
+  data.heightHint = convertVerticalDLUsToPixels( IDialogConstants.BUTTON_HEIGHT );
+  int widthHint = convertHorizontalDLUsToPixels( IDialogConstants.BUTTON_WIDTH );
+  data.widthHint = Math.max( widthHint, button.computeSize( SWT.DEFAULT, SWT.DEFAULT, true ).x );
+  button.setLayoutData( data );
+  button.setFont( parent.getFont() );
+
+  return button;
+ }
+
+ protected int convertVerticalDLUsToPixels( int dlus )
+ {
+  if ( fFontMetrics == null )
+   return 0;
+  return Dialog.convertVerticalDLUsToPixels( fFontMetrics, dlus );
+ }
+
+ protected int convertHorizontalDLUsToPixels( int dlus )
+ {
+  if ( fFontMetrics == null )
+   return 0;
+  return Dialog.convertHorizontalDLUsToPixels( fFontMetrics, dlus );
+ }
+
+ protected void initializeDialogUnits( Control control )
+ {
+  // Compute and store a font metric
+  GC gc = new GC( control );
+  gc.setFont( control.getFont() );
+  fFontMetrics = gc.getFontMetrics();
+  gc.dispose();
+ }

+ public String getLocationPath()
+ {
+  return fLocationText.getText().trim();
+ }

+ public String getAssociationPath()
+ {
+  if ( fAssocitedCheckButton.getSelection() )
+  {
+   return fAssociationText.getText().trim();
+  }
+  return "";
+ }
+}
Index: src/org/eclipse/cdt/debug/ui/AttachSourceLocationDialog.java
===================================================================
RCS file: src/org/eclipse/cdt/debug/ui/AttachSourceLocationDialog.java
diff -N src/org/eclipse/cdt/debug/ui/AttachSourceLocationDialog.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/debug/ui/AttachSourceLocationDialog.java 17 Dec 2002 19:59:50 -0000
@@ -0,0 +1,130 @@
+/*
+ *(c) Copyright QNX Software Systems Ltd. 2002.
+ * All Rights Reserved.
+ *
+ */
+package org.eclipse.cdt.debug.ui.sourcelookup;
+
+import java.text.MessageFormat;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * Enter type comment.
+ *
+ * @since: Dec 12, 2002
+ */
+public class AttachSourceLocationDialog extends Dialog
+{
+ private IPath fLocationPath = null;
+ private IPath fAssociationPath = null;
+ private AttachSourceLocationBlock fAttachBlock;
+
+ /**
+  * Constructor for AttachSourceLocationDialog.
+  * @param parentShell
+  */
+ public AttachSourceLocationDialog( Shell parentShell )
+ {
+  super( parentShell );
+  fAttachBlock = new AttachSourceLocationBlock();
+ }
+
+ /* (non-Javadoc)
+  * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(Composite)
+  */
+ protected Control createDialogArea( Composite parent )
+ {
+  Composite composite = (Composite)super.createDialogArea( parent );
+  getShell().setText( "Attach Source Location" );
+  fAttachBlock.createControl( composite );
+  fAttachBlock.setInitialAssociationPath( fAssociationPath );
+
+  return composite;
+ }
+
+ public void setInitialPath( IPath path )
+ {
+  fAssociationPath = path;
+ }
+
+ /* (non-Javadoc)
+  * @see org.eclipse.jface.dialogs.Dialog#okPressed()
+  */
+ protected void okPressed()
+ {
+  String locationString = fAttachBlock.getLocationPath();
+  if ( locationString.length() == 0 )
+  {
+   MessageDialog.openError( getShell(), getShell().getText(), "Location directory is not selected" );
+   return;
+  }
+  if ( !isLocationPathValid( locationString ) )
+  {
+   MessageDialog.openError( getShell(), getShell().getText(), MessageFormat.format( "Invalid path: ''{0}''", new String[] { locationString } ) );
+   return;
+  }
+  String associationString = fAttachBlock.getAssociationPath();
+  if ( !isAssociationPathValid( associationString ) )
+  {
+   MessageDialog.openError( getShell(), getShell().getText(), MessageFormat.format( "Invalid path: ''{0}''", new String[] { associationString } ) );
+   return;
+  }
+  fLocationPath = getLocation0();
+  fAssociationPath = getAssociation0();
+  super.okPressed();
+ }
+
+ public boolean isLocationPathValid( String pathString )
+ {
+  if ( Path.EMPTY.isValidPath( pathString ) )
+  {
+   Path path = new Path( pathString );
+   return path.toFile().exists();
+  }
+  return false;
+ }
+
+ public boolean isAssociationPathValid( String pathString )
+ {
+  if ( pathString.length() > 0 )
+  {
+   return Path.EMPTY.isValidPath( pathString );
+  }
+  return true;
+ }

+ public IPath getLocation()
+ {
+  return fLocationPath;
+ }
+
+ private IPath getLocation0()
+ {
+  if ( Path.EMPTY.isValidPath( fAttachBlock.getLocationPath() ) )
+  {
+   return new Path( fAttachBlock.getLocationPath() );
+  }
+  return null;
+ } 

+ public IPath getAssociation()
+ {
+  return fAssociationPath;
+ }
+
+ private IPath getAssociation0()
+ {
+  if ( Path.EMPTY.isValidPath( fAttachBlock.getAssociationPath() ) )
+  {
+   return new Path( fAttachBlock.getAssociationPath() );
+  }
+  return null;
+ } 
+}
Index: src/org/eclipse/cdt/debug/ui/CUISourceLocator.java
===================================================================
RCS file: src/org/eclipse/cdt/debug/ui/CUISourceLocator.java
diff -N src/org/eclipse/cdt/debug/ui/CUISourceLocator.java
--- src/org/eclipse/cdt/debug/ui/CUISourceLocator.java 4 Dec 2002 15:28:47 -0000 1.8
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,228 +0,0 @@
-/*
- *(c) Copyright QNX Software Systems Ltd. 2002.
- * All Rights Reserved.
- *
- */
-package org.eclipse.cdt.debug.ui;
-
-import java.text.MessageFormat;
-
-import org.eclipse.cdt.debug.core.model.IStackFrameInfo;
-import org.eclipse.cdt.debug.internal.core.sourcelookup.CSourceLocator;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.CoreException;
-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.jface.dialogs.Dialog;
-import org.eclipse.swt.SWT;
-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.swt.widgets.Shell;
-
-/**
- *
- * A source locator that prompts the user to find source when source cannot
- * be found on the current source lookup path.
- *
- * @since Sep 24, 2002
- */
-public class CUISourceLocator implements IPersistableSourceLocator
-{
- /**
-  * Identifier for the 'Prompting C/C++ Source Locator' extension
-  * (value <code>"org.eclipse.cdt.debug.ui.cSourceLocator"</code>).
-  */
- public static final String ID_PROMPTING_C_SOURCE_LOCATOR = CDebugUIPlugin.getUniqueIdentifier() + ".cSourceLocator"; //$NON-NLS-1$
-
- /**
-  * The project being debugged.
-  */
- private IProject fProject = null;

- /**
-  * Underlying source locator.
-  */
- private CSourceLocator fSourceLocator;

- /**
-  * Whether the user should be prompted for source.
-  * Initially true, until the user checks the 'do not
-  * ask again' box.
-  */
- protected boolean fAllowedToAsk;
-
-
- /**
-  * Constructor for CUISourceLocator.
-  */
- public CUISourceLocator()
- {
-  fSourceLocator = new CSourceLocator();
-  fAllowedToAsk = true;
- }
-
- /**
-  * Constructor for CUISourceLocator.
-  */
- public CUISourceLocator( IProject project )
- {
-  fProject = project;
-  fSourceLocator = new CSourceLocator( project );
-  fAllowedToAsk = true;
- }
-
- /* (non-Javadoc)
-  * @see org.eclipse.debug.core.model.IPersistableSourceLocator#getMemento()
-  */
- public String getMemento() throws CoreException
- {
-  return fSourceLocator.getMemento();
- }
-
- /* (non-Javadoc)
-  * @see org.eclipse.debug.core.model.IPersistableSourceLocator#initializeFromMemento(String)
-  */
- public void initializeFromMemento( String memento ) throws CoreException
- {
-  fSourceLocator.initializeFromMemento( memento );
- }
-
- /* (non-Javadoc)
-  * @see org.eclipse.debug.core.model.IPersistableSourceLocator#initializeDefaults(ILaunchConfiguration)
-  */
- public void initializeDefaults( ILaunchConfiguration configuration ) throws CoreException
- {
-  fSourceLocator.initializeDefaults( configuration );
- }
-
- /* (non-Javadoc)
-  * @see org.eclipse.debug.core.model.ISourceLocator#getSourceElement(IStackFrame)
-  */
- public Object getSourceElement( IStackFrame stackFrame )
- {
-  Object res = fSourceLocator.getSourceElement( stackFrame );
-  if ( res == null && fAllowedToAsk )
-  {
-   IStackFrameInfo frameInfo = (IStackFrameInfo)stackFrame.getAdapter( IStackFrameInfo.class );
-   if ( frameInfo != null )
-   {
-    showDebugSourcePage( frameInfo.getFile(), stackFrame.getLaunch().getLaunchConfiguration() );
-    res = fSourceLocator.getSourceElement( stackFrame );
-   }
-  }
-  return res;
- }
-
- /**
-  * Prompts to locate the source of the given type.
-  *
-  * @param frameInfo the frame information for which source
-  *  could not be located
-  */
- private void showDebugSourcePage( final String fileName, final ILaunchConfiguration lc )
- {
-  Runnable prompter = new Runnable()
-        {
-         public void run()
-         {
-          SourceLookupDialog dialog = new SourceLookupDialog( CDebugUIPlugin.getActiveWorkbenchShell(), fileName, lc, CUISourceLocator.this );
-          dialog.open();
-          fAllowedToAsk = !dialog.isNotAskAgain();
-         }
-        };
-  CDebugUIPlugin.getStandardDisplay().syncExec( prompter );
- }
-
- /**
-  * Dialog that prompts for source lookup path.
-  */
- private static class SourceLookupDialog extends Dialog
- {
-
-  private CUISourceLocator fLocator;
-  private ILaunchConfiguration fConfiguration;
-  private String fFileName;
-  private boolean fNotAskAgain;
-  private Button fAskAgainCheckBox;
-
-  public SourceLookupDialog( Shell shell,
-           String fileName,
-           ILaunchConfiguration configuration,
-           CUISourceLocator locator )
-  {
-   super( shell );
-   fFileName = fileName;
-   fNotAskAgain = false;
-   fAskAgainCheckBox = null;
-   fLocator = locator;
-   fConfiguration = configuration;
-  }
-
-  public boolean isNotAskAgain()
-  {
-   return fNotAskAgain;
-  }
-
-  protected Control createDialogArea( Composite parent )
-  {
-   getShell().setText( "Debugger Source Lookup" );
-
-   Composite composite = (Composite)super.createDialogArea( parent );
-   composite.setLayout( new GridLayout() );
-   Label message = new Label( composite, SWT.LEFT + SWT.WRAP );
-   message.setText( MessageFormat.format( "The source could not be shown as the file ''{0}'' was not found.", new String[] { fFileName }  ) );
-   GridData data = "" GridData();
-   data.widthHint = convertWidthInCharsToPixels( message, 70 );
-   message.setLayoutData( data );
-   fAskAgainCheckBox = new Button( composite, SWT.CHECK + SWT.WRAP );
-   data = "" GridData();
-   data.widthHint = convertWidthInCharsToPixels( fAskAgainCheckBox, 70 );
-   fAskAgainCheckBox.setLayoutData(data);
-   fAskAgainCheckBox.setText( "Do &not ask again" );
-
-   return composite;
-  }
-
-  /**
-   * @see Dialog#convertWidthInCharsToPixels(FontMetrics, int)
-   */
-  protected int convertWidthInCharsToPixels( Control control, int chars )
-  {
-   GC gc = new GC( control );
-   gc.setFont( control.getFont() );
-   FontMetrics fontMetrics = gc.getFontMetrics();
-   gc.dispose();
-   return Dialog.convertWidthInCharsToPixels( fontMetrics, chars );
-  }
-
-  protected void okPressed()
-  {
-   try
-   {
-    if ( fAskAgainCheckBox != null )
-    {
-     fNotAskAgain = fAskAgainCheckBox.getSelection();
-    }
-    ILaunchConfigurationWorkingCopy wc = fConfiguration.getWorkingCopy();
-    if ( !fConfiguration.contentsEqual( wc ) )
-    {
-     fConfiguration = wc.doSave();
-     fLocator.initializeDefaults( fConfiguration );
-    }
-   }
-   catch( CoreException e )
-   {
-    CDebugUIPlugin.log( e );
-   }
-   super.okPressed();
-  }
- }
-}

Back to the top