Debugger now steps through embedded PHP in HTML files.
[phpeclipse.git] / net.sourceforge.phpeclipse.debug.ui / src / net / sourceforge / phpdt / internal / debug / ui / PHPSourceLocator.java
diff --git a/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/PHPSourceLocator.java b/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/PHPSourceLocator.java
deleted file mode 100644 (file)
index 8dfbfdd..0000000
+++ /dev/null
@@ -1,163 +0,0 @@
-package net.sourceforge.phpdt.internal.debug.ui;
-
-import java.util.Iterator;
-import java.util.Map;
-
-import net.sourceforge.phpdt.internal.debug.core.model.PHPStackFrame;
-import net.sourceforge.phpdt.internal.launching.PHPLaunchConfigurationAttribute;
-import net.sourceforge.phpeclipse.PHPeclipsePlugin;
-import net.sourceforge.phpeclipse.builder.ExternalEditorInput;
-import net.sourceforge.phpeclipse.builder.FileStorage;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.debug.core.ILaunchConfiguration;
-import org.eclipse.debug.core.model.IPersistableSourceLocator;
-import org.eclipse.debug.core.model.IStackFrame;
-import org.eclipse.debug.ui.ISourcePresentation;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.part.FileEditorInput;
-
-public class PHPSourceLocator implements IPersistableSourceLocator, ISourcePresentation {
-  private String absoluteWorkingDirectory;
-  private Map pathMap = null;
-       private boolean remoteDebug;
-       private IPath remoteSourcePath;
-       private String projectName;
-
-  public PHPSourceLocator() {
-
-  }
-
-  public String getAbsoluteWorkingDirectory() {
-    return absoluteWorkingDirectory;
-  }
-  /**
-   * @see org.eclipse.debug.core.model.IPersistableSourceLocator#getMemento()
-   */
-  public String getMemento() throws CoreException {
-    return null;
-  }
-
-  /**
-   * @see org.eclipse.debug.core.model.IPersistableSourceLocator#initializeFromMemento(String)
-   */
-  public void initializeFromMemento(String memento) throws CoreException {
-  }
-
-  /**
-   * @see org.eclipse.debug.core.model.IPersistableSourceLocator#initializeDefaults(ILaunchConfiguration)
-   */
-  public void initializeDefaults(ILaunchConfiguration configuration) throws CoreException {
-    this.absoluteWorkingDirectory = configuration.getAttribute(PHPLaunchConfigurationAttribute.WORKING_DIRECTORY, "");
-               this.remoteDebug=configuration.getAttribute(PHPLaunchConfigurationAttribute.REMOTE_DEBUG,false);
-               this.pathMap = configuration.getAttribute(PHPLaunchConfigurationAttribute.FILE_MAP, (Map)null);
-               this.projectName =configuration.getAttribute(PHPLaunchConfigurationAttribute.PROJECT_NAME, "");
-               
-               if (Platform.getOS().equals(Platform.OS_WIN32))
-                       this.remoteSourcePath= new Path((configuration.getAttribute(PHPLaunchConfigurationAttribute.REMOTE_PATH, "")).toLowerCase());
-               else
-                       this.remoteSourcePath= new Path(configuration.getAttribute(PHPLaunchConfigurationAttribute.REMOTE_PATH, ""));
-               
-//             system.os.name
-
-  }
-
-  /**
-   * @see org.eclipse.debug.core.model.ISourceLocator#getSourceElement(IStackFrame)
-   */
-  public Object getSourceElement(IStackFrame stackFrame) {
-  
-               String fileName=((PHPStackFrame) stackFrame).getFileName();
-               String file="";
-                   
-    if (remoteDebug)
-    {
-                       IPath path = new Path(fileName);
-                       if (remoteSourcePath.isPrefixOf(path))
-                       {
-                               IPath projectPath;
-                               path=path.removeFirstSegments(remoteSourcePath.matchingFirstSegments(path));
-                               file=path.toString();
-                               projectPath=(PHPeclipsePlugin.getWorkspace().getRoot().getProject(projectName).getLocation());
-                               return (projectPath.append(path)).toOSString();
-                       }
-   
-                       if (pathMap == null) {
-                               return fileName;
-                       }
-                       Iterator iterator = pathMap.keySet().iterator();
-                       while (iterator.hasNext()) {
-                               String local = (String) iterator.next();
-                               IPath remotePath = new Path((String) pathMap.get(local));
-                               if (remotePath.isPrefixOf(path)) {
-                                       path=path.removeFirstSegments(remotePath.matchingFirstSegments(path));
-                                       IPath localPath= new Path(local);
-                                       return localPath.append(path).toOSString();
-                               }
-                       }
-                       return fileName;
-               } else {                
-                       return fileName;
-    }
-  }
-
-  /**
-   * @see org.eclipse.debug.ui.ISourcePresentation#getEditorId(IEditorInput, Object)
-   */
-  public String getEditorId(IEditorInput input, Object element) {
-    return PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor((String) element).getId();
-  }
-
-  /**
-   * @see org.eclipse.debug.ui.ISourcePresentation#getEditorInput(Object)
-   */
-  public IEditorInput getEditorInput(Object element) {
-
-    String filename = (String) element;
-    IWorkbench workbench = PlatformUI.getWorkbench();
-    IWorkbenchWindow window = workbench.getWorkbenchWindows()[0];
-    IWorkbenchPage page = window.getActivePage();
-    IPath path = new Path(filename);
-    
-    
-
-    // If the file exists in the workspace, open it
-    IFile eclipseFile = PHPeclipsePlugin.getWorkspace().getRoot().getFileForLocation(path);
-    //    IFile eclipseFile = PHPeclipsePlugin.getWorkspace().getRoot().getFileForLocation(new Path(filename));
-//    if (eclipseFile == null) {
-//      filename = this.getAbsoluteWorkingDirectory() + "/" + filename;
-//      eclipseFile = PHPeclipsePlugin.getWorkspace().getRoot().getFileForLocation(new Path(filename));
-//      if (eclipseFile == null) {
-//        PHPeclipsePlugin.log(IStatus.INFO, "Could not find file \"" + element + "\".");
-//        return null;
-//      }
-//    } else 
-    if (eclipseFile == null || !eclipseFile.exists()) {
-      //               Otherwise open the stream directly
-      if (page == null) {
-        PHPeclipsePlugin.log(IStatus.INFO, "Could not find file \"" + element + "\".");
-        return null;
-      }
-      FileStorage storage = new FileStorage(path);
-      storage.setReadOnly();
-      //      IEditorRegistry registry = workbench.getEditorRegistry();
-      //      IEditorDescriptor desc = registry.getDefaultEditor(filename);
-      //      if (desc == null) {
-      //        desc = registry.getDefaultEditor();
-      //      }
-      return new ExternalEditorInput(storage);
-    }
-    return new FileEditorInput(eclipseFile);
-
-  }
-
-}