From: khartlage Date: Wed, 12 Nov 2003 22:22:11 +0000 (+0000) Subject: view external project files in debugger mode X-Git-Url: http://secure.phpeclipse.com?hp=e4d0331a18738a30edd09f5e03565616aecef922 view external project files in debugger mode --- 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 index 8ff3848..07d0841 100644 --- 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 @@ -1,17 +1,26 @@ package net.sourceforge.phpdt.internal.debug.ui; +import net.sourceforge.phpdt.internal.debug.core.model.PHPStackFrame; import net.sourceforge.phpdt.internal.launching.PHPLaunchConfigurationAttribute; import net.sourceforge.phpeclipse.PHPeclipsePlugin; -import net.sourceforge.phpdt.internal.debug.core.model.PHPStackFrame; +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.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.IEditorDescriptor; import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IEditorRegistry; +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; @@ -49,14 +58,14 @@ public class PHPSourceLocator implements IPersistableSourceLocator, ISourcePrese * @see org.eclipse.debug.core.model.ISourceLocator#getSourceElement(IStackFrame) */ public Object getSourceElement(IStackFrame stackFrame) { - return ((PHPStackFrame) stackFrame).getFileName(); + return ((PHPStackFrame) stackFrame).getFileName(); } /** * @see org.eclipse.debug.ui.ISourcePresentation#getEditorId(IEditorInput, Object) */ public String getEditorId(IEditorInput input, Object element) { - return PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor((String)element).getId(); + return PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor((String) element).getId(); } /** @@ -65,14 +74,36 @@ public class PHPSourceLocator implements IPersistableSourceLocator, ISourcePrese public IEditorInput getEditorInput(Object element) { String filename = (String) element; - 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) { + 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); diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPSourceViewerConfiguration.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPSourceViewerConfiguration.java index 360da1e..7406714 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPSourceViewerConfiguration.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPSourceViewerConfiguration.java @@ -59,6 +59,7 @@ import org.eclipse.jface.text.source.ISourceViewer; import org.eclipse.jface.text.source.SourceViewerConfiguration; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IFileEditorInput; /** @@ -417,11 +418,14 @@ public class PHPSourceViewerConfiguration extends SourceViewerConfiguration { * Method declared on SourceViewerConfiguration */ public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) { - try { - IFile f = ((IFileEditorInput) fEditor.getEditorInput()).getFile(); - return new PHPTextHover(f.getProject()); - } catch (NullPointerException e) { - // this exception occurs, if getTextHover is called by preference pages ! + IEditorInput editorInput = fEditor.getEditorInput(); + if (editorInput instanceof IFileEditorInput) { + try { + IFile f = ((IFileEditorInput) editorInput).getFile(); + return new PHPTextHover(f.getProject()); + } catch (NullPointerException e) { + // this exception occurs, if getTextHover is called by preference pages ! + } } return new PHPTextHover(null); }