From: khartlage Date: Mon, 23 Dec 2002 21:31:38 +0000 (+0000) Subject: This commit was generated by cvs2svn to compensate for changes in r50, X-Git-Url: http://secure.phpeclipse.com This commit was generated by cvs2svn to compensate for changes in r50, which included commits to RCS files with non-trunk default branches. --- diff --git a/net.sourceforge.phpeclipse.debug.core/.classpath b/net.sourceforge.phpeclipse.debug.core/.classpath new file mode 100644 index 0000000..8f1260d --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.core/.classpath @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + diff --git a/net.sourceforge.phpeclipse.debug.core/.project b/net.sourceforge.phpeclipse.debug.core/.project new file mode 100644 index 0000000..375b066 --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.core/.project @@ -0,0 +1,29 @@ + + + net.sourceforge.phpeclipse.debug.core + + + net.sourceforge.phpeclipse + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.pde.PluginNature + + diff --git a/net.sourceforge.phpeclipse.debug.core/.template b/net.sourceforge.phpeclipse.debug.core/.template new file mode 100644 index 0000000..d65e0f4 --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.core/.template @@ -0,0 +1,4 @@ + +
+

Tips on working with this plug-in project

  • For the view of the new plug-in at a glance, go to the Overview.
  • You can test the contributions of this plug-in by launching another instance of the workbench. On the Run menu, click Run As and choose Run-time Workbench from the available choices.
  • You can add more functionality to this plug-in by adding extensions using the New Extension Wizard.
  • The plug-in project contains Java code that you can debug. Place breakpoints in Java classes. On the Run menu, select Debug As and choose Run-time Workbench from the available choices.
  • +
    diff --git a/net.sourceforge.phpeclipse.debug.core/build.properties b/net.sourceforge.phpeclipse.debug.core/build.properties new file mode 100644 index 0000000..9179bbb --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.core/build.properties @@ -0,0 +1 @@ +source.core.jar = src/ diff --git a/net.sourceforge.phpeclipse.debug.core/plugin.properties b/net.sourceforge.phpeclipse.debug.core/plugin.properties new file mode 100644 index 0000000..cf8b0bc --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.core/plugin.properties @@ -0,0 +1,2 @@ + +Plugin.name=PHPEclipse Debug Core diff --git a/net.sourceforge.phpeclipse.debug.core/plugin.xml b/net.sourceforge.phpeclipse.debug.core/plugin.xml new file mode 100644 index 0000000..9e5ccc5 --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.core/plugin.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + diff --git a/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/PHPDebugCorePlugin.java b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/PHPDebugCorePlugin.java new file mode 100644 index 0000000..e50fad3 --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/PHPDebugCorePlugin.java @@ -0,0 +1,40 @@ +package net.sourceforge.phpdt.internal.debug.core; + +import net.sourceforge.phpeclipse.PHPeclipsePlugin; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.runtime.IPluginDescriptor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Plugin; +import org.eclipse.core.runtime.Status; + +public class PHPDebugCorePlugin extends Plugin { + public static final String PLUGIN_ID = "net.sourceforge.phpeclipse.debug.core"; //$NON-NLS-1$ + + protected static PHPDebugCorePlugin plugin; + + public PHPDebugCorePlugin(IPluginDescriptor descriptor) { + super(descriptor); + plugin = this; + } + + public static PHPDebugCorePlugin getDefault() { + return plugin; + } + + public static IWorkspace getWorkspace() { + return PHPeclipsePlugin.getWorkspace(); + } + + public static void log(int severity, String message) { + Status status = new Status(severity, PLUGIN_ID, IStatus.OK, message, null) ; + PHPDebugCorePlugin.log(status) ; + } + + public static void log(IStatus status) { + getDefault().getLog().log(status); + } + + public static void log(Throwable e) { + log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "PHPLaunchingPlugin.internalErrorOccurred", e)); //$NON-NLS-1$ + } +} diff --git a/net.sourceforge.phpeclipse.debug.launching/.classpath b/net.sourceforge.phpeclipse.debug.launching/.classpath new file mode 100644 index 0000000..40e8710 --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.launching/.classpath @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + diff --git a/net.sourceforge.phpeclipse.debug.launching/.project b/net.sourceforge.phpeclipse.debug.launching/.project new file mode 100644 index 0000000..6472dbe --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.launching/.project @@ -0,0 +1,29 @@ + + + net.sourceforge.phpeclipse.launching + + + net.sourceforge.phpeclipse + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.pde.PluginNature + + diff --git a/net.sourceforge.phpeclipse.debug.launching/.template b/net.sourceforge.phpeclipse.debug.launching/.template new file mode 100644 index 0000000..d65e0f4 --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.launching/.template @@ -0,0 +1,4 @@ + +
    +

    Tips on working with this plug-in project

  • For the view of the new plug-in at a glance, go to the Overview.
  • You can test the contributions of this plug-in by launching another instance of the workbench. On the Run menu, click Run As and choose Run-time Workbench from the available choices.
  • You can add more functionality to this plug-in by adding extensions using the New Extension Wizard.
  • The plug-in project contains Java code that you can debug. Place breakpoints in Java classes. On the Run menu, select Debug As and choose Run-time Workbench from the available choices.
  • +
    diff --git a/net.sourceforge.phpeclipse.debug.launching/plugin.properties b/net.sourceforge.phpeclipse.debug.launching/plugin.properties new file mode 100644 index 0000000..973f149 --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.launching/plugin.properties @@ -0,0 +1,3 @@ + +Plugin.name=PHPEclipse Launching Support +LaunchConfigurationTypePHPApplication.name=PHP Application \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.debug.launching/plugin.xml b/net.sourceforge.phpeclipse.debug.launching/plugin.xml new file mode 100644 index 0000000..170f061 --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.launching/plugin.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.debug.launching/src/net/sourceforge/phpdt/internal/launching/InterpreterRunner.java b/net.sourceforge.phpeclipse.debug.launching/src/net/sourceforge/phpdt/internal/launching/InterpreterRunner.java new file mode 100644 index 0000000..5e76ed5 --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.launching/src/net/sourceforge/phpdt/internal/launching/InterpreterRunner.java @@ -0,0 +1,90 @@ +package net.sourceforge.phpdt.internal.launching; + +import java.io.File; +import java.io.IOException; +import java.util.Iterator; + +import net.sourceforge.phpeclipse.resourcesview.PHPProject; +import org.eclipse.core.boot.BootLoader; +import org.eclipse.core.resources.IProject; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.ILaunch; +import org.eclipse.debug.core.model.IProcess; + +public class InterpreterRunner { + + public InterpreterRunner() { + } + + public IProcess run(InterpreterRunnerConfiguration configuration, ILaunch launch) { + String commandLine = renderCommandLine(configuration); + File workingDirectory = configuration.getAbsoluteWorkingDirectory(); + + Process nativePHPProcess = null; + try { + nativePHPProcess = configuration.getInterpreter().exec(commandLine, workingDirectory); + } catch (IOException e) { + throw new RuntimeException("Unable to execute interpreter: " + commandLine + workingDirectory); + } + + IProcess process = DebugPlugin.getDefault().newProcess(launch, nativePHPProcess, renderLabel(configuration)); + process.setAttribute(PHPLaunchingPlugin.PLUGIN_ID + ".launcher.cmdline", commandLine); + return process ; + } + + protected String renderLabel(InterpreterRunnerConfiguration configuration) { + StringBuffer buffer = new StringBuffer(); + + PHPInterpreter interpreter = configuration.getInterpreter(); + buffer.append("PHP "); + buffer.append(interpreter.getCommand()); + buffer.append(" : "); + buffer.append(configuration.getFileName()); + + return buffer.toString(); + } + + protected String renderCommandLine(InterpreterRunnerConfiguration configuration) { + PHPInterpreter interpreter = configuration.getInterpreter(); + + StringBuffer buffer = new StringBuffer(); + buffer.append(this.getDebugCommandLineArgument()); + // buffer.append(renderLoadPath(configuration)); + buffer.append(" " + configuration.getInterpreterArguments()); + // buffer.append(interpreter.endOfOptionsDelimeter); + buffer.append(" " + osDependentPath(configuration.getAbsoluteFileName())); + buffer.append(" " + configuration.getProgramArguments()); + + return buffer.toString(); + } + +// protected String renderLoadPath(InterpreterRunnerConfiguration configuration) { +// StringBuffer loadPath = new StringBuffer(); +// +// PHPProject project = configuration.getProject(); +// addToLoadPath(loadPath, project.getProject()); +// +// Iterator referencedProjects = project.getReferencedProjects().iterator(); +// while (referencedProjects.hasNext()) +// addToLoadPath(loadPath, (IProject) referencedProjects.next()); +// +// return loadPath.toString(); +// } + +// protected void addToLoadPath(StringBuffer loadPath, IProject project) { +// +// loadPath.append(" -I " + osDependentPath(project.getLocation().toOSString())); +// } + + protected String osDependentPath(String aPath) { + if (BootLoader.getOS().equals(BootLoader.OS_WIN32)) + aPath = "\"" + aPath + "\""; + + return aPath; + } + + protected String getDebugCommandLineArgument() { + return "" ; + } + +} diff --git a/net.sourceforge.phpeclipse.debug.launching/src/net/sourceforge/phpdt/internal/launching/InterpreterRunnerConfiguration.java b/net.sourceforge.phpeclipse.debug.launching/src/net/sourceforge/phpdt/internal/launching/InterpreterRunnerConfiguration.java new file mode 100644 index 0000000..5af6d02 --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.launching/src/net/sourceforge/phpdt/internal/launching/InterpreterRunnerConfiguration.java @@ -0,0 +1,86 @@ +package net.sourceforge.phpdt.internal.launching; + +import java.io.File; + +import net.sourceforge.phpeclipse.resourcesview.PHPProject; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.debug.core.ILaunchConfiguration; + +public class InterpreterRunnerConfiguration { + protected ILaunchConfiguration configuration; + + public InterpreterRunnerConfiguration(ILaunchConfiguration aConfiguration) { + configuration = aConfiguration; + } + + public String getAbsoluteFileName() { + IPath path = new Path(getFileName()); + IProject project = getProject().getProject(); + + return project.getLocation().toOSString() + "/" + getFileName(); + } + + public String getFileName() { + String fileName = ""; + + try { + fileName = configuration.getAttribute(PHPLaunchConfigurationAttribute.FILE_NAME, "No file specified in configuration"); + } catch(CoreException e) {} + + return fileName.replace('\\', '/'); + } + + public PHPProject getProject() { + String projectName = ""; + + try { + projectName = configuration.getAttribute(PHPLaunchConfigurationAttribute.PROJECT_NAME, ""); + } catch(CoreException e) { + PHPLaunchingPlugin.getDefault().log(e); + } + + IProject project = PHPLaunchingPlugin.getWorkspace().getRoot().getProject(projectName); + + PHPProject phpProject = new PHPProject(); + phpProject.setProject(project); + return phpProject; + } + + public File getAbsoluteWorkingDirectory() { + String file = null; + try { + file = configuration.getAttribute(PHPLaunchConfigurationAttribute.WORKING_DIRECTORY, ""); + } catch(CoreException e) { + PHPLaunchingPlugin.log(e); + } + return new File(file); + } + + public String getInterpreterArguments() { + try { + return configuration.getAttribute(PHPLaunchConfigurationAttribute.INTERPRETER_ARGUMENTS, ""); + } catch(CoreException e) {} + + return ""; + } + + public String getProgramArguments() { + try { + return configuration.getAttribute(PHPLaunchConfigurationAttribute.PROGRAM_ARGUMENTS, ""); + } catch (CoreException e) {} + + return ""; + } + + public PHPInterpreter getInterpreter() { + String selectedInterpreter = null; + try { + selectedInterpreter = configuration.getAttribute(PHPLaunchConfigurationAttribute.SELECTED_INTERPRETER, ""); + } catch(CoreException e) {} + + return PHPRuntime.getDefault().getInterpreter(selectedInterpreter); + } +} diff --git a/net.sourceforge.phpeclipse.debug.launching/src/net/sourceforge/phpdt/internal/launching/PHPInterpreter.java b/net.sourceforge.phpeclipse.debug.launching/src/net/sourceforge/phpdt/internal/launching/PHPInterpreter.java new file mode 100644 index 0000000..2e342b9 --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.launching/src/net/sourceforge/phpdt/internal/launching/PHPInterpreter.java @@ -0,0 +1,60 @@ +package net.sourceforge.phpdt.internal.launching; + +import java.io.File; +import java.io.IOException; + +import org.eclipse.core.internal.resources.OS; +import org.eclipse.core.runtime.IPath; + +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) throws IOException { + return Runtime.getRuntime().exec(this.getCommand() + " " + arguments, null, 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; + } +} diff --git a/net.sourceforge.phpeclipse.debug.launching/src/net/sourceforge/phpdt/internal/launching/PHPLaunchConfigurationAttribute.java b/net.sourceforge.phpeclipse.debug.launching/src/net/sourceforge/phpdt/internal/launching/PHPLaunchConfigurationAttribute.java new file mode 100644 index 0000000..d6b853e --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.launching/src/net/sourceforge/phpdt/internal/launching/PHPLaunchConfigurationAttribute.java @@ -0,0 +1,18 @@ +package net.sourceforge.phpdt.internal.launching; + + + +public interface PHPLaunchConfigurationAttribute { + static final String PHP_LAUNCH_CONFIGURATION_TYPE = "net.sourceforge.phpdt.launching.LaunchConfigurationTypePHPApplication"; + + static final String CUSTOM_LOAD_PATH = PHPLaunchingPlugin.PLUGIN_ID + ".CUSTOM_LOAD_PATH"; + static final String FILE_NAME = PHPLaunchingPlugin.PLUGIN_ID + ".FILE_NAME"; + static final String INTERPRETER_ARGUMENTS = PHPLaunchingPlugin.PLUGIN_ID + ".INTERPRETER_ARGUMENTS"; + static final String MODULE_NAME = PHPLaunchingPlugin.PLUGIN_ID + ".MODULE_NAME"; + static final String PROGRAM_ARGUMENTS = PHPLaunchingPlugin.PLUGIN_ID + ".PROGRAM_ARGUMENTS"; + static final String PROJECT_NAME = PHPLaunchingPlugin.PLUGIN_ID + ".PROJECT_NAME"; + static final String SELECTED_INTERPRETER = PHPLaunchingPlugin.PLUGIN_ID + ".SELECTED_INTERPRETER"; + static final String WORKING_DIRECTORY = PHPLaunchingPlugin.PLUGIN_ID + ".WORKING_DIRECTORY"; + static final String USE_DEFAULT_LOAD_PATH = PHPLaunchingPlugin.PLUGIN_ID + ".USE_DEFAULT_LOAD_PATH"; + static final String USE_DEFAULT_WORKING_DIRECTORY = PHPLaunchingPlugin.PLUGIN_ID + ".USE_DEFAULT_WORKING_DIRECTORY"; +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.debug.launching/src/net/sourceforge/phpdt/internal/launching/PHPLaunchConfigurationDelegate.java b/net.sourceforge.phpeclipse.debug.launching/src/net/sourceforge/phpdt/internal/launching/PHPLaunchConfigurationDelegate.java new file mode 100644 index 0000000..bbc6a9e --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.launching/src/net/sourceforge/phpdt/internal/launching/PHPLaunchConfigurationDelegate.java @@ -0,0 +1,34 @@ +package net.sourceforge.phpdt.internal.launching; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.debug.core.ILaunch; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.model.ILaunchConfigurationDelegate; + + +public class PHPLaunchConfigurationDelegate implements ILaunchConfigurationDelegate { + protected static final InterpreterRunner interpreterRunner = new InterpreterRunner(); +// protected static final DebuggerRunner debuggerRunner = new DebuggerRunner(); + + public PHPLaunchConfigurationDelegate() { + super(); + } + + /** + * @see ILaunchConfigurationDelegate#launch(ILaunchConfiguration, String, ILaunch, IProgressMonitor) + */ + public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException { + if (PHPRuntime.getDefault().getSelectedInterpreter() == null) + throw new CoreException(new Status(IStatus.ERROR, PHPLaunchingPlugin.PLUGIN_ID, IStatus.OK, "You must define an interpreter before running PHP.", null)); +// if (mode.equals("debug")) { +// debuggerRunner.run(new InterpreterRunnerConfiguration(configuration), launch); +// } else { + interpreterRunner.run(new InterpreterRunnerConfiguration(configuration), launch); +// } + } +} diff --git a/net.sourceforge.phpeclipse.debug.launching/src/net/sourceforge/phpdt/internal/launching/PHPLaunchingMessages.java b/net.sourceforge.phpeclipse.debug.launching/src/net/sourceforge/phpdt/internal/launching/PHPLaunchingMessages.java new file mode 100644 index 0000000..ca7ed89 --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.launching/src/net/sourceforge/phpdt/internal/launching/PHPLaunchingMessages.java @@ -0,0 +1,21 @@ +package net.sourceforge.phpdt.internal.launching; + +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +public class PHPLaunchingMessages { + + private static final String BUNDLE_NAME = PHPLaunchingMessages.class.getName(); + + private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME); + + private PHPLaunchingMessages() {} + + public static String getString(String key) { + try { + return RESOURCE_BUNDLE.getString(key); + } catch (MissingResourceException e) { + return '!' + key + '!'; + } + } +} diff --git a/net.sourceforge.phpeclipse.debug.launching/src/net/sourceforge/phpdt/internal/launching/PHPLaunchingMessages.properties b/net.sourceforge.phpeclipse.debug.launching/src/net/sourceforge/phpdt/internal/launching/PHPLaunchingMessages.properties new file mode 100644 index 0000000..bc2d362 --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.launching/src/net/sourceforge/phpdt/internal/launching/PHPLaunchingMessages.properties @@ -0,0 +1,6 @@ + +######################################### +# PHPLaunchingPlugin +######################################### + +PHPLaunchingPlugin.internalErrorOccurred=Internal error occurred \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.debug.launching/src/net/sourceforge/phpdt/internal/launching/PHPLaunchingPlugin.java b/net.sourceforge.phpeclipse.debug.launching/src/net/sourceforge/phpdt/internal/launching/PHPLaunchingPlugin.java new file mode 100644 index 0000000..dee7aa5 --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.launching/src/net/sourceforge/phpdt/internal/launching/PHPLaunchingPlugin.java @@ -0,0 +1,35 @@ +package net.sourceforge.phpdt.internal.launching; + +import net.sourceforge.phpeclipse.PHPeclipsePlugin; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.runtime.IPluginDescriptor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Plugin; +import org.eclipse.core.runtime.Status; + +public class PHPLaunchingPlugin extends Plugin { + public static final String PLUGIN_ID = "net.sourceforge.phpeclipse.launching"; //$NON-NLS-1$ + + protected static PHPLaunchingPlugin plugin; + + public PHPLaunchingPlugin(IPluginDescriptor descriptor) { + super(descriptor); + plugin = this; + } + + public static PHPLaunchingPlugin getDefault() { + return plugin; + } + + public static IWorkspace getWorkspace() { + return PHPeclipsePlugin.getWorkspace(); + } + + public static void log(IStatus status) { + getDefault().getLog().log(status); + } + + public static void log(Throwable e) { + log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, PHPLaunchingMessages.getString("PHPLaunchingPlugin.internalErrorOccurred"), e)); //$NON-NLS-1$ + } +} diff --git a/net.sourceforge.phpeclipse.debug.launching/src/net/sourceforge/phpdt/internal/launching/PHPRuntime.java b/net.sourceforge.phpeclipse.debug.launching/src/net/sourceforge/phpdt/internal/launching/PHPRuntime.java new file mode 100644 index 0000000..03447e1 --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.launching/src/net/sourceforge/phpdt/internal/launching/PHPRuntime.java @@ -0,0 +1,174 @@ +package net.sourceforge.phpdt.internal.launching; + +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.Reader; +import java.io.StringReader; +import java.io.Writer; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import javax.xml.parsers.SAXParserFactory; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.xml.sax.Attributes; +import org.xml.sax.ContentHandler; +import org.xml.sax.InputSource; +import org.xml.sax.Locator; +import org.xml.sax.SAXException; +import org.xml.sax.XMLReader; + +public class PHPRuntime { + protected static PHPRuntime runtime; + + protected List installedInterpreters; + protected PHPInterpreter selectedInterpreter; + protected PHPRuntime() { + super(); + } + + public static PHPRuntime getDefault() { + if (runtime == null) { + runtime = new PHPRuntime(); + } + return runtime; + } + + public PHPInterpreter getSelectedInterpreter() { + if (selectedInterpreter == null) { + loadRuntimeConfiguration(); + } + return selectedInterpreter; + } + + public PHPInterpreter getInterpreter(String name) { + Iterator interpreters = getInstalledInterpreters().iterator(); + while(interpreters.hasNext()) { + PHPInterpreter each = (PHPInterpreter) interpreters.next(); + if (each.getName().equals(name)) + return each; + } + + return getSelectedInterpreter(); + } + + public void setSelectedInterpreter(PHPInterpreter anInterpreter) { + selectedInterpreter = anInterpreter; + saveRuntimeConfiguration(); + } + + public void addInstalledInterpreter(PHPInterpreter anInterpreter) { + getInstalledInterpreters().add(anInterpreter); + if (getInstalledInterpreters().size() == 1) + setSelectedInterpreter((PHPInterpreter) getInstalledInterpreters().get(0)); + + saveRuntimeConfiguration(); + } + + public List getInstalledInterpreters() { + if (installedInterpreters == null) + loadRuntimeConfiguration(); + return installedInterpreters; + } + + public void setInstalledInterpreters(List newInstalledInterpreters) { + installedInterpreters = newInstalledInterpreters; + if (installedInterpreters.size() > 0) + setSelectedInterpreter((PHPInterpreter)installedInterpreters.get(0)); + else + setSelectedInterpreter(null); + } + + protected void saveRuntimeConfiguration() { + writeXML(getRuntimeConfigurationWriter()); + } + + protected Writer getRuntimeConfigurationWriter() { + try { + OutputStream stream = new BufferedOutputStream(new FileOutputStream(getRuntimeConfigurationFile())); + return new OutputStreamWriter(stream); + } catch (FileNotFoundException e) {} + + return null; + } + + protected void loadRuntimeConfiguration() { + installedInterpreters = new ArrayList(); + try { + XMLReader reader = SAXParserFactory.newInstance().newSAXParser().getXMLReader(); + reader.setContentHandler(getRuntimeConfigurationContentHandler()); + reader.parse(new InputSource(getRuntimeConfigurationReader())); + } catch(Exception e) { + PHPLaunchingPlugin.getDefault().log(e); + } + } + + protected Reader getRuntimeConfigurationReader() { + try { + return new FileReader(getRuntimeConfigurationFile()); + } catch(FileNotFoundException e) {} + return new StringReader(""); + } + + protected void writeXML(Writer writer) { + try { + writer.write(""); + Iterator interpretersIterator = installedInterpreters.iterator(); + while (interpretersIterator.hasNext()) { + writer.write(""); + } + writer.write(""); + writer.flush(); + } catch(IOException e) { + PHPLaunchingPlugin.log(e); + } + } + + protected ContentHandler getRuntimeConfigurationContentHandler() { + return new ContentHandler() { + public void setDocumentLocator(Locator locator) {} + public void startDocument() throws SAXException {} + public void endDocument() throws SAXException {} + public void startPrefixMapping(String prefix, String uri) throws SAXException {} + 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); + installedInterpreters.add(interpreter); + if (atts.getValue("selected") != null) + selectedInterpreter = interpreter; + } + } + public void endElement(String namespaceURI, String localName, String qName) throws SAXException {} + public void characters(char[] ch, int start, int length) throws SAXException {} + public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {} + public void processingInstruction(String target, String data) throws SAXException {} + public void skippedEntity(String name) throws SAXException {} + }; + } + + protected File getRuntimeConfigurationFile() { + IPath stateLocation = PHPLaunchingPlugin.getDefault().getStateLocation(); + IPath fileLocation = stateLocation.append("runtimeConfiguration.xml"); + return new File(fileLocation.toOSString()); + } +} diff --git a/net.sourceforge.phpeclipse.debug.phphelp/.classpath b/net.sourceforge.phpeclipse.debug.phphelp/.classpath new file mode 100644 index 0000000..8a77a77 --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.phphelp/.classpath @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + diff --git a/net.sourceforge.phpeclipse.debug.phphelp/.project b/net.sourceforge.phpeclipse.debug.phphelp/.project new file mode 100644 index 0000000..39448c4 --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.phphelp/.project @@ -0,0 +1,29 @@ + + + net.sourceforge.phpeclipse.phphelp + + + net.sourceforge.phpeclipse + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.pde.PluginNature + + diff --git a/net.sourceforge.phpeclipse.debug.phphelp/.template b/net.sourceforge.phpeclipse.debug.phphelp/.template new file mode 100644 index 0000000..d65e0f4 --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.phphelp/.template @@ -0,0 +1,4 @@ + +
    +

    Tips on working with this plug-in project

  • For the view of the new plug-in at a glance, go to the Overview.
  • You can test the contributions of this plug-in by launching another instance of the workbench. On the Run menu, click Run As and choose Run-time Workbench from the available choices.
  • You can add more functionality to this plug-in by adding extensions using the New Extension Wizard.
  • The plug-in project contains Java code that you can debug. Place breakpoints in Java classes. On the Run menu, select Debug As and choose Run-time Workbench from the available choices.
  • +
    diff --git a/net.sourceforge.phpeclipse.debug.phphelp/phphelp.xml b/net.sourceforge.phpeclipse.debug.phphelp/phphelp.xml new file mode 100644 index 0000000..8e19278 --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.phphelp/phphelp.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.debug.phphelp/plugin.properties b/net.sourceforge.phpeclipse.debug.phphelp/plugin.properties new file mode 100644 index 0000000..0a31e89 --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.phphelp/plugin.properties @@ -0,0 +1,5 @@ +######################################### +# +######################################### +pluginName=PHP Plugin Help +providerName=EclipseProject.de diff --git a/net.sourceforge.phpeclipse.debug.phphelp/plugin.xml b/net.sourceforge.phpeclipse.debug.phphelp/plugin.xml new file mode 100644 index 0000000..8d80216 --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.phphelp/plugin.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/net.sourceforge.phpeclipse.debug.phphelp/src/net/sourceforge/phpdt/phphelp/actions/PHPEclipseShowContextHelp.java b/net.sourceforge.phpeclipse.debug.phphelp/src/net/sourceforge/phpdt/phphelp/actions/PHPEclipseShowContextHelp.java new file mode 100644 index 0000000..027eb91 --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.phphelp/src/net/sourceforge/phpdt/phphelp/actions/PHPEclipseShowContextHelp.java @@ -0,0 +1,96 @@ +/********************************************************************** +Copyright (c) 2000, 2002 IBM Corp. and others. +All rights reserved. This program and the accompanying materials +are made available under the terms of the Common Public License v1.0 +which accompanies this distribution, and is available at +http://www.eclipse.org/legal/cpl-v10.html + +Contributors: + IBM Corporation - Initial implementation + Klaus Hartlage - www.eclipseproject.de +**********************************************************************/ +package net.sourceforge.phpdt.phphelp.actions; + +import net.sourceforge.phpeclipse.phpeditor.PHPEditor; +import net.sourceforge.phpeclipse.phpeditor.php.PHPWordExtractor; +import org.eclipse.help.IHelp; +import org.eclipse.help.IHelpResource; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.ITextSelection; +import org.eclipse.jface.text.TextSelection; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.swt.graphics.Point; +import org.eclipse.ui.IEditorActionDelegate; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.actions.ActionDelegate; +import org.eclipse.ui.help.WorkbenchHelp; + +public class PHPEclipseShowContextHelp extends ActionDelegate implements IEditorActionDelegate { + + private IWorkbenchWindow window; + private PHPEditor editor; + + public void dispose() { + } + + public void init(IWorkbenchWindow window) { + this.window = window; + } + + public void selectionChanged(IAction action, ISelection selection) { + if (!selection.isEmpty()) { + if (selection instanceof TextSelection) { + action.setEnabled(true); + } else if (window.getActivePage() != null && window.getActivePage().getActivePart() != null) { + // + } + } + } + + public void run(IAction action) { + if (editor == null) { + IEditorPart targetEditor = window.getActivePage().getActiveEditor(); + if (targetEditor != null && (targetEditor instanceof PHPEditor)) { + editor = (PHPEditor) targetEditor; + } + } + if (editor != null) { + editor.openContextHelp(); + } + } + + public void setActiveEditor(IAction action, IEditorPart targetEditor) { + if (targetEditor != null && (targetEditor instanceof PHPEditor)) { + editor = (PHPEditor) targetEditor; + IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput()); + ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection(); + int pos = selection.getOffset(); + String word = getFunctionName(doc, pos); + openContextHelp(word); + } + } + + public static void openContextHelp(String word) { + IHelp help = WorkbenchHelp.getHelpSupport(); + if (help != null) { + IHelpResource helpResource = new PHPFunctionHelpResource(word); + WorkbenchHelp.getHelpSupport().displayHelpResource(helpResource); + } else { + // showMessage(shell, dialogTitle, ActionMessages.getString("Open help not available"), false); //$NON-NLS-1$ + } + } + + private String getFunctionName(IDocument doc, int pos) { + Point word = PHPWordExtractor.findWord(doc, pos); + if (word != null) { + try { + return doc.get(word.x, word.y).replace('_', '-'); + } catch (BadLocationException e) { + } + } + return ""; + } +} diff --git a/net.sourceforge.phpeclipse.debug.phphelp/src/net/sourceforge/phpdt/phphelp/actions/PHPFunctionHelpResource.java b/net.sourceforge.phpeclipse.debug.phphelp/src/net/sourceforge/phpdt/phphelp/actions/PHPFunctionHelpResource.java new file mode 100644 index 0000000..7f0249f --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.phphelp/src/net/sourceforge/phpdt/phphelp/actions/PHPFunctionHelpResource.java @@ -0,0 +1,35 @@ +/********************************************************************** +Copyright (c) 2000, 2002 IBM Corp. and others. +All rights reserved. This program and the accompanying materials +are made available under the terms of the Common Public License v1.0 +which accompanies this distribution, and is available at +http://www.eclipse.org/legal/cpl-v10.html + +Contributors: + IBM Corporation - Initial implementation + Klaus Hartlage - www.eclipseproject.de +**********************************************************************/ +package net.sourceforge.phpdt.phphelp.actions; + +import org.eclipse.help.IHelpResource; + +/** + * + */ +public class PHPFunctionHelpResource implements IHelpResource { + + private String word; + + public PHPFunctionHelpResource(String word) { + this.word = word; + } + + public String getHref() { + return "/net.sourceforge.phpeclipse.phphelp/doc/function." + word + ".html"; + } + + public String getLabel() { + return "PHP Context Help"; + } + +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.debug.ui/.classpath b/net.sourceforge.phpeclipse.debug.ui/.classpath new file mode 100644 index 0000000..93f4cb0 --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.ui/.classpath @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + diff --git a/net.sourceforge.phpeclipse.debug.ui/.project b/net.sourceforge.phpeclipse.debug.ui/.project new file mode 100644 index 0000000..5cfad78 --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.ui/.project @@ -0,0 +1,30 @@ + + + net.sourceforge.phpeclipse.debug.ui + + + net.sourceforge.phpeclipse + net.sourceforge.phpeclipse.launching + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.pde.PluginNature + + diff --git a/net.sourceforge.phpeclipse.debug.ui/.template b/net.sourceforge.phpeclipse.debug.ui/.template new file mode 100644 index 0000000..d65e0f4 --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.ui/.template @@ -0,0 +1,4 @@ + +
    +

    Tips on working with this plug-in project

  • For the view of the new plug-in at a glance, go to the Overview.
  • You can test the contributions of this plug-in by launching another instance of the workbench. On the Run menu, click Run As and choose Run-time Workbench from the available choices.
  • You can add more functionality to this plug-in by adding extensions using the New Extension Wizard.
  • The plug-in project contains Java code that you can debug. Place breakpoints in Java classes. On the Run menu, select Debug As and choose Run-time Workbench from the available choices.
  • +
    diff --git a/net.sourceforge.phpeclipse.debug.ui/icons/ctool16/run_php.gif b/net.sourceforge.phpeclipse.debug.ui/icons/ctool16/run_php.gif new file mode 100644 index 0000000..f01f87e Binary files /dev/null and b/net.sourceforge.phpeclipse.debug.ui/icons/ctool16/run_php.gif differ diff --git a/net.sourceforge.phpeclipse.debug.ui/icons/dtool16/run_php.gif b/net.sourceforge.phpeclipse.debug.ui/icons/dtool16/run_php.gif new file mode 100644 index 0000000..f01f87e Binary files /dev/null and b/net.sourceforge.phpeclipse.debug.ui/icons/dtool16/run_php.gif differ diff --git a/net.sourceforge.phpeclipse.debug.ui/icons/eview16/arguments_tab.gif b/net.sourceforge.phpeclipse.debug.ui/icons/eview16/arguments_tab.gif new file mode 100644 index 0000000..8670a38 Binary files /dev/null and b/net.sourceforge.phpeclipse.debug.ui/icons/eview16/arguments_tab.gif differ diff --git a/net.sourceforge.phpeclipse.debug.ui/plugin.properties b/net.sourceforge.phpeclipse.debug.ui/plugin.properties new file mode 100644 index 0000000..0882208 --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.ui/plugin.properties @@ -0,0 +1,7 @@ + +Plugin.name=PHPEclipse Debug UI + +PreferencePage.PHPBase.name=PHP +PreferencePage.PHPInterpreter.name=Installed Interpreters + +LaunchShortcut.PHP.label=PHP Application \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.debug.ui/plugin.xml b/net.sourceforge.phpeclipse.debug.ui/plugin.xml new file mode 100644 index 0000000..cbc9276 --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.ui/plugin.xml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/debug/ui/PHPDebugUiConstants.java b/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/debug/ui/PHPDebugUiConstants.java new file mode 100644 index 0000000..d2a0475 --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/debug/ui/PHPDebugUiConstants.java @@ -0,0 +1,9 @@ +package net.sourceforge.phpdt.debug.ui; + +import net.sourceforge.phpdt.internal.debug.ui.PHPDebugUiPlugin; + +public interface PHPDebugUiConstants { + public static final String DEFAULT_WORKING_DIRECTORY = PHPDebugUiPlugin.getWorkspace().getRoot().getLocation().toString(); + + public static final String PREFERENCE_KEYWORDS = PHPDebugUiPlugin.PLUGIN_ID + ".preference_keywords"; +} diff --git a/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/debug/ui/PHPDebugUiImages.java b/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/debug/ui/PHPDebugUiImages.java new file mode 100644 index 0000000..787fe19 --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/debug/ui/PHPDebugUiImages.java @@ -0,0 +1,112 @@ +package net.sourceforge.phpdt.debug.ui; + +import java.net.MalformedURLException; +import java.net.URL; + +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.resource.ImageRegistry; +import org.eclipse.swt.graphics.Image; +import net.sourceforge.phpdt.internal.debug.ui.PHPDebugUiPlugin; + +public class PHPDebugUiImages { + + protected static final String NAME_PREFIX = "net.sourceforge.phpdt.debug.ui."; + protected static final int NAME_PREFIX_LENGTH = NAME_PREFIX.length(); + protected static URL iconBaseURL; + + static { + String pathSuffix = "icons/"; + try { + iconBaseURL = new URL(PHPDebugUiPlugin.getDefault().getDescriptor().getInstallURL(), pathSuffix); + } catch (MalformedURLException e) { + PHPDebugUiPlugin.log(e); + } + } + + protected static final ImageRegistry IMAGE_REGISTRY = new ImageRegistry(); + + protected static final String CTOOL_PREFIX = "ctool16"; + protected static final String EVIEW_PREFIX = "eview16"; + + public static final String IMG_EVIEW_ARGUMENTS_TAB = NAME_PREFIX + "arguments_tab.gif"; + + public static final ImageDescriptor DESC_EVIEW_ARGUMENTS_TAB = createManaged(EVIEW_PREFIX, IMG_EVIEW_ARGUMENTS_TAB); + + /** + * Returns the image managed under the given key in this registry. + * + * @param key the image's key + * @return the image managed under the given key + */ + public static Image get(String key) { + return IMAGE_REGISTRY.get(key); + } + + /** + * Sets the three image descriptors for enabled, disabled, and hovered to an action. The actions + * are retrieved from the *tool16 folders. + */ + public static void setToolImageDescriptors(IAction action, String iconName) { + setImageDescriptors(action, "tool16", iconName); + } + + /** + * Sets the three image descriptors for enabled, disabled, and hovered to an action. The actions + * are retrieved from the *lcl16 folders. + */ + public static void setLocalImageDescriptors(IAction action, String iconName) { + setImageDescriptors(action, "lcl16", iconName); + } + + public static ImageRegistry getImageRegistry() { + return IMAGE_REGISTRY; + } + + //---- Helper methods to access icons on the file system -------------------------------------- + + protected static void setImageDescriptors(IAction action, String type, String relPath) { + + try { + ImageDescriptor id = ImageDescriptor.createFromURL(makeIconFileURL("d" + type, relPath)); + if (id != null) + action.setDisabledImageDescriptor(id); + } catch (MalformedURLException e) {} + + try { + ImageDescriptor id = ImageDescriptor.createFromURL(makeIconFileURL("c" + type, relPath)); + if (id != null) + action.setHoverImageDescriptor(id); + } catch (MalformedURLException e) {} + + action.setImageDescriptor(create("e" + type, relPath)); + } + + protected static ImageDescriptor createManaged(String prefix, String name) { + try { + ImageDescriptor result = ImageDescriptor.createFromURL(makeIconFileURL(prefix, name.substring(NAME_PREFIX_LENGTH))); + IMAGE_REGISTRY.put(name, result); + return result; + } catch (MalformedURLException e) { + return ImageDescriptor.getMissingImageDescriptor(); + } + } + + protected static ImageDescriptor create(String prefix, String name) { + try { + return ImageDescriptor.createFromURL(makeIconFileURL(prefix, name)); + } catch (MalformedURLException e) { + return ImageDescriptor.getMissingImageDescriptor(); + } + } + + protected static URL makeIconFileURL(String prefix, String name) throws MalformedURLException { + if (iconBaseURL == null) + throw new MalformedURLException(); + + StringBuffer buffer = new StringBuffer(prefix); + buffer.append('/'); + buffer.append(name); + return new URL(iconBaseURL, buffer.toString()); + } +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/PHPDebugUiMessages.java b/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/PHPDebugUiMessages.java new file mode 100644 index 0000000..dc23fa0 --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/PHPDebugUiMessages.java @@ -0,0 +1,29 @@ +package net.sourceforge.phpdt.internal.debug.ui; + +import java.text.MessageFormat; +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +public class PHPDebugUiMessages { + + private static final String BUNDLE_NAME = PHPDebugUiMessages.class.getName(); + private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME); + + private PHPDebugUiMessages() {} + + public static String getString(String key) { + try { + return RESOURCE_BUNDLE.getString(key); + } catch (MissingResourceException e) { + return '!' + key + '!'; + } + } + + public static String getFormattedString(String key, Object arg) { + return MessageFormat.format(getString(key), new Object[] { arg }); + } + + public static String getFormattedString(String key, Object[] args) { + return MessageFormat.format(getString(key), args); + } +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/PHPDebugUiMessages.properties b/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/PHPDebugUiMessages.properties new file mode 100644 index 0000000..ec9e132 --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/PHPDebugUiMessages.properties @@ -0,0 +1,52 @@ + +######################################### +# LaunchConfigurationTab +######################################### + +LaunchConfigurationTab.PHPArguments.name=Arguments +LaunchConfigurationTab.PHPArguments.working_dir=Working Directory: +LaunchConfigurationTab.PHPArguments.working_dir_browser_message=Select a working directory for the launch configuration +LaunchConfigurationTab.PHPArguments.working_dir_use_default_message=Use default working directory +LaunchConfigurationTab.PHPArguments.working_dir_error_message=Invalid working directory +LaunchConfigurationTab.PHPArguments.interpreter_args_box_title=Interpreter Arguments: +LaunchConfigurationTab.PHPArguments.program_args_box_title=Program Arguments: + +LaunchConfigurationTab.PHPEntryPoint.name=File +LaunchConfigurationTab.PHPEntryPoint.projectLabel=Project: +LaunchConfigurationTab.PHPEntryPoint.projectSelectorMessage=Choose the project containing the application entry point: +LaunchConfigurationTab.PHPEntryPoint.invalidProjectSelectionMessage=Invalid project selection. +LaunchConfigurationTab.PHPEntryPoint.fileLabel=File: +LaunchConfigurationTab.PHPEntryPoint.fileSelectorMessage=Choose the PHP file that represents the application entry point: +LaunchConfigurationTab.PHPEntryPoint.invalidFileSelectionMessage=Invalid PHP file. + +LaunchConfigurationTab.PHPEnvironment.name=Environment +LaunchConfigurationTab.PHPEnvironment.loadPathTab.label=Load&path +LaunchConfigurationTab.PHPEnvironment.loadPathDefaultButton.label=&Use default loadpath +LaunchConfigurationTab.PHPEnvironment.interpreterAddButton.label=N&ew... +LaunchConfigurationTab.PHPEnvironment.interpreterTab.label=&Interpreter +LaunchConfigurationTab.PHPEnvironment.editInterpreterDialog.title=Add Interpreter +LaunchConfigurationTab.PHPEnvironment.interpreter_not_selected_error_message=No interpreter has been selected + +LaunchConfigurationShortcut.PHP.multipleConfigurationsError=The file you are trying to launch has multiple configurations associated with it.\nPlease launch using 'Run...' and choose a configuration. + +######################################### +# PHP Interpreter configuration +######################################### + +EditInterpreterDialog.PHPInterpreter.path.label=Location: +EditInterpreterDialog.PHPInterpreter.path.browse.button.label=Browse... +EditInterpreterDialog.PHPInterpreter.path.error=The directory containing PHP must be selected +EditInterpreterDialog.PHPInterpreter.name=Interpreter Name: +EditInterpreterDialog.PHPInterpreter.name.error=Name cannot be empty +EditInterpreterDialog.PHPInterpreter.path.browse.message=Choose location + +PHPInterpreterPreferencePage.addButton.label=Add +PHPInterpreterPreferencePage.editButton.label=Edit +PHPInterpreterPreferencePage.removeButton.label=Remove +PHPInterpreterPreferencePage.PHPInterpreterTable.interpreterName=Name +PHPInterpreterPreferencePage.PHPInterpreterTable.interpreterPath=Location + +PHPInterpreterPreferencePage.EditInterpreterDialog.addInterpreter.title=Add Interpreter +PHPInterpreterPreferencePage.EditInterpreterDialog.editInterpreter.title=Edit Interpreter + +PHPBasePreferencePage.label=General Properties diff --git a/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/PHPDebugUiPlugin.java b/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/PHPDebugUiPlugin.java new file mode 100644 index 0000000..971388a --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/PHPDebugUiPlugin.java @@ -0,0 +1,56 @@ +package net.sourceforge.phpdt.internal.debug.ui; + +import net.sourceforge.phpeclipse.PHPeclipsePlugin; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.runtime.IPluginDescriptor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import net.sourceforge.phpdt.debug.ui.PHPDebugUiConstants; + +public class PHPDebugUiPlugin extends AbstractUIPlugin { + public static final String PLUGIN_ID = "net.sourceforge.phpeclipse.debug.ui"; //$NON-NLS-1$ + protected static PHPDebugUiPlugin plugin; + + public PHPDebugUiPlugin(IPluginDescriptor descriptor) { + super(descriptor); + plugin = this; + } + + public static IWorkbenchWindow getActiveWorkbenchWindow() { + return getDefault().getWorkbench().getActiveWorkbenchWindow(); + } + + public static IWorkbenchPage getActivePage() { + return getDefault().getActiveWorkbenchWindow().getActivePage(); + } + + public static PHPDebugUiPlugin getDefault() { + return plugin; + } + + public static IWorkspace getWorkspace() { + return PHPeclipsePlugin.getWorkspace(); + } + + public static void log(IStatus status) { + getDefault().getLog().log(status); + } + + public static void log(Throwable e) { + log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, PHPDebugUiMessages.getString("RdtDebugUiPlugin.internalErrorOccurred"), e)); //$NON-NLS-1$ + } + +// protected void initializeDefaultPreferences(IPreferenceStore store) { +// super.initializeDefaultPreferences(store); +// +// store.setDefault(RdtDebugUiConstants.PREFERENCE_KEYWORDS, getDefaultKeywords()); +// } + +// protected String getDefaultKeywords() { +// return "class,def,end,if,module,new,puts,require,rescue,throw,while"; +// } +} diff --git a/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/PHPExecutionArgumentsPage.java b/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/PHPExecutionArgumentsPage.java new file mode 100644 index 0000000..bc3200b --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/PHPExecutionArgumentsPage.java @@ -0,0 +1,69 @@ +package net.sourceforge.phpdt.internal.debug.ui; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.QualifiedName; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.IWorkbenchPropertyPage; +import org.eclipse.ui.dialogs.PropertyPage; + +public class PHPExecutionArgumentsPage extends PropertyPage implements IWorkbenchPropertyPage { + protected Text interpreterArgumentsText, programArgumentsText; + + public PHPExecutionArgumentsPage() { + } + + protected Control createContents(Composite parent) { + noDefaultAndApplyButton(); + + Composite composite = new Composite(parent, SWT.NONE); + + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + composite.setLayout(layout); + new Label(composite, SWT.NONE).setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPArguments.interpreter_args_box_title")); + new Label(composite, SWT.NONE).setText(" "); + interpreterArgumentsText = new Text(composite, SWT.BORDER); + GridData interpreterArgumentsData = new GridData(GridData.HORIZONTAL_ALIGN_FILL); + interpreterArgumentsData.horizontalSpan = 2; + interpreterArgumentsText.setLayoutData(interpreterArgumentsData); + interpreterArgumentsText.setText(getArgument("interpreter")); + + new Label(composite, SWT.NONE).setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPArguments.program_args_box_title")); + programArgumentsText = new Text(composite, SWT.BORDER); + GridData programArgumentsData = new GridData(GridData.HORIZONTAL_ALIGN_FILL); + programArgumentsData.horizontalSpan = 2; + programArgumentsText.setLayoutData(programArgumentsData); + programArgumentsText.setText(getArgument("program")); + + return composite; + } + + protected String getArgument(String name) { + String argumentValue = null; + try { + argumentValue = ((IFile)getElement()).getPersistentProperty(new QualifiedName("executionArguments", name)); + } catch(CoreException e) {} + + return argumentValue != null ? argumentValue : ""; + } + + public boolean performOk() { + IFile phpFile = (IFile)getElement(); + try { + phpFile.setPersistentProperty(new QualifiedName("executionArguments", "interpreter"), interpreterArgumentsText.getText()); + phpFile.setPersistentProperty(new QualifiedName("executionArguments", "program"), programArgumentsText.getText()); + } catch(CoreException e) { + PHPDebugUiPlugin.log(e); + return false; + } + return true; + } + +} 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 new file mode 100644 index 0000000..c4e4e3f --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/PHPSourceLocator.java @@ -0,0 +1,81 @@ +package net.sourceforge.phpdt.internal.debug.ui; + +import net.sourceforge.phpeclipse.PHPeclipsePlugin; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.CoreException; +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.IEditorInput; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.part.FileEditorInput; +import net.sourceforge.phpdt.internal.launching.PHPLaunchConfigurationAttribute; + +public class PHPSourceLocator implements IPersistableSourceLocator, ISourcePresentation { + private String absoluteWorkingDirectory; + + 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, ""); + } + + /** + * @see org.eclipse.debug.core.model.ISourceLocator#getSourceElement(IStackFrame) + */ + public Object getSourceElement(IStackFrame stackFrame) { + return null; + //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(); + } + + /** + * @see org.eclipse.debug.ui.ISourcePresentation#getEditorInput(Object) + */ + 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) { + PHPeclipsePlugin.log(IStatus.INFO, "Could not find file \"" + element + "\"."); + return null; + } + } + return new FileEditorInput(eclipseFile); + + } + +} diff --git a/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/launcher/ExecutionArguments.java b/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/launcher/ExecutionArguments.java new file mode 100644 index 0000000..108e2fb --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/launcher/ExecutionArguments.java @@ -0,0 +1,47 @@ +package net.sourceforge.phpdt.internal.debug.ui.launcher; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.QualifiedName; + +public class ExecutionArguments { + protected static final QualifiedName EXECUTION_ARGUMENTS_PROPERTY = new QualifiedName("net.sourceforge.phpdt", "executionArguments"); + protected static final String ARGUMENT_SEPARATOR = "****"; + + protected String interpreterArguments, phpFileArguments; + + public static ExecutionArguments getExecutionArguments(IFile phpScriptFile) { + try { + String executionArgumentsPersistableFormat = phpScriptFile.getPersistentProperty(EXECUTION_ARGUMENTS_PROPERTY); + ExecutionArguments executionArguments = new ExecutionArguments(); + + if (executionArgumentsPersistableFormat != null) { + int argBreakIndex = executionArgumentsPersistableFormat.indexOf(ARGUMENT_SEPARATOR); + executionArguments.setInterpreterArguments(executionArgumentsPersistableFormat.substring(0, argBreakIndex)); + executionArguments.setPHPFileArguments(executionArgumentsPersistableFormat.substring(argBreakIndex + ARGUMENT_SEPARATOR.length())); + } + + return executionArguments; + } catch (CoreException e) {} + + return null; + } + + public static void setExecutionArguments(IFile phpScriptFile, ExecutionArguments arguments) { + try { + phpScriptFile.setPersistentProperty(EXECUTION_ARGUMENTS_PROPERTY, arguments.toPersistableFormat()); + } catch (CoreException e) {} + } + + public void setInterpreterArguments(String theArguments) { + interpreterArguments = theArguments; + } + + public void setPHPFileArguments(String theArguments) { + phpFileArguments = theArguments; + } + + public String toPersistableFormat() { + return interpreterArguments + ARGUMENT_SEPARATOR + phpFileArguments; + } +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/launcher/LoadPathEntryLabelProvider.java b/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/launcher/LoadPathEntryLabelProvider.java new file mode 100644 index 0000000..6591de8 --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/launcher/LoadPathEntryLabelProvider.java @@ -0,0 +1,60 @@ +package net.sourceforge.phpdt.internal.debug.ui.launcher; + +import net.sourceforge.phpeclipse.LoadPathEntry; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.swt.graphics.Image; +import net.sourceforge.phpdt.internal.debug.ui.PHPDebugUiPlugin; + +/** + * @author xp4 + * + * To change this generated comment edit the template variable "typecomment": + * Window>Preferences>Java>Templates. + */ +public class LoadPathEntryLabelProvider implements ILabelProvider { + + /** + * @see ILabelProvider#getImage(Object) + */ + public Image getImage(Object element) { + return null; + } + + /** + * @see ILabelProvider#getText(Object) + */ + public String getText(Object element) { + if (element != null && element.getClass() == LoadPathEntry.class) + return ((LoadPathEntry) element).getProject().getLocation().toOSString(); + + PHPDebugUiPlugin.log(new RuntimeException("Unable to render load path.")); + return null; + } + + /** + * @see IBaseLabelProvider#addListener(ILabelProviderListener) + */ + public void addListener(ILabelProviderListener listener) { + } + + /** + * @see IBaseLabelProvider#dispose() + */ + public void dispose() { + } + + /** + * @see IBaseLabelProvider#isLabelProperty(Object, String) + */ + public boolean isLabelProperty(Object element, String property) { + return false; + } + + /** + * @see IBaseLabelProvider#removeListener(ILabelProviderListener) + */ + public void removeListener(ILabelProviderListener listener) { + } + +} diff --git a/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/launcher/PHPApplicationTabGroup.java b/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/launcher/PHPApplicationTabGroup.java new file mode 100644 index 0000000..21db464 --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/launcher/PHPApplicationTabGroup.java @@ -0,0 +1,28 @@ +package net.sourceforge.phpdt.internal.debug.ui.launcher; + +import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup; +import org.eclipse.debug.ui.CommonTab; +import org.eclipse.debug.ui.ILaunchConfigurationDialog; +import org.eclipse.debug.ui.ILaunchConfigurationTab; + +public class PHPApplicationTabGroup + extends AbstractLaunchConfigurationTabGroup { + + public PHPApplicationTabGroup() { + super(); + } + + /** + * @see ILaunchConfigurationTabGroup#createTabs(ILaunchConfigurationDialog, String) + */ + public void createTabs(ILaunchConfigurationDialog dialog, String mode) { + ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] { + new PHPEntryPointTab(), + new PHPArgumentsTab(), + new PHPEnvironmentTab(), + new CommonTab() + }; + setTabs(tabs); + } + +} diff --git a/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/launcher/PHPArgumentsTab.java b/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/launcher/PHPArgumentsTab.java new file mode 100644 index 0000000..e45fdb1 --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/launcher/PHPArgumentsTab.java @@ -0,0 +1,150 @@ +package net.sourceforge.phpdt.internal.debug.ui.launcher; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.debug.ui.AbstractLaunchConfigurationTab; +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.graphics.Image; +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.Label; +import org.eclipse.swt.widgets.Text; +import net.sourceforge.phpdt.debug.ui.PHPDebugUiConstants; +import net.sourceforge.phpdt.debug.ui.PHPDebugUiImages; +import net.sourceforge.phpdt.internal.debug.ui.PHPDebugUiMessages; +import net.sourceforge.phpdt.internal.debug.ui.PHPDebugUiPlugin; +import net.sourceforge.phpdt.internal.launching.PHPLaunchConfigurationAttribute; +import net.sourceforge.phpdt.internal.ui.util.DirectorySelector; + +public class PHPArgumentsTab extends AbstractLaunchConfigurationTab { + protected Text interpreterArgsText, programArgsText; + protected DirectorySelector workingDirectorySelector; + protected Button useDefaultWorkingDirectoryButton; + + public PHPArgumentsTab() { + super(); + } + + public void createControl(Composite parent) { + Composite composite = createPageRoot(parent); + + new Label(composite, SWT.NONE).setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPArguments.working_dir")); + workingDirectorySelector = new DirectorySelector(composite); + workingDirectorySelector.setBrowseDialogMessage(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPArguments.working_dir_browser_message")); + workingDirectorySelector.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + workingDirectorySelector.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + updateLaunchConfigurationDialog(); + } + }); + + Composite defaultWorkingDirectoryComposite = new Composite(composite, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + defaultWorkingDirectoryComposite.setLayout(layout); + useDefaultWorkingDirectoryButton = new Button(defaultWorkingDirectoryComposite, SWT.CHECK); + useDefaultWorkingDirectoryButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + setUseDefaultWorkingDirectory(((Button) e.getSource()).getSelection()); + } + }); + new Label(defaultWorkingDirectoryComposite, SWT.NONE).setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPArguments.working_dir_use_default_message")); + defaultWorkingDirectoryComposite.pack(); + + Label verticalSpacer = new Label(composite, SWT.NONE); + + new Label(composite, SWT.NONE).setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPArguments.interpreter_args_box_title")); + interpreterArgsText = new Text(composite, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER); + interpreterArgsText.setLayoutData(new GridData(GridData.FILL_BOTH)); + + new Label(composite, SWT.NONE).setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPArguments.program_args_box_title")); + programArgsText = new Text(composite, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER); + programArgsText.setLayoutData(new GridData(GridData.FILL_BOTH)); + } + + protected void setUseDefaultWorkingDirectory(boolean useDefault) { + if (!useDefaultWorkingDirectoryButton.getSelection() == useDefault) + useDefaultWorkingDirectoryButton.setSelection(useDefault); + if (useDefault) + workingDirectorySelector.setSelectionText(PHPDebugUiConstants.DEFAULT_WORKING_DIRECTORY); + workingDirectorySelector.setEnabled(!useDefault); + } + + public void setDefaults(ILaunchConfigurationWorkingCopy configuration) { + setUseDefaultWorkingDirectory(true); + configuration.setAttribute(PHPLaunchConfigurationAttribute.WORKING_DIRECTORY, PHPDebugUiConstants.DEFAULT_WORKING_DIRECTORY); + // set hidden attribute + //configuration.setAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_ID, "net.sourceforge.phpdt.internal.debug.ui.PHPSourceLocator") ; + } + + public void initializeFrom(ILaunchConfiguration configuration) { + String workingDirectory = "", interpreterArgs = "", programArgs = ""; + boolean useDefaultWorkDir = true; + try { + workingDirectory = configuration.getAttribute(PHPLaunchConfigurationAttribute.WORKING_DIRECTORY, ""); + interpreterArgs = configuration.getAttribute(PHPLaunchConfigurationAttribute.INTERPRETER_ARGUMENTS, ""); + programArgs = configuration.getAttribute(PHPLaunchConfigurationAttribute.PROGRAM_ARGUMENTS, ""); + useDefaultWorkDir = configuration.getAttribute(PHPLaunchConfigurationAttribute.USE_DEFAULT_WORKING_DIRECTORY, true); + } catch (CoreException e) { + log(e); + } + + workingDirectorySelector.setSelectionText(workingDirectory); + interpreterArgsText.setText(interpreterArgs); + programArgsText.setText(programArgs); + setUseDefaultWorkingDirectory(useDefaultWorkDir); + } + + public void performApply(ILaunchConfigurationWorkingCopy configuration) { + configuration.setAttribute(PHPLaunchConfigurationAttribute.WORKING_DIRECTORY, workingDirectorySelector.getValidatedSelectionText()); + configuration.setAttribute(PHPLaunchConfigurationAttribute.INTERPRETER_ARGUMENTS, interpreterArgsText.getText()); + configuration.setAttribute(PHPLaunchConfigurationAttribute.PROGRAM_ARGUMENTS, programArgsText.getText()); + configuration.setAttribute(PHPLaunchConfigurationAttribute.USE_DEFAULT_WORKING_DIRECTORY, useDefaultWorkingDirectoryButton.getSelection()); + } + + protected Composite createPageRoot(Composite parent) { + Composite composite = new Composite(parent, SWT.NONE); + GridLayout compositeLayout = new GridLayout(); + compositeLayout.marginWidth = 0; + compositeLayout.numColumns = 1; + composite.setLayout(compositeLayout); + + setControl(composite); + return composite; + } + + public String getName() { + return PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPArguments.name"); + } + + public boolean isValid(ILaunchConfiguration launchConfig) { + try { + String workingDirectory = launchConfig.getAttribute(PHPLaunchConfigurationAttribute.WORKING_DIRECTORY, ""); + if (workingDirectory.length() == 0) { + setErrorMessage(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPArguments.working_dir_error_message")); + return false; + } + } catch (CoreException e) { + log(e); + } + + setErrorMessage(null); + return true; + } + + protected void log(Throwable t) { + PHPDebugUiPlugin.getDefault().log(t); + } + + public Image getImage() { + return PHPDebugUiImages.get(PHPDebugUiImages.IMG_EVIEW_ARGUMENTS_TAB); + } + +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/launcher/PHPEntryPointTab.java b/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/launcher/PHPEntryPointTab.java new file mode 100644 index 0000000..4f3ebf7 --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/launcher/PHPEntryPointTab.java @@ -0,0 +1,159 @@ +package net.sourceforge.phpdt.internal.debug.ui.launcher; + +import net.sourceforge.phpdt.internal.ui.PHPUiImages; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.Path; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.debug.ui.AbstractLaunchConfigurationTab; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IWorkbenchPage; +import net.sourceforge.phpdt.internal.debug.ui.PHPDebugUiMessages; +import net.sourceforge.phpdt.internal.debug.ui.PHPDebugUiPlugin; +import net.sourceforge.phpdt.internal.launching.PHPLaunchConfigurationAttribute; +import net.sourceforge.phpdt.internal.ui.util.PHPFileSelector; +import net.sourceforge.phpdt.internal.ui.util.PHPProjectSelector; + +public class PHPEntryPointTab extends AbstractLaunchConfigurationTab { + protected String originalFileName, originalProjectName; + protected PHPProjectSelector projectSelector; + protected PHPFileSelector fileSelector; + + public PHPEntryPointTab() { + super(); + } + + public void createControl(Composite parent) { + Composite composite = createPageRoot(parent); + + new Label(composite, SWT.NONE).setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEntryPoint.projectLabel")); + projectSelector = new PHPProjectSelector(composite); + projectSelector.setBrowseDialogMessage(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEntryPoint.projectSelectorMessage")); + projectSelector.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + projectSelector.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent evt) { + updateLaunchConfigurationDialog(); + } + }); + + new Label(composite, SWT.NONE).setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEntryPoint.fileLabel")); + fileSelector = new PHPFileSelector(composite, projectSelector); + fileSelector.setBrowseDialogMessage(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEntryPoint.fileSelectorMessage")); + fileSelector.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + fileSelector.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent evt) { + updateLaunchConfigurationDialog(); + } + }); + } + + protected IProject getContext() { + IWorkbenchPage page = PHPDebugUiPlugin.getActivePage(); + if (page != null) { + ISelection selection = page.getSelection(); + if (selection instanceof IStructuredSelection) { + IStructuredSelection ss = (IStructuredSelection) selection; + if (!ss.isEmpty()) { + Object obj = ss.getFirstElement(); + if (obj instanceof IResource) + return ((IResource) obj).getProject(); + } + } + IEditorPart part = page.getActiveEditor(); + if (part != null) { + IEditorInput input = part.getEditorInput(); + IResource file = (IResource) input.getAdapter(IResource.class); + return file.getProject(); + } + } + return null; + } + + public void setDefaults(ILaunchConfigurationWorkingCopy configuration) { + IProject project = getContext(); + if (project != null) + configuration.setAttribute(PHPLaunchConfigurationAttribute.PROJECT_NAME, project.getName()); + } + + public void initializeFrom(ILaunchConfiguration configuration) { + try { + originalProjectName = configuration.getAttribute(PHPLaunchConfigurationAttribute.PROJECT_NAME, ""); + originalFileName = configuration.getAttribute(PHPLaunchConfigurationAttribute.FILE_NAME, ""); + } catch (CoreException e) { + log(e); + } + + projectSelector.setSelectionText(originalProjectName); + if (!"".equals(originalFileName)) + fileSelector.setSelectionText(new Path(originalFileName).toOSString()); + } + + public void performApply(ILaunchConfigurationWorkingCopy configuration) { + configuration.setAttribute(PHPLaunchConfigurationAttribute.PROJECT_NAME, projectSelector.getSelectionText()); + IFile file = fileSelector.getSelection(); + configuration.setAttribute(PHPLaunchConfigurationAttribute.FILE_NAME, file == null ? "" : file.getProjectRelativePath().toString()); + } + + protected Composite createPageRoot(Composite parent) { + Composite composite = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.marginWidth = 0; + composite.setLayout(layout); + + setControl(composite); + return composite; + } + + public String getName() { + return PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEntryPoint.name"); + } + + public boolean isValid(ILaunchConfiguration launchConfig) { + try { + + String projectName = launchConfig.getAttribute(PHPLaunchConfigurationAttribute.PROJECT_NAME, ""); + if (projectName.length() == 0) { + setErrorMessage(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEntryPoint.invalidProjectSelectionMessage")); + return false; + } + + String fileName = launchConfig.getAttribute(PHPLaunchConfigurationAttribute.FILE_NAME, ""); + if (fileName.length() == 0) { + setErrorMessage(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEntryPoint.invalidFileSelectionMessage")); + return false; + } + } catch (CoreException e) { + log(e); + } + + setErrorMessage(null); + return true; + } + + protected void log(Throwable t) { + PHPDebugUiPlugin.getDefault().log(t); + } + + public boolean canSave() { + return getErrorMessage() == null; + } + + public Image getImage() { + return PHPUiImages.get(PHPUiImages.IMG_CTOOLS_PHP_PAGE); + } + +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/launcher/PHPEnvironmentTab.java b/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/launcher/PHPEnvironmentTab.java new file mode 100644 index 0000000..13c8630 --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/launcher/PHPEnvironmentTab.java @@ -0,0 +1,266 @@ +package net.sourceforge.phpdt.internal.debug.ui.launcher; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +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.launching.PHPInterpreter; +import net.sourceforge.phpdt.internal.launching.PHPLaunchConfigurationAttribute; +import net.sourceforge.phpdt.internal.launching.PHPRuntime; +import net.sourceforge.phpdt.internal.ui.PHPUiImages; +import net.sourceforge.phpeclipse.LoadPathEntry; +import net.sourceforge.phpeclipse.PHPCore; +import net.sourceforge.phpeclipse.resourcesview.PHPProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.debug.ui.AbstractLaunchConfigurationTab; +import org.eclipse.jface.viewers.ListViewer; +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.events.SelectionListener; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.TabFolder; +import org.eclipse.swt.widgets.TabItem; +import org.eclipse.ui.internal.dialogs.ListContentProvider; + +public class PHPEnvironmentTab extends AbstractLaunchConfigurationTab { + protected ListViewer loadPathListViewer; + protected java.util.List installedInterpretersWorkingCopy; + protected Combo interpreterCombo; + protected Button loadPathDefaultButton; + + public PHPEnvironmentTab() { + super(); + } + + public void createControl(Composite parent) { + Composite composite = createPageRoot(parent); + + TabFolder tabFolder = new TabFolder(composite, SWT.NONE); + GridData gridData = new GridData(GridData.FILL_BOTH); + tabFolder.setLayoutData(gridData); + + addLoadPathTab(tabFolder); + addInterpreterTab(tabFolder); + } + + protected void addLoadPathTab(TabFolder tabFolder) { + Composite loadPathComposite = new Composite(tabFolder, SWT.NONE); + loadPathComposite.setLayout(new GridLayout()); + + loadPathListViewer = new ListViewer(loadPathComposite, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL); + loadPathListViewer.setContentProvider(new ListContentProvider()); + loadPathListViewer.setLabelProvider(new LoadPathEntryLabelProvider()); + loadPathListViewer.getList().setLayoutData(new GridData(GridData.FILL_BOTH)); + + TabItem loadPathTab = new TabItem(tabFolder, SWT.NONE, 0); + loadPathTab.setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment.loadPathTab.label")); + loadPathTab.setControl(loadPathComposite); + loadPathTab.setData(loadPathListViewer); + + loadPathDefaultButton = new Button(loadPathComposite, SWT.CHECK); + loadPathDefaultButton.setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment.loadPathDefaultButton.label")); + loadPathDefaultButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING)); + loadPathDefaultButton.addSelectionListener(getLoadPathDefaultButtonSelectionListener()); + + loadPathDefaultButton.setEnabled(false); //for now, until the load path is customizable on the configuration + } + + protected SelectionListener getLoadPathSelectionListener() { + return new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + System.out.println("Loadpath list selection occurred: " + e.getSource()); + } + }; + } + + protected SelectionListener getLoadPathDefaultButtonSelectionListener() { + return new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + setUseLoadPathDefaults(((Button) e.getSource()).getSelection()); + } + }; + } + + protected void addInterpreterTab(TabFolder tabFolder) { + Composite interpreterComposite = new Composite(tabFolder, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + layout.marginHeight = 0; + layout.marginWidth = 0; + interpreterComposite.setLayout(layout); + interpreterComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + createVerticalSpacer(interpreterComposite, 2); + + interpreterCombo = new Combo(interpreterComposite, SWT.READ_ONLY); + interpreterCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + initializeInterpreterCombo(interpreterCombo); + interpreterCombo.addModifyListener(getInterpreterComboModifyListener()); + + Button interpreterAddButton = new Button(interpreterComposite, SWT.PUSH); + 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()) { + PHPRuntime.getDefault().addInstalledInterpreter(newInterpreter); + interpreterCombo.add(newInterpreter.getName()); + interpreterCombo.select(interpreterCombo.indexOf(newInterpreter.getName())); + } + } + }); + + TabItem interpreterTab = new TabItem(tabFolder, SWT.NONE); + interpreterTab.setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment.interpreterTab.label")); + interpreterTab.setControl(interpreterComposite); + } + + protected ModifyListener getInterpreterComboModifyListener() { + return new ModifyListener() { + public void modifyText(ModifyEvent evt) { + updateLaunchConfigurationDialog(); + } + }; + } + + protected void createVerticalSpacer(Composite comp, int colSpan) { + Label label = new Label(comp, SWT.NONE); + GridData gd = new GridData(); + gd.horizontalSpan = colSpan; + label.setLayoutData(gd); + } + + public void setDefaults(ILaunchConfigurationWorkingCopy configuration) { + } + + public void initializeFrom(ILaunchConfiguration configuration) { + initializeLoadPath(configuration); + initializeInterpreterSelection(configuration); + } + + protected void initializeLoadPath(ILaunchConfiguration configuration) { + boolean useDefaultLoadPath = true; + try { + useDefaultLoadPath = configuration.getAttribute(PHPLaunchConfigurationAttribute.USE_DEFAULT_LOAD_PATH, true); + setUseLoadPathDefaults(useDefaultLoadPath); + if (useDefaultLoadPath) { + String projectName = configuration.getAttribute(PHPLaunchConfigurationAttribute.PROJECT_NAME, ""); + if (projectName != "") { + PHPProject project = PHPCore.getPHPProject(projectName); + if (project != null) { + List loadPathEntries = project.getLoadPathEntries(); + loadPathListViewer.setInput(loadPathEntries); + } + } + } + } catch (CoreException e) { + log(e); + } + } + + protected void setUseLoadPathDefaults(boolean useDefaults) { + loadPathListViewer.getList().setEnabled(!useDefaults); + loadPathDefaultButton.setSelection(useDefaults); + } + + protected void initializeInterpreterSelection(ILaunchConfiguration configuration) { + String interpreterName = null; + try { + interpreterName = configuration.getAttribute(PHPLaunchConfigurationAttribute.SELECTED_INTERPRETER, ""); + } catch (CoreException e) { + log(e); + } + if (interpreterName != null && !interpreterName.equals("")) + interpreterCombo.select(interpreterCombo.indexOf(interpreterName)); + } + + protected void initializeInterpreterCombo(Combo interpreterCombo) { + installedInterpretersWorkingCopy = new ArrayList(); + installedInterpretersWorkingCopy.addAll(PHPRuntime.getDefault().getInstalledInterpreters()); + + String[] interpreterNames = new String[installedInterpretersWorkingCopy.size()]; + for (int interpreterIndex = 0; interpreterIndex < installedInterpretersWorkingCopy.size(); interpreterIndex++) { + PHPInterpreter interpreter = (PHPInterpreter) installedInterpretersWorkingCopy.get(interpreterIndex); + interpreterNames[interpreterIndex] = interpreter.getName(); + } + interpreterCombo.setItems(interpreterNames); + + PHPInterpreter selectedInterpreter = PHPRuntime.getDefault().getSelectedInterpreter(); + if (selectedInterpreter != null) + interpreterCombo.select(interpreterCombo.indexOf(selectedInterpreter.getName())); + } + + public void performApply(ILaunchConfigurationWorkingCopy configuration) { + int selectionIndex = interpreterCombo.getSelectionIndex(); + if (selectionIndex >= 0) + configuration.setAttribute(PHPLaunchConfigurationAttribute.SELECTED_INTERPRETER, interpreterCombo.getItem(selectionIndex)); + + configuration.setAttribute(PHPLaunchConfigurationAttribute.USE_DEFAULT_LOAD_PATH, loadPathDefaultButton.getSelection()); + + if (!loadPathDefaultButton.getSelection()) { + List loadPathEntries = (List) loadPathListViewer.getInput(); + List loadPathStrings = new ArrayList(); + for (Iterator iterator = loadPathEntries.iterator(); iterator.hasNext();) { + LoadPathEntry entry = (LoadPathEntry) iterator.next(); + loadPathStrings.add(entry.getPath().toString()); + } + configuration.setAttribute(PHPLaunchConfigurationAttribute.CUSTOM_LOAD_PATH, loadPathStrings); + } + } + + protected Composite createPageRoot(Composite parent) { + Composite composite = new Composite(parent, SWT.NULL); + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + composite.setLayout(layout); + createVerticalSpacer(composite, 2); + setControl(composite); + + return composite; + } + + public String getName() { + return PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment.name"); + } + + public boolean isValid(ILaunchConfiguration launchConfig) { + try { + String selectedInterpreter = launchConfig.getAttribute(PHPLaunchConfigurationAttribute.SELECTED_INTERPRETER, ""); + if (selectedInterpreter.length() == 0) { + setErrorMessage(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment.interpreter_not_selected_error_message")); + return false; + } + } catch (CoreException e) { + log(e); + } + + setErrorMessage(null); + return true; + } + + protected void log(Throwable t) { + PHPDebugUiPlugin.getDefault().log(t); + } + + public Image getImage() { + return PHPUiImages.get(PHPUiImages.IMG_CTOOLS_PHP); + } + +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/launcher/PHPLaunchShortcut.java b/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/launcher/PHPLaunchShortcut.java new file mode 100644 index 0000000..c33a7d0 --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/launcher/PHPLaunchShortcut.java @@ -0,0 +1,116 @@ +package net.sourceforge.phpdt.internal.debug.ui.launcher; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.Status; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationType; +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.debug.core.ILaunchManager; +import org.eclipse.debug.ui.ILaunchShortcut; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IEditorPart; +import net.sourceforge.phpdt.debug.ui.PHPDebugUiConstants; +import net.sourceforge.phpdt.internal.debug.ui.PHPDebugUiMessages; +import net.sourceforge.phpdt.internal.debug.ui.PHPDebugUiPlugin; +import net.sourceforge.phpdt.internal.launching.PHPLaunchConfigurationAttribute; + +public class PHPLaunchShortcut implements ILaunchShortcut { + public PHPLaunchShortcut() { + } + + public void launch(ISelection selection, String mode) { + if (selection instanceof IStructuredSelection) { + Object firstSelection = ((IStructuredSelection)selection).getFirstElement(); + if (firstSelection instanceof IFile) { + if ( + ((IFile) firstSelection).getFileExtension().equals("php") || + ((IFile) firstSelection).getFileExtension().equals("php3") || + ((IFile) firstSelection).getFileExtension().equals("php4") + ) { + ILaunchConfiguration config = findLaunchConfiguration((IFile)firstSelection, mode); + try { + if (config != null) + config.launch(mode, null); + } catch (CoreException e) { + log(e); + } + return; + } + } + } + + log("The resource selected is not a PHP file."); + } + + public void launch(IEditorPart editor, String mode) { + IEditorInput input = editor.getEditorInput(); + ISelection selection = new StructuredSelection(input.getAdapter(IFile.class)); + launch(selection, mode); + } + + protected ILaunchConfiguration findLaunchConfiguration(IFile phpFile, String mode) { + ILaunchConfigurationType configType = getPHPLaunchConfigType(); + List candidateConfigs = null; + try { + ILaunchConfiguration[] configs = getLaunchManager().getLaunchConfigurations(configType); + candidateConfigs = new ArrayList(configs.length); + for (int i = 0; i < configs.length; i++) { + ILaunchConfiguration config = configs[i]; + if (config.getAttribute(PHPLaunchConfigurationAttribute.FILE_NAME, "").equals(phpFile.getFullPath().toString())) { + candidateConfigs.add(config); + } + } + } catch (CoreException e) { + log(e); + } + + switch (candidateConfigs.size()) { + case 0 : + return createConfiguration(phpFile); + case 1 : + return (ILaunchConfiguration) candidateConfigs.get(0); + default : + log(new RuntimeException(PHPDebugUiMessages.getString("LaunchConfigurationShortcut.PHP.multipleConfigurationsError"))); + return null; + } + } + + protected ILaunchConfiguration createConfiguration(IFile phpFile) { + ILaunchConfiguration config = null; + try { + ILaunchConfigurationType configType = getPHPLaunchConfigType(); + ILaunchConfigurationWorkingCopy wc = configType.newInstance(null, getLaunchManager().generateUniqueLaunchConfigurationNameFrom(phpFile.getName())); + wc.setAttribute(PHPLaunchConfigurationAttribute.PROJECT_NAME, phpFile.getProject().getName()); + wc.setAttribute(PHPLaunchConfigurationAttribute.FILE_NAME, phpFile.getProjectRelativePath().toString()); + wc.setAttribute(PHPLaunchConfigurationAttribute.WORKING_DIRECTORY, PHPDebugUiConstants.DEFAULT_WORKING_DIRECTORY); + config = wc.doSave(); + } catch (CoreException ce) { + log(ce); + } + return config; + } + + protected ILaunchConfigurationType getPHPLaunchConfigType() { + return getLaunchManager().getLaunchConfigurationType(PHPLaunchConfigurationAttribute.PHP_LAUNCH_CONFIGURATION_TYPE); + } + + protected ILaunchManager getLaunchManager() { + return DebugPlugin.getDefault().getLaunchManager(); + } + + protected void log(String message) { + PHPDebugUiPlugin.getDefault().log(new Status(Status.INFO, PHPDebugUiPlugin.PLUGIN_ID, Status.INFO, message, null)); + } + + protected void log(Throwable t) { + PHPDebugUiPlugin.getDefault().log(t); + } +} 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 new file mode 100644 index 0000000..c0f6d45 --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/preferences/EditInterpreterDialog.java @@ -0,0 +1,166 @@ +package net.sourceforge.phpdt.internal.debug.ui.preferences; + +import java.io.File; + +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; +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.dialog.StatusDialog; + +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 diff --git a/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/preferences/PHPBasePreferencePage.java b/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/preferences/PHPBasePreferencePage.java new file mode 100644 index 0000000..9126e66 --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/preferences/PHPBasePreferencePage.java @@ -0,0 +1,34 @@ +package net.sourceforge.phpdt.internal.debug.ui.preferences; + +import org.eclipse.jface.preference.PreferencePage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; +import net.sourceforge.phpdt.internal.debug.ui.PHPDebugUiMessages; + +public class PHPBasePreferencePage extends PreferencePage implements IWorkbenchPreferencePage { + + public PHPBasePreferencePage() { + super(); + } + + public void init(IWorkbench workbench) {} + + protected Control createContents(Composite parent) { + noDefaultAndApplyButton(); + + Composite composite = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.marginHeight = 0; + layout.marginWidth = 0; + composite.setLayout(layout); + + new Label(composite, SWT.NONE).setText(PHPDebugUiMessages.getString("PHPBasePreferencePage.label")); //$NON-NLS-1$ + + return composite; + } +} diff --git a/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/preferences/PHPInterpreterContentProvider.java b/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/preferences/PHPInterpreterContentProvider.java new file mode 100644 index 0000000..f5a5aef --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/preferences/PHPInterpreterContentProvider.java @@ -0,0 +1,25 @@ +package net.sourceforge.phpdt.internal.debug.ui.preferences; + +import java.util.List; + +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.Viewer; +import net.sourceforge.phpdt.internal.launching.PHPInterpreter; + +public class PHPInterpreterContentProvider implements IStructuredContentProvider { + protected List interpreters; + + public PHPInterpreterContentProvider() { + super(); + } + + public Object[] getElements(Object inputElement) { + return interpreters.toArray(); + } + + public void dispose() {} + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + interpreters = (List) newInput; + } +} diff --git a/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/preferences/PHPInterpreterLabelProvider.java b/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/preferences/PHPInterpreterLabelProvider.java new file mode 100644 index 0000000..e94f498 --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/preferences/PHPInterpreterLabelProvider.java @@ -0,0 +1,42 @@ +package net.sourceforge.phpdt.internal.debug.ui.preferences; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.swt.graphics.Image; +import net.sourceforge.phpdt.internal.launching.PHPInterpreter; + +public class PHPInterpreterLabelProvider implements ITableLabelProvider { + + public PHPInterpreterLabelProvider() { + super(); + } + + public Image getColumnImage(Object element, int columnIndex) { + return null; + } + + public String getColumnText(Object element, int columnIndex) { + 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"; + default : + return "Unknown Column Index"; + } + } + + public void addListener(ILabelProviderListener listener) {} + + public void dispose() {} + + public boolean isLabelProperty(Object element, String property) { + return false; + } + + public void removeListener(ILabelProviderListener listener) {} + +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/preferences/PHPInterpreterPreferencePage.java b/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/preferences/PHPInterpreterPreferencePage.java new file mode 100644 index 0000000..3997682 --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/preferences/PHPInterpreterPreferencePage.java @@ -0,0 +1,211 @@ +package net.sourceforge.phpdt.internal.debug.ui.preferences; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.jface.preference.PreferencePage; +import org.eclipse.jface.viewers.CheckStateChangedEvent; +import org.eclipse.jface.viewers.CheckboxTableViewer; +import org.eclipse.jface.viewers.DoubleClickEvent; +import org.eclipse.jface.viewers.ICheckStateListener; +import org.eclipse.jface.viewers.IDoubleClickListener; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.swt.SWT; +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.Event; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; +import net.sourceforge.phpdt.internal.debug.ui.PHPDebugUiMessages; +import net.sourceforge.phpdt.internal.launching.PHPInterpreter; +import net.sourceforge.phpdt.internal.launching.PHPRuntime; + +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(); + } + +} \ No newline at end of file