Tried to implement ConsoleLineTracker (see plugin.xml) for PHP stack traces in the...
authoraxelcl <axelcl>
Fri, 24 Jun 2005 21:18:26 +0000 (21:18 +0000)
committeraxelcl <axelcl>
Fri, 24 Jun 2005 21:18:26 +0000 (21:18 +0000)
Doesn't work at the moment.

net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/launcher/PHPEnvironmentTab.java
net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/preferences/EditInterpreterDialog.java [deleted file]
net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/preferences/PHPInterpreterLabelProvider.java
net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/preferences/PHPInterpreterPreferencePage.java
net.sourceforge.phpeclipse.launching/plugin.xml
net.sourceforge.phpeclipse.launching/src/net/sourceforge/phpdt/internal/launching/ConsoleLineTracker.java [new file with mode: 0644]
net.sourceforge.phpeclipse.launching/src/net/sourceforge/phpdt/internal/launching/InterpreterRunner.java
net.sourceforge.phpeclipse.launching/src/net/sourceforge/phpdt/internal/launching/PHPInterpreter.java
net.sourceforge.phpeclipse.launching/src/net/sourceforge/phpdt/internal/launching/PHPLaunchConfigurationAttribute.java
net.sourceforge.phpeclipse.launching/src/net/sourceforge/phpdt/internal/launching/PHPRuntime.java

index a705d70..a40d0c0 100644 (file)
@@ -1,5 +1,6 @@
 package net.sourceforge.phpdt.internal.debug.ui.launcher;
 
+import java.io.File;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -7,8 +8,8 @@ import java.util.Map;
 
 import net.sourceforge.phpdt.internal.debug.ui.PHPDebugUiMessages;
 import net.sourceforge.phpdt.internal.debug.ui.PHPDebugUiPlugin;
-import net.sourceforge.phpdt.internal.debug.ui.preferences.EditInterpreterDialog;
 import net.sourceforge.phpdt.internal.debug.ui.preferences.EditPathMapDialog;
+import net.sourceforge.phpdt.internal.debug.ui.preferences.PHPInterpreterPreferencePage;
 import net.sourceforge.phpdt.internal.launching.PHPInterpreter;
 import net.sourceforge.phpdt.internal.launching.PHPLaunchConfigurationAttribute;
 import net.sourceforge.phpdt.internal.launching.PHPRuntime;
@@ -412,15 +413,13 @@ public class PHPEnvironmentTab extends AbstractLaunchConfigurationTab {
     interpreterAddButton.setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment.interpreterAddButton.label"));
     interpreterAddButton.addSelectionListener(new SelectionAdapter() {
       public void widgetSelected(SelectionEvent evt) {
-        PHPInterpreter newInterpreter = new PHPInterpreter(null, null);
-        EditInterpreterDialog editor = new EditInterpreterDialog(getShell(), PHPDebugUiMessages
-            .getString("LaunchConfigurationTab.PHPEnvironment.editInterpreterDialog.title"));
-        editor.create();
-        editor.setInterpreterToEdit(newInterpreter);
-        if (EditInterpreterDialog.OK == editor.open()) {
+        PHPInterpreter newInterpreter = new PHPInterpreter(null);
+        File phpRuntime = PHPInterpreterPreferencePage.getFile(getShell(), null);
+        if (phpRuntime != null) {
+          newInterpreter.setInstallLocation(phpRuntime);
           PHPRuntime.getDefault().addInstalledInterpreter(newInterpreter);
-          interpreterCombo.add(newInterpreter.getName());
-          interpreterCombo.select(interpreterCombo.indexOf(newInterpreter.getName()));
+          interpreterCombo.add(newInterpreter.getInstallLocation().toString());
+          interpreterCombo.select(interpreterCombo.indexOf(newInterpreter.getInstallLocation().toString()));
         }
       }
     });
@@ -559,13 +558,13 @@ public class PHPEnvironmentTab extends AbstractLaunchConfigurationTab {
     String[] interpreterNames = new String[installedInterpretersWorkingCopy.size()];
     for (int interpreterIndex = 0; interpreterIndex < installedInterpretersWorkingCopy.size(); interpreterIndex++) {
       PHPInterpreter interpreter = (PHPInterpreter) installedInterpretersWorkingCopy.get(interpreterIndex);
-      interpreterNames[interpreterIndex] = interpreter.getName();
+      interpreterNames[interpreterIndex] = interpreter.getInstallLocation().toString();
     }
     interpreterCombo.setItems(interpreterNames);
 
     PHPInterpreter selectedInterpreter = PHPRuntime.getDefault().getSelectedInterpreter();
     if (selectedInterpreter != null)
-      interpreterCombo.select(interpreterCombo.indexOf(selectedInterpreter.getName()));
+      interpreterCombo.select(interpreterCombo.indexOf(selectedInterpreter.getInstallLocation().toString()));
   }
 
   public void performApply(ILaunchConfigurationWorkingCopy configuration) {
diff --git a/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/preferences/EditInterpreterDialog.java b/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/preferences/EditInterpreterDialog.java
deleted file mode 100644 (file)
index bb41fa3..0000000
+++ /dev/null
@@ -1,167 +0,0 @@
-package net.sourceforge.phpdt.internal.debug.ui.preferences;
-
-import java.io.File;
-
-import net.sourceforge.phpdt.internal.debug.ui.PHPDebugUiMessages;
-import net.sourceforge.phpdt.internal.debug.ui.PHPDebugUiPlugin;
-import net.sourceforge.phpdt.internal.launching.PHPInterpreter;
-import net.sourceforge.phpdt.internal.ui.dialogs.StatusDialog;
-
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.layout.RowData;
-import org.eclipse.swt.layout.RowLayout;
-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;
-
-public class EditInterpreterDialog extends StatusDialog {
-       protected PHPInterpreter interpreterToEdit;
-       protected Text interpreterNameText, interpreterLocationText;
-       protected IStatus[] allStatus = new IStatus[2];
-
-       public EditInterpreterDialog(Shell parentShell, String aDialogTitle) {
-               super(parentShell);
-               setTitle(aDialogTitle);
-       }
-       
-       public void setInterpreterToEdit(PHPInterpreter anInterpreter) {
-               interpreterToEdit = anInterpreter;
-               
-               String interpreterName = interpreterToEdit.getName();
-               interpreterNameText.setText(interpreterName != null ? interpreterName : ""); //$NON-NLS-1$
-
-               IPath installLocation = interpreterToEdit.getInstallLocation();
-               interpreterLocationText.setText(installLocation != null ? installLocation.toOSString() : ""); //$NON-NLS-1$
-       }
-
-       protected void createLocationEntryField(Composite composite) {
-               new Label(composite, SWT.NONE).setText(PHPDebugUiMessages.getString("EditInterpreterDialog.PHPInterpreter.path.label")); //$NON-NLS-1$
-
-               Composite locationComposite = new Composite(composite, SWT.NONE);
-               RowLayout locationLayout = new RowLayout();
-               locationLayout.marginLeft = 0;
-               locationComposite.setLayout(locationLayout);
-
-               interpreterLocationText = new Text(locationComposite, SWT.SINGLE | SWT.BORDER);
-               interpreterLocationText.addModifyListener(new ModifyListener() {
-                       public void modifyText(ModifyEvent e) {
-                               allStatus[1] = validateInterpreterLocationText();
-                               updateStatusLine();
-                       }
-               });
-               interpreterLocationText.setLayoutData(new RowData(120, SWT.DEFAULT));
-
-               Button browseButton = new Button(composite, SWT.PUSH);
-               browseButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
-               browseButton.setText(PHPDebugUiMessages.getString("EditInterpreterDialog.PHPInterpreter.path.browse.button.label")); //$NON-NLS-1$
-               browseButton.addSelectionListener(new SelectionAdapter() {
-                       public void widgetSelected(SelectionEvent e) {
-                               browseForInstallDir();
-                       }
-               });
-       }
-
-       protected void updateStatusLine() {
-               updateStatus(getMostSevereStatus());
-       }
-
-       protected IStatus getMostSevereStatus() {
-               IStatus max = new Status(0, PHPDebugUiPlugin.PLUGIN_ID, IStatus.OK, "", null); //$NON-NLS-1$
-               for (int i = 0; i < allStatus.length; i++) {
-                       IStatus curr = allStatus[i];
-                       if (curr != null) {
-                               if (curr.matches(IStatus.ERROR)) {
-                                       return curr;
-                               }
-                               if (max == null || curr.getSeverity() > max.getSeverity()) {
-                                       max = curr;
-                               }
-                       }
-               }
-               return max;
-       }
-
-       protected IStatus validateInterpreterLocationText() {
-               File path = new File(interpreterLocationText.getText());
-               if (path.exists()) {
-                       File unix_php = new File(path, "php"); //$NON-NLS-1$ //$NON-NLS-2$
-                       File windows_php_exe = new File(path, "php.exe"); //$NON-NLS-1$ //$NON-NLS-2$
-                       if (unix_php.isFile() || windows_php_exe.isFile())
-                               return new Status(IStatus.OK, PHPDebugUiPlugin.PLUGIN_ID, 0, "", null); //$NON-NLS-1$
-               }
-
-               return new Status(IStatus.ERROR, PHPDebugUiPlugin.PLUGIN_ID, 1, PHPDebugUiMessages.getString("EditInterpreterDialog.PHPInterpreter.path.error"), null); //$NON-NLS-1$
-       }
-
-       protected void createNameEntryField(Composite composite) {
-               new Label(composite, SWT.NONE).setText(PHPDebugUiMessages.getString("EditInterpreterDialog.PHPInterpreter.name")); //$NON-NLS-1$
-
-               GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
-               gridData.horizontalSpan = 2;
-
-               interpreterNameText = new Text(composite, SWT.SINGLE | SWT.BORDER);
-               interpreterNameText.addModifyListener(new ModifyListener() {
-                       public void modifyText(ModifyEvent e) {
-                               allStatus[0] = validateInterpreterNameText();
-                               updateStatusLine();
-                       }
-               });
-               interpreterNameText.setLayoutData(gridData);
-       }
-
-       protected IStatus validateInterpreterNameText() {
-               int status = IStatus.OK;
-               String message = ""; //$NON-NLS-1$
-
-               if (interpreterNameText.getText() == null || interpreterNameText.getText().length() <= 0) {
-                       status = IStatus.ERROR;
-                       message = PHPDebugUiMessages.getString("EditInterpreterDialog.PHPInterpreter.name.error"); //$NON-NLS-1$
-               }
-
-               return new Status(status, PHPDebugUiPlugin.PLUGIN_ID, 0, message, null);
-       }
-
-       protected void browseForInstallDir() {
-               DirectoryDialog dialog = new DirectoryDialog(getShell());
-               dialog.setFilterPath(interpreterLocationText.getText());
-               dialog.setMessage(PHPDebugUiMessages.getString("EditInterpreterDialog.PHPInterpreter.path.browse.message")); //$NON-NLS-1$
-               String newPath = dialog.open();
-               if (newPath != null)
-                       interpreterLocationText.setText(newPath);
-       }
-
-       protected void okPressed() {
-               if (interpreterToEdit == null)
-                       interpreterToEdit = new PHPInterpreter(null, null);
-
-               interpreterToEdit.setName(interpreterNameText.getText());
-               interpreterToEdit.setInstallLocation(new Path(interpreterLocationText.getText()));
-               super.okPressed();
-       }
-       protected Control createDialogArea(Composite parent) {
-               Composite composite = (Composite) super.createDialogArea(parent);
-               GridLayout layout = new GridLayout();
-               layout.numColumns = 3;
-               composite.setLayout(layout);
-
-               createNameEntryField(composite);
-               createLocationEntryField(composite);
-               
-               return composite;
-       }
-
-}
\ No newline at end of file
index 83131e7..84b52f9 100644 (file)
@@ -2,7 +2,6 @@ package net.sourceforge.phpdt.internal.debug.ui.preferences;
 
 import net.sourceforge.phpdt.internal.launching.PHPInterpreter;
 
-import org.eclipse.core.runtime.IPath;
 import org.eclipse.jface.viewers.ILabelProviderListener;
 import org.eclipse.jface.viewers.ITableLabelProvider;
 import org.eclipse.swt.graphics.Image;
@@ -21,10 +20,10 @@ public class PHPInterpreterLabelProvider implements ITableLabelProvider {
                PHPInterpreter interpreter = (PHPInterpreter) element;
                switch (columnIndex) {
                        case 0 :
-                               return interpreter.getName();
-                       case 1 :
-                               IPath installLocation = interpreter.getInstallLocation();
-                               return installLocation != null ? installLocation.toOSString() : "In user path";
+                               return interpreter.getInstallLocation().toString();
+//                     case 1 :
+//                             IPath installLocation = interpreter.getInstallLocation();
+//                             return installLocation != null ? installLocation.toOSString() : "In user path";
                        default :
                                return "Unknown Column Index";
                }
index 3cfe475..689b864 100644 (file)
@@ -1,5 +1,6 @@
 package net.sourceforge.phpdt.internal.debug.ui.preferences;
 
+import java.io.File;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -7,6 +8,7 @@ import net.sourceforge.phpdt.internal.debug.ui.PHPDebugUiMessages;
 import net.sourceforge.phpdt.internal.launching.PHPInterpreter;
 import net.sourceforge.phpdt.internal.launching.PHPRuntime;
 
+import org.eclipse.core.runtime.Platform;
 import org.eclipse.jface.preference.PreferencePage;
 import org.eclipse.jface.viewers.CheckStateChangedEvent;
 import org.eclipse.jface.viewers.CheckboxTableViewer;
@@ -23,7 +25,9 @@ import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.FileDialog;
 import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.widgets.Table;
 import org.eclipse.swt.widgets.TableColumn;
 import org.eclipse.swt.widgets.TableItem;
@@ -31,182 +35,218 @@ import org.eclipse.ui.IWorkbench;
 import org.eclipse.ui.IWorkbenchPreferencePage;
 
 public class PHPInterpreterPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
-       protected CheckboxTableViewer tableViewer;
-       protected Button addButton, editButton, removeButton;
-
-       public PHPInterpreterPreferencePage() {
-               super();
-       }
-
-       public void init(IWorkbench workbench) {}
-
-       protected Control createContents(Composite parent) {
-               noDefaultAndApplyButton();
-
-               Composite composite = createPageRoot(parent);
-               Table table = createInstalledInterpretersTable(composite);
-               createInstalledInterpretersTableViewer(table);
-               createButtonGroup(composite);
-
-               tableViewer.setInput(PHPRuntime.getDefault().getInstalledInterpreters());
-               PHPInterpreter selectedInterpreter = PHPRuntime.getDefault().getSelectedInterpreter();
-               if (selectedInterpreter != null)
-                       tableViewer.setChecked(selectedInterpreter, true);
-
-               enableButtons();
-
-               return composite;
-       }
-
-       protected void createButtonGroup(Composite composite) {
-               Composite buttons = new Composite(composite, SWT.NULL);
-               buttons.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
-               GridLayout layout = new GridLayout();
-               layout.marginHeight = 0;
-               layout.marginWidth = 0;
-               buttons.setLayout(layout);
-
-               addButton = new Button(buttons, SWT.PUSH);
-               addButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
-               addButton.setText(PHPDebugUiMessages.getString("PHPInterpreterPreferencePage.addButton.label")); //$NON-NLS-1$
-               addButton.addListener(SWT.Selection, new Listener() {
-                       public void handleEvent(Event evt) {
-                               addInterpreter();
-                       }
-               });
-
-               editButton = new Button(buttons, SWT.PUSH);
-               editButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
-               editButton.setText(PHPDebugUiMessages.getString("PHPInterpreterPreferencePage.editButton.label")); //$NON-NLS-1$
-               editButton.addListener(SWT.Selection, new Listener() {
-                       public void handleEvent(Event evt) {
-                               editInterpreter();
-                       }
-               });
-
-               removeButton = new Button(buttons, SWT.PUSH);
-               removeButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
-               removeButton.setText(PHPDebugUiMessages.getString("PHPInterpreterPreferencePage.removeButton.label")); //$NON-NLS-1$
-               removeButton.addListener(SWT.Selection, new Listener() {
-                       public void handleEvent(Event evt) {
-                               removeInterpreter();
-                       }
-               });
-       }
-
-       protected void createInstalledInterpretersTableViewer(Table table) {
-               tableViewer = new CheckboxTableViewer(table);
-
-               tableViewer.setLabelProvider(new PHPInterpreterLabelProvider());
-               tableViewer.setContentProvider(new PHPInterpreterContentProvider());
-
-               tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
-                       public void selectionChanged(SelectionChangedEvent evt) {
-                               enableButtons();
-                       }
-               });
-
-               tableViewer.addCheckStateListener(new ICheckStateListener() {
-                       public void checkStateChanged(CheckStateChangedEvent event) {
-                               updateSelectedInterpreter(event.getElement());
-                       }
-               });
-               
-               tableViewer.addDoubleClickListener(new IDoubleClickListener() {
-                       public void doubleClick(DoubleClickEvent e) {
-                               editInterpreter();
-                       }
-               });
-       }
-
-       protected Table createInstalledInterpretersTable(Composite composite) {
-               Table table = new Table(composite, SWT.CHECK | SWT.BORDER | SWT.FULL_SELECTION);
-
-               GridData data = new GridData(GridData.FILL_BOTH);
-               data.widthHint = convertWidthInCharsToPixels(80);
-               data.heightHint = convertHeightInCharsToPixels(10);
-               table.setLayoutData(data);
-               table.setHeaderVisible(true);
-               table.setLinesVisible(false);
-
-               TableColumn column = new TableColumn(table, SWT.NULL);
-               column.setText(PHPDebugUiMessages.getString("PHPInterpreterPreferencePage.PHPInterpreterTable.interpreterName")); //$NON-NLS-1$
-               column.setWidth(125);
-
-               column = new TableColumn(table, SWT.NULL);
-               column.setText(PHPDebugUiMessages.getString("PHPInterpreterPreferencePage.PHPInterpreterTable.interpreterPath")); //$NON-NLS-1$
-               column.setWidth(350);
-
-               return table;
-       }
-
-       protected Composite createPageRoot(Composite parent) {
-               Composite composite = new Composite(parent, SWT.NULL);
-               GridLayout layout = new GridLayout();
-               layout.numColumns = 2;
-               composite.setLayout(layout);
-               return composite;
-       }
-
-       protected void addInterpreter() {
-               PHPInterpreter newInterpreter = new PHPInterpreter(null, null);
-               EditInterpreterDialog editor = new EditInterpreterDialog(getShell(), PHPDebugUiMessages.getString("PHPInterpreterPreferencePage.EditInterpreterDialog.addInterpreter.title")); //$NON-NLS-1$
-               editor.create();
-               editor.setInterpreterToEdit(newInterpreter);
-               if (EditInterpreterDialog.OK == editor.open())
-                       tableViewer.add(newInterpreter);
-       }
-
-       protected void removeInterpreter() {
-               tableViewer.remove(getSelectedInterpreter());
-       }
-
-       protected void enableButtons() {
-               if (getSelectedInterpreter() != null) {
-                       editButton.setEnabled(true);
-                       removeButton.setEnabled(true);
-               } else {
-                       editButton.setEnabled(false);
-                       removeButton.setEnabled(false);
-               }
-       }
-
-       protected void updateSelectedInterpreter(Object interpreter) {
-               Object[] checkedElements = tableViewer.getCheckedElements();
-               for (int i = 0; i < checkedElements.length; i++) {
-                       tableViewer.setChecked(checkedElements[i], false);
-               }
-
-               tableViewer.setChecked(interpreter, true);
-       }
-
-       protected void editInterpreter() {
-               EditInterpreterDialog editor = new EditInterpreterDialog(getShell(), PHPDebugUiMessages.getString("PHPInterpreterPreferencePage.EditInterpreterDialog.editInterpreter.title")); //$NON-NLS-1$
-               editor.create();
-               
-               PHPInterpreter anInterpreter = getSelectedInterpreter();
-               editor.setInterpreterToEdit(anInterpreter);
-               if (EditInterpreterDialog.OK == editor.open())
-                       tableViewer.update(anInterpreter, null);
-       }
-       
-       protected PHPInterpreter getSelectedInterpreter() {
-               IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
-               return (PHPInterpreter) selection.getFirstElement();
-       }
-       
-       public boolean performOk() {
-               TableItem[] tableItems = tableViewer.getTable().getItems();
-               List installedInterpreters = new ArrayList(tableItems.length);
-               for (int i = 0; i < tableItems.length; i++)
-                       installedInterpreters.add(tableItems[i].getData());
-               PHPRuntime.getDefault().setInstalledInterpreters(installedInterpreters);
-
-               Object[] checkedElements = tableViewer.getCheckedElements();
-               if (checkedElements.length > 0)
-                       PHPRuntime.getDefault().setSelectedInterpreter((PHPInterpreter) checkedElements[0]);
-
-               return super.performOk();
-       }
-
+  protected CheckboxTableViewer tableViewer;
+
+  protected Button addButton, editButton, removeButton;
+
+  public PHPInterpreterPreferencePage() {
+    super();
+  }
+
+  public void init(IWorkbench workbench) {
+  }
+
+  protected Control createContents(Composite parent) {
+    noDefaultAndApplyButton();
+
+    Composite composite = createPageRoot(parent);
+    Table table = createInstalledInterpretersTable(composite);
+    createInstalledInterpretersTableViewer(table);
+    createButtonGroup(composite);
+
+    tableViewer.setInput(PHPRuntime.getDefault().getInstalledInterpreters());
+    PHPInterpreter selectedInterpreter = PHPRuntime.getDefault().getSelectedInterpreter();
+    if (selectedInterpreter != null)
+      tableViewer.setChecked(selectedInterpreter, true);
+
+    enableButtons();
+
+    return composite;
+  }
+
+  protected void createButtonGroup(Composite composite) {
+    Composite buttons = new Composite(composite, SWT.NULL);
+    buttons.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
+    GridLayout layout = new GridLayout();
+    layout.marginHeight = 0;
+    layout.marginWidth = 0;
+    buttons.setLayout(layout);
+
+    addButton = new Button(buttons, SWT.PUSH);
+    addButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+    addButton.setText(PHPDebugUiMessages.getString("PHPInterpreterPreferencePage.addButton.label")); //$NON-NLS-1$
+    addButton.addListener(SWT.Selection, new Listener() {
+      public void handleEvent(Event evt) {
+        addInterpreter();
+      }
+    });
+
+    editButton = new Button(buttons, SWT.PUSH);
+    editButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+    editButton.setText(PHPDebugUiMessages.getString("PHPInterpreterPreferencePage.editButton.label")); //$NON-NLS-1$
+    editButton.addListener(SWT.Selection, new Listener() {
+      public void handleEvent(Event evt) {
+        editInterpreter();
+      }
+    });
+
+    removeButton = new Button(buttons, SWT.PUSH);
+    removeButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+    removeButton.setText(PHPDebugUiMessages.getString("PHPInterpreterPreferencePage.removeButton.label")); //$NON-NLS-1$
+    removeButton.addListener(SWT.Selection, new Listener() {
+      public void handleEvent(Event evt) {
+        removeInterpreter();
+      }
+    });
+  }
+
+  protected void createInstalledInterpretersTableViewer(Table table) {
+    tableViewer = new CheckboxTableViewer(table);
+
+    tableViewer.setLabelProvider(new PHPInterpreterLabelProvider());
+    tableViewer.setContentProvider(new PHPInterpreterContentProvider());
+
+    tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+      public void selectionChanged(SelectionChangedEvent evt) {
+        enableButtons();
+      }
+    });
+
+    tableViewer.addCheckStateListener(new ICheckStateListener() {
+      public void checkStateChanged(CheckStateChangedEvent event) {
+        updateSelectedInterpreter(event.getElement());
+      }
+    });
+
+    tableViewer.addDoubleClickListener(new IDoubleClickListener() {
+      public void doubleClick(DoubleClickEvent e) {
+        editInterpreter();
+      }
+    });
+  }
+
+  protected Table createInstalledInterpretersTable(Composite composite) {
+    Table table = new Table(composite, SWT.CHECK | SWT.BORDER | SWT.FULL_SELECTION);
+
+    GridData data = new GridData(GridData.FILL_BOTH);
+    data.widthHint = convertWidthInCharsToPixels(80);
+    data.heightHint = convertHeightInCharsToPixels(10);
+    table.setLayoutData(data);
+    table.setHeaderVisible(true);
+    table.setLinesVisible(false);
+
+    TableColumn column = new TableColumn(table, SWT.NULL);
+    column.setText(PHPDebugUiMessages.getString("PHPInterpreterPreferencePage.PHPInterpreterTable.interpreterPath")); //$NON-NLS-1$
+    column.setWidth(400);
+
+    //    column = new TableColumn(table, SWT.NULL);
+    //    column.setText(PHPDebugUiMessages.getString("PHPInterpreterPreferencePage.PHPInterpreterTable.interpreterPath"));
+    // //$NON-NLS-1$
+    //    column.setWidth(350);
+
+    return table;
+  }
+
+  protected Composite createPageRoot(Composite parent) {
+    Composite composite = new Composite(parent, SWT.NULL);
+    GridLayout layout = new GridLayout();
+    layout.numColumns = 2;
+    composite.setLayout(layout);
+    return composite;
+  }
+
+  protected void addInterpreter() {
+    PHPInterpreter newInterpreter = new PHPInterpreter(null);
+    File phpRuntime = getFile(getShell(), null);
+    if (phpRuntime != null) {
+      newInterpreter.setInstallLocation(phpRuntime);
+      tableViewer.add(newInterpreter);
+    }
+  }
+
+  protected void removeInterpreter() {
+    tableViewer.remove(getSelectedInterpreter());
+  }
+
+  protected void enableButtons() {
+    if (getSelectedInterpreter() != null) {
+      editButton.setEnabled(true);
+      removeButton.setEnabled(true);
+    } else {
+      editButton.setEnabled(false);
+      removeButton.setEnabled(false);
+    }
+  }
+
+  protected void updateSelectedInterpreter(Object interpreter) {
+    Object[] checkedElements = tableViewer.getCheckedElements();
+    for (int i = 0; i < checkedElements.length; i++) {
+      tableViewer.setChecked(checkedElements[i], false);
+    }
+
+    tableViewer.setChecked(interpreter, true);
+  }
+
+  protected void editInterpreter() {
+    PHPInterpreter anInterpreter = getSelectedInterpreter();
+    File phpRuntime = anInterpreter.getInstallLocation();
+    if (phpRuntime != null) {
+      File parent = phpRuntime.getParentFile();
+      phpRuntime = getFile(getShell(), parent);
+    } else {
+      phpRuntime = getFile(getShell(), null);
+    }
+    if (phpRuntime != null) {
+      anInterpreter.setInstallLocation(phpRuntime);
+      tableViewer.update(anInterpreter, null);
+    }
+
+  }
+
+  protected PHPInterpreter getSelectedInterpreter() {
+    IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
+    return (PHPInterpreter) selection.getFirstElement();
+  }
+
+  public boolean performOk() {
+    TableItem[] tableItems = tableViewer.getTable().getItems();
+    List installedInterpreters = new ArrayList(tableItems.length);
+    for (int i = 0; i < tableItems.length; i++)
+      installedInterpreters.add(tableItems[i].getData());
+    PHPRuntime.getDefault().setInstalledInterpreters(installedInterpreters);
+
+    Object[] checkedElements = tableViewer.getCheckedElements();
+    if (checkedElements.length > 0)
+      PHPRuntime.getDefault().setSelectedInterpreter((PHPInterpreter) checkedElements[0]);
+
+    return super.performOk();
+  }
+
+  /**
+   * Helper to open the file chooser dialog.
+   * 
+   * @param startingDirectory
+   *          the directory to open the dialog on.
+   * @return File The File the user selected or <code>null</code> if they do not.
+   */
+  public static File getFile(Shell shell, File startingDirectory) {
+
+    FileDialog dialog = new FileDialog(shell, SWT.OPEN);
+    if (startingDirectory != null) {
+      dialog.setFileName(startingDirectory.getPath());
+    }
+    String operatingSystem = Platform.getOS();
+    if (operatingSystem.equals(Platform.OS_WIN32)) {
+      String[] extensions = { "*.exe" };
+      dialog.setFilterExtensions(extensions);
+    }
+    String file = dialog.open();
+    if (file != null) {
+      file = file.trim();
+      if (file.length() > 0)
+        return new File(file);
+    }
+
+    return null;
+  }
 }
\ No newline at end of file
index 9a5b6ad..900019a 100644 (file)
@@ -19,6 +19,8 @@
       <import plugin="org.eclipse.core.resources"/>
       <import plugin="org.eclipse.ui"/>
       <import plugin="org.eclipse.debug.core"/>
+      <import plugin="org.eclipse.jface.text"/>
+      <import plugin="org.eclipse.ui.workbench.texteditor"/>
       <import plugin="net.sourceforge.phpeclipse"/>
       <import plugin="net.sourceforge.phpeclipse.debug.core"/>
       <import plugin="org.eclipse.debug.ui"/>
          </fileExtension>
       </launchConfigurationType>
    </extension>
-
+   
+  <extension
+         point="org.eclipse.debug.ui.consoleLineTrackers">
+      <consoleLineTracker
+            class="net.sourceforge.phpdt.internal.launching.ConsoleLineTracker"
+            processType="net.sourceforge.phpdt.launching.processType"
+            id="net.sourceforge.phpdt.internal.launching.ConsoleLineTracker">
+      </consoleLineTracker>
+  </extension>
+  
 </plugin>
\ No newline at end of file
diff --git a/net.sourceforge.phpeclipse.launching/src/net/sourceforge/phpdt/internal/launching/ConsoleLineTracker.java b/net.sourceforge.phpeclipse.launching/src/net/sourceforge/phpdt/internal/launching/ConsoleLineTracker.java
new file mode 100644 (file)
index 0000000..e1cf774
--- /dev/null
@@ -0,0 +1,144 @@
+package net.sourceforge.phpdt.internal.launching;
+
+import net.sourceforge.phpdt.core.JavaModelException;
+import net.sourceforge.phpeclipse.phpeditor.EditorUtility;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.debug.ui.console.IConsole;
+import org.eclipse.debug.ui.console.IConsoleHyperlink;
+import org.eclipse.debug.ui.console.IConsoleLineTracker;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.texteditor.ITextEditor;
+
+
+public class ConsoleLineTracker implements IConsoleLineTracker {
+    
+       private static class JavadocConsoleHyperLink implements IConsoleHyperlink {
+               
+               private IPath fExternalPath;
+               private int fLineNumber;
+
+               public JavadocConsoleHyperLink(IPath externalPath, int lineNumber) {
+                       fExternalPath= externalPath;
+                       fLineNumber= lineNumber;
+               }
+
+               /* (non-Javadoc)
+                * @see org.eclipse.debug.ui.console.IConsoleHyperlink#linkEntered()
+                */
+               public void linkEntered() {
+               }
+
+               /* (non-Javadoc)
+                * @see org.eclipse.debug.ui.console.IConsoleHyperlink#linkExited()
+                */
+               public void linkExited() {
+               }
+
+               /* (non-Javadoc)
+                * @see org.eclipse.debug.ui.console.IConsoleHyperlink#linkActivated()
+                */
+               public void linkActivated() {
+                       try {
+                               IFile[] files= ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(fExternalPath);
+                               if (files.length > 0) {
+                                       for (int i = 0; i < files.length; i++) {
+                                               IFile curr= files[0];
+                                               IEditorPart part= EditorUtility.openInEditor(curr, true);
+                                               if (part != null) {
+                                                       if (part instanceof ITextEditor) {
+                                                               revealLine((ITextEditor) part, fLineNumber);
+                                                       }
+                                                       return;
+                                               }
+                                       }
+                               }       
+                       } catch (BadLocationException e) {
+                               PHPLaunchingPlugin.log(e);
+                       } catch (PartInitException e) {
+                         PHPLaunchingPlugin.log(e);
+                       } catch (JavaModelException e) {
+                         PHPLaunchingPlugin.log(e);
+                       }
+               }
+               
+               private void revealLine(ITextEditor editor, int lineNumber) throws BadLocationException {
+                       IDocument document= editor.getDocumentProvider().getDocument(editor.getEditorInput());
+                       IRegion region= document.getLineInformation(lineNumber - 1);
+                       editor.selectAndReveal(region.getOffset(), 0);
+               }
+               
+       }
+       
+
+       private IConsole fConsole;
+       
+       public ConsoleLineTracker() {
+         super();
+       }
+       
+       /* (non-Javadoc)
+        * @see org.eclipse.debug.ui.console.IConsoleLineTracker#init(org.eclipse.debug.ui.console.IConsole)
+        */
+       public void init(IConsole console) {
+               fConsole= console;
+       }
+
+       /* (non-Javadoc)
+        * @see org.eclipse.debug.ui.console.IConsoleLineTracker#lineAppended(org.eclipse.jface.text.IRegion)
+        */
+       public void lineAppended(IRegion line) {
+               try {
+                       int offset = line.getOffset();
+                       int length = line.getLength();
+                       String text = fConsole.getDocument().get(offset, length);
+                       
+                       int index1= text.indexOf(':');
+                       if (index1 == -1) {
+                               return;
+                       }
+                       
+                       int lineNumber= -1;
+                       IPath path= null;
+                       int index2= text.indexOf(':', index1 + 1);
+                       while ((index2 != -1) && (path == null)) {
+                               if (index1 < index2) {
+                                       try {
+                                               String substr= text.substring(index1 + 1, index2);
+                                               lineNumber= Integer.parseInt(substr);
+                                               path= new Path(text.substring(0, index1));
+                                       } catch (NumberFormatException e) {
+                                               // ignore
+                                       }
+                               }
+                               index1= index2;
+                               index2= text.indexOf(':', index1 + 1);
+                       }
+                       
+                       if (lineNumber != -1) {
+                               JavadocConsoleHyperLink link= new JavadocConsoleHyperLink(path, lineNumber);
+                               fConsole.addLink(link, line.getOffset(), index1);
+
+                       }
+               } catch (BadLocationException e) {
+                       // ignore
+               }
+       }
+
+
+
+       /* (non-Javadoc)
+        * @see org.eclipse.debug.ui.console.IConsoleLineTracker#dispose()
+        */
+       public void dispose() {
+               fConsole = null;
+       }
+
+}
index a3be7fa..ee56530 100644 (file)
@@ -13,6 +13,8 @@ import org.eclipse.core.runtime.Path;
 import org.eclipse.core.runtime.Platform;
 import org.eclipse.debug.core.DebugPlugin;
 import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.debug.core.Launch;
 import org.eclipse.debug.core.model.IProcess;
 
 public class InterpreterRunner {
@@ -35,7 +37,8 @@ public class InterpreterRunner {
 
                IProcess process = DebugPlugin.newProcess(launch, nativePHPProcess, renderLabel(configuration));
                process.setAttribute(PHPLaunchingPlugin.PLUGIN_ID + ".launcher.cmdline", commandLine);
-
+        process.setAttribute(IProcess.ATTR_PROCESS_TYPE, PHPLaunchConfigurationAttribute.PHP_LAUNCH_PROCESS_TYPE);
+        
                return process ;
        }
 
index 151d5f0..f8b5ac1 100644 (file)
@@ -1,59 +1,98 @@
 package net.sourceforge.phpdt.internal.launching;
 
 import java.io.File;
+import java.io.FileWriter;
 import java.io.IOException;
+import java.util.ArrayList;
 
-import org.eclipse.core.runtime.IPath;
+import net.sourceforge.phpdt.internal.ui.phpdocexport.JavadocExportMessages;
+import net.sourceforge.phpdt.internal.ui.util.ExceptionHandler;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.IDebugEventSetListener;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.ILaunchConfigurationType;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.debug.core.Launch;
+import org.eclipse.debug.core.model.IProcess;
+import org.eclipse.debug.ui.IDebugUIConstants;
 
 public class PHPInterpreter {
-       //public final String endOfOptionsDelimeter = " -- ";
-
-       protected IPath installLocation;
-       protected String name;
-
-       public PHPInterpreter(String aName, IPath validInstallLocation) {
-               name = aName;
-               installLocation = validInstallLocation;
-       }
-
-       public IPath getInstallLocation() {
-               return installLocation;
-       }
-
-       public void setInstallLocation(IPath validInstallLocation) {
-               installLocation = validInstallLocation;
-       }
-       
-       public String getName() {
-               return name;
-       }
-       
-       public void setName(String newName) {
-               name = newName;
-       }
-       
-       public String getCommand() {
-               String directory = installLocation.toOSString() + File.separator;
-               if (new File(directory + "php.exe").isFile())
-                       return directory + "php.exe";
-
-               if (new File(directory, "php").isFile())
-                       return directory + "php";
-                       
-               return null;
-       }
-       
-       public Process exec(String arguments, File workingDirectory, String[] env) throws IOException {
-               return Runtime.getRuntime().exec(this.getCommand() + " " +  arguments, env, workingDirectory);
-       }
-       
-       public boolean equals(Object other) {
-               if (other instanceof PHPInterpreter) {
-                       PHPInterpreter otherInterpreter = (PHPInterpreter) other;
-                       if (name.equals(otherInterpreter.getName()))
-                               return installLocation.equals(otherInterpreter.getInstallLocation());
-               }
-               
-               return false;
-       }
-}
+
+  protected File installLocation;
+
+  public PHPInterpreter(File interpreter) {
+    installLocation = interpreter;
+  }
+
+  public File getInstallLocation() {
+    return installLocation;
+  }
+
+  public void setInstallLocation(File interpreter) {
+    installLocation = interpreter;
+  }
+
+  public String getCommand() {
+    return installLocation.toString();
+  }
+
+  private boolean executePHPProcess(String arguments, File workingDirectory, String[] env) {
+    Process process = null;
+    try {
+      StringBuffer buf = new StringBuffer();
+      buf.append(getCommand() + " " + arguments);
+      process = Runtime.getRuntime().exec(buf.toString(), env, workingDirectory);
+      if (process != null) {
+        // construct a formatted command line for the process properties
+
+        //                     for (int i= 0; i < args.length; i++) {
+        //                             buf.append(args[i]);
+        //                             buf.append(' ');
+        //                     }
+
+        ILaunchConfigurationWorkingCopy wc = null;
+        try {
+          ILaunchConfigurationType lcType = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationType(
+              PHPLaunchConfigurationAttribute.PHP_LAUNCH_CONFIGURATION_TYPE);
+          String name = "PHP Launcher"; //$NON-NLS-1$
+          wc = lcType.newInstance(null, name);
+          wc.setAttribute(IDebugUIConstants.ATTR_FAVORITE_GROUPS, true);
+
+          ILaunch newLaunch = new Launch(wc, ILaunchManager.RUN_MODE, null);
+          IProcess iprocess = DebugPlugin.newProcess(newLaunch, process, "PHP Process"); //$NON-NLS-1$
+          iprocess.setAttribute(IProcess.ATTR_CMDLINE, buf.toString());
+          iprocess.setAttribute(IProcess.ATTR_PROCESS_TYPE, PHPLaunchConfigurationAttribute.PHP_LAUNCH_PROCESS_TYPE);
+
+          DebugPlugin.getDefault().getLaunchManager().addLaunch(newLaunch);
+
+        } catch (CoreException e) {
+        }
+
+        return true;
+
+      }
+    } catch (IOException e) {
+      return false;
+    }
+    return false;
+
+  }
+
+  public Process exec(String arguments, File workingDirectory, String[] env) throws IOException {
+    return Runtime.getRuntime().exec(getCommand() + " " + arguments, env, workingDirectory);
+    //    executePHPProcess(arguments, workingDirectory, env);
+  }
+
+  public boolean equals(Object other) {
+    if (other instanceof PHPInterpreter) {
+      PHPInterpreter otherInterpreter = (PHPInterpreter) other;
+      return installLocation.equals(otherInterpreter.getInstallLocation());
+    }
+    return false;
+  }
+}
\ No newline at end of file
index cd05cf3..5cc70dc 100644 (file)
@@ -4,6 +4,7 @@ package net.sourceforge.phpdt.internal.launching;
 
 public interface PHPLaunchConfigurationAttribute {
        static final String PHP_LAUNCH_CONFIGURATION_TYPE = "net.sourceforge.phpdt.launching.LaunchConfigurationTypePHPApplication";
+       static final String PHP_LAUNCH_PROCESS_TYPE = "net.sourceforge.phpdt.launching.processType";
 
        static final String CUSTOM_LOAD_PATH = PHPLaunchingPlugin.PLUGIN_ID + ".CUSTOM_LOAD_PATH";
        static final String FILE_NAME = PHPLaunchingPlugin.PLUGIN_ID + ".FILE_NAME";
index f454e62..0613535 100644 (file)
@@ -49,11 +49,11 @@ public class PHPRuntime {
                return selectedInterpreter;
        }
 
-       public PHPInterpreter getInterpreter(String name) {
+       public PHPInterpreter getInterpreter(String installLocation) {
                Iterator interpreters = getInstalledInterpreters().iterator();
                while(interpreters.hasNext()) {
                        PHPInterpreter each = (PHPInterpreter) interpreters.next();
-                       if (each.getName().equals(name))
+                       if (each.getInstallLocation().toString().equals(installLocation))
                                return each;
                }
                
@@ -129,7 +129,7 @@ public class PHPRuntime {
                                writer.write("<interpreter name=\"");
                                
                                PHPInterpreter entry = (PHPInterpreter) interpretersIterator.next();
-                               writer.write(entry.getName());
+//                             writer.write(entry.getName());
                                writer.write("\" path=\"");
                                writer.write(entry.getInstallLocation().toString());
                                writer.write("\"");
@@ -154,9 +154,14 @@ public class PHPRuntime {
                        public void endPrefixMapping(String prefix) throws SAXException {}
                        public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
                                if ("interpreter".equals(qName)) {
-                                       String interpreterName = atts.getValue("name");
-                                       IPath installLocation = new Path(atts.getValue("path"));
-                                       PHPInterpreter interpreter = new PHPInterpreter(interpreterName, installLocation);
+                                       String interpreterName = atts.getValue("name");
+                                       java.io.File installLocation;
+                                       if (interpreterName!=null) {
+                                         installLocation = new File(atts.getValue("path")+File.separatorChar+interpreterName);
+                                       } else {
+                                         installLocation = new File(atts.getValue("path"));
+                                       }
+                                       PHPInterpreter interpreter = new PHPInterpreter(installLocation);
                                        installedInterpreters.add(interpreter);
                                        if (atts.getValue("selected") != null)
                                                selectedInterpreter = interpreter;