From a160a0a753aaa61e6f185cc13addaf7a18729a4d Mon Sep 17 00:00:00 2001 From: axelcl Date: Sat, 11 Jun 2005 17:15:02 +0000 Subject: [PATCH] All prefs administrated in external tools plugin. --- .../externaltools/actions/ExternalPHPParser.java | 318 ++++++++++++++++++++ .../actions/PHPExternalParserAction.java | 89 ++++++ .../actions/PHPRestartApacheAction.java | 30 ++ .../actions/PHPStartApacheAction.java | 74 +++++ .../externaltools/actions/PHPStartMySQLAction.java | 29 ++ .../externaltools/actions/PHPStartXAMPPAction.java | 73 +++++ .../externaltools/actions/PHPStopApacheAction.java | 29 ++ .../externaltools/actions/PHPStopXAMPPAction.java | 73 +++++ .../PHPExternalToolsPreferencePage.java | 247 +++++++++++++++ .../preferences/PHPPreferencesMessages.java | 39 +++ .../preferences/PHPPreferencesMessages.properties | 91 ++++++ .../phpdt/externaltools/util/StringUtil.java | 34 ++ .../externaltools/ExternalToolsPlugin.java | 76 ++++- .../phpeclipse/externaltools/PHPConsole.java | 107 +++++++ 14 files changed, 1296 insertions(+), 13 deletions(-) create mode 100644 net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/actions/ExternalPHPParser.java create mode 100644 net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/actions/PHPExternalParserAction.java create mode 100644 net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/actions/PHPRestartApacheAction.java create mode 100644 net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/actions/PHPStartApacheAction.java create mode 100644 net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/actions/PHPStartMySQLAction.java create mode 100644 net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/actions/PHPStartXAMPPAction.java create mode 100644 net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/actions/PHPStopApacheAction.java create mode 100644 net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/actions/PHPStopXAMPPAction.java create mode 100644 net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/preferences/PHPExternalToolsPreferencePage.java create mode 100644 net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/preferences/PHPPreferencesMessages.java create mode 100644 net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/preferences/PHPPreferencesMessages.properties create mode 100644 net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/util/StringUtil.java create mode 100644 net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpeclipse/externaltools/PHPConsole.java diff --git a/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/actions/ExternalPHPParser.java b/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/actions/ExternalPHPParser.java new file mode 100644 index 0000000..9169c71 --- /dev/null +++ b/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/actions/ExternalPHPParser.java @@ -0,0 +1,318 @@ +package net.sourceforge.phpdt.externaltools.actions; + +import java.io.IOException; +import java.io.InputStream; +import java.text.MessageFormat; +import java.util.Hashtable; + +import net.sourceforge.phpdt.externaltools.util.StringUtil; +import net.sourceforge.phpeclipse.externaltools.ExternalToolsPlugin; +import net.sourceforge.phpeclipse.externaltools.PHPConsole; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.ui.texteditor.MarkerUtilities; + +/** + * Calls the external parser and generates problem markers if necessary + */ +public class ExternalPHPParser { + private final static String PROBLEM_ID = "net.sourceforge.phpeclipse.problem"; + + // strings for external parser call + private static final String PARSE_ERROR_STRING = "Parse error"; //$NON-NLS-1$ + + private static final String PARSE_WARNING_STRING = "Warning"; //$NON-NLS-1$ + + public static final int ERROR = 2; + + public static final int WARNING = 1; + + public static final int INFO = 0; + + public static final int TASK = 3; + + // TODO design error? Analyze why fileToParse must be static ??? + final protected IFile fFileToParse; + + public ExternalPHPParser(IFile file) { + fFileToParse = file; + } + + /** + * Call the php parse command ( php -l -f <filename> ) and create markers according to the external parser output. + * + * @param file + * the file that will be parsed + */ + public void phpExternalParse() { + //IFile file = (IFile) resource; + // final IPath path = file.getFullPath(); + final IPreferenceStore store = ExternalToolsPlugin.getDefault().getPreferenceStore(); + final String filename = fFileToParse.getLocation().toString(); + + final String[] arguments = { filename }; + final MessageFormat form = new MessageFormat(store.getString(ExternalToolsPlugin.EXTERNAL_PARSER_PREF)); + final String command = form.format(arguments); + + final String parserResult = getParserOutput(command, "External parser: "); + + try { + // parse the buffer to find the errors and warnings + createMarkers(parserResult, fFileToParse); + } catch (CoreException e) { + } + } + + /** + * Create markers according to the external parser output. + * + * @param output + * the external parser output + * @param file + * the file that was parsed. + */ + protected void createMarkers(final String output, final IFile file) throws CoreException { + // delete all markers + file.deleteMarkers(PROBLEM_ID, false, 0); + + int indx = 0; + int brIndx; + boolean flag = true; + while ((brIndx = output.indexOf("
", indx)) != -1) { + // newer php error output (tested with 4.2.3) + scanLine(output, file, indx, brIndx); + indx = brIndx + 6; + flag = false; + } + if (flag) { + while ((brIndx = output.indexOf("
", indx)) != -1) { + // older php error output (tested with 4.2.3) + scanLine(output, file, indx, brIndx); + indx = brIndx + 4; + } + } + } + + private void scanLine(final String output, final IFile file, final int indx, final int brIndx) throws CoreException { + String current; + // String outLineNumberString; never used + final StringBuffer lineNumberBuffer = new StringBuffer(10); + char ch; + current = output.substring(indx, brIndx); + + if (current.indexOf(PARSE_WARNING_STRING) != -1 || current.indexOf(PARSE_ERROR_STRING) != -1) { + final int onLine = current.indexOf("on line "); + if (onLine != -1) { + lineNumberBuffer.delete(0, lineNumberBuffer.length()); + for (int i = onLine; i < current.length(); i++) { + ch = current.charAt(i); + if ('0' <= ch && '9' >= ch) { + lineNumberBuffer.append(ch); + } + } + + final int lineNumber = Integer.parseInt(lineNumberBuffer.toString()); + + final Hashtable attributes = new Hashtable(); + + current = StringUtil.replaceAll(current, "\n", ""); + current = StringUtil.replaceAll(current, "", ""); + current = StringUtil.replaceAll(current, "", ""); + MarkerUtilities.setMessage(attributes, current); + + if (current.indexOf(PARSE_ERROR_STRING) != -1) + attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR)); + else if (current.indexOf(PARSE_WARNING_STRING) != -1) + attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING)); + else + attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO)); + MarkerUtilities.setLineNumber(attributes, lineNumber); + MarkerUtilities.createMarker(file, attributes, PROBLEM_ID); + } + } + } + + /** + * This will set a marker. + * + * @param file + * the file that generated the marker + * @param message + * the message + * @param charStart + * the starting character + * @param charEnd + * the end character + * @param errorLevel + * the error level ({@link ExternalPHPParser#ERROR},{@link ExternalPHPParser#INFO},{@link ExternalPHPParser#WARNING}), + * {@link ExternalPHPParser#TASK}) + * @throws CoreException + * an exception throwed by the MarkerUtilities + */ + private void setMarker(final IFile file, final String message, final int charStart, final int charEnd, final int errorLevel) + throws CoreException { + if (file != null) { + final Hashtable attributes = new Hashtable(); + MarkerUtilities.setMessage(attributes, message); + switch (errorLevel) { + case ERROR: + attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR)); + break; + case WARNING: + attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING)); + break; + case INFO: + attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO)); + break; + case TASK: + attributes.put(IMarker.SEVERITY, new Integer(IMarker.TASK)); + break; + } + MarkerUtilities.setCharStart(attributes, charStart); + MarkerUtilities.setCharEnd(attributes, charEnd); + MarkerUtilities.createMarker(file, attributes, PROBLEM_ID); + } + } + + /** + * This will set a marker. + * + * @param file + * the file that generated the marker + * @param message + * the message + * @param line + * the line number + * @param errorLevel + * the error level ({@link ExternalPHPParser#ERROR},{@link ExternalPHPParser#INFO},{@link ExternalPHPParser#WARNING}) + * @throws CoreException + * an exception throwed by the MarkerUtilities + */ + private void setMarker(final IFile file, final String message, final int line, final int errorLevel, final String location) + throws CoreException { + if (file != null) { + String markerKind = PROBLEM_ID; + final Hashtable attributes = new Hashtable(); + MarkerUtilities.setMessage(attributes, message); + switch (errorLevel) { + case ERROR: + attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR)); + break; + case WARNING: + attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING)); + break; + case INFO: + attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO)); + break; + case TASK: + attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO)); + markerKind = IMarker.TASK; + break; + } + attributes.put(IMarker.LOCATION, location); + MarkerUtilities.setLineNumber(attributes, line); + MarkerUtilities.createMarker(file, attributes, markerKind); + } + } + + /** + * This will set a marker. + * + * @param message + * the message + * @param charStart + * the starting character + * @param charEnd + * the end character + * @param errorLevel + * the error level ({@link ExternalPHPParser#ERROR},{@link ExternalPHPParser#INFO},{@link ExternalPHPParser#WARNING}) + * @throws CoreException + * an exception throwed by the MarkerUtilities + */ + private void setMarker(final String message, final int charStart, final int charEnd, final int errorLevel, final String location) + throws CoreException { + if (fFileToParse != null) { + setMarker(fFileToParse, message, charStart, charEnd, errorLevel, location); + } + } + + /** + * This will set a marker. + * + * @param file + * the file that generated the marker + * @param message + * the message + * @param charStart + * the starting character + * @param charEnd + * the end character + * @param errorLevel + * the error level ({@link ExternalPHPParser#ERROR},{@link ExternalPHPParser#INFO},{@link ExternalPHPParser#WARNING}) + * @param location + * the location of the error + * @throws CoreException + * an exception throwed by the MarkerUtilities + */ + private void setMarker(final IFile file, final String message, final int charStart, final int charEnd, final int errorLevel, + final String location) throws CoreException { + if (file != null) { + final Hashtable attributes = new Hashtable(); + MarkerUtilities.setMessage(attributes, message); + switch (errorLevel) { + case ERROR: + attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR)); + break; + case WARNING: + attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING)); + break; + case INFO: + attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO)); + break; + case TASK: + attributes.put(IMarker.SEVERITY, new Integer(IMarker.TASK)); + break; + } + attributes.put(IMarker.LOCATION, location); + MarkerUtilities.setCharStart(attributes, charStart); + MarkerUtilities.setCharEnd(attributes, charEnd); + MarkerUtilities.createMarker(file, attributes, PROBLEM_ID); //IMarker.PROBLEM); + } + } + + private String getParserOutput(String command, String consoleMessage) { + try { + PHPConsole console = new PHPConsole(); + try { + console.println(consoleMessage + command); + } catch (Throwable th) { + + } + + Runtime runtime = Runtime.getRuntime(); + + // runs the command + Process p = runtime.exec(command); + + // gets the input stream to have the post-compile-time information + InputStream stream = p.getInputStream(); + + // get the string from Stream + String consoleOutput = PHPConsole.getStringFromStream(stream); + + // prints out the information + if (console != null) { + console.print(consoleOutput); + } + return consoleOutput; + + } catch (IOException e) { + MessageDialog.openInformation(null, "IOException: ", e.getMessage()); + } + return ""; + } +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/actions/PHPExternalParserAction.java b/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/actions/PHPExternalParserAction.java new file mode 100644 index 0000000..58a5a2e --- /dev/null +++ b/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/actions/PHPExternalParserAction.java @@ -0,0 +1,89 @@ +/********************************************************************** +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 + www.phpeclipse.de +**********************************************************************/ +package net.sourceforge.phpdt.externaltools.actions; + +import java.util.Iterator; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IResource; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.ui.IActionDelegate; +import org.eclipse.ui.IObjectActionDelegate; +import org.eclipse.ui.IWorkbenchPart; + + +public class PHPExternalParserAction implements IObjectActionDelegate { + + private IWorkbenchPart workbenchPart; + /** + * Constructor for Action1. + */ + public PHPExternalParserAction() { + super(); + } + + /** + * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart) + */ + public void setActivePart(IAction action, IWorkbenchPart targetPart) { + workbenchPart = targetPart; + } + + // public static void open(final URL url, final Shell shell, final String dialogTitle) { + // IHelp help= WorkbenchHelp.getHelpSupport(); + // if (help != null) { + // WorkbenchHelp.getHelpSupport().displayHelpResource(url.toExternalForm()); + // } else { + // showMessage(shell, dialogTitle, ActionMessages.getString("OpenBrowserUtil.help_not_available"), false); //$NON-NLS-1$ + // } + // } + + public void run(IAction action) { + ISelectionProvider selectionProvider = null; + selectionProvider = workbenchPart.getSite().getSelectionProvider(); + + StructuredSelection selection = null; + selection = (StructuredSelection) selectionProvider.getSelection(); + + //Shell shell = null; + Iterator iterator = null; + iterator = selection.iterator(); + while (iterator.hasNext()) { + // obj => selected object in the view + Object obj = iterator.next(); + + // is it a resource + if (obj instanceof IResource) { + IResource resource = (IResource) obj; + + // check if it's a file resource + switch (resource.getType()) { + + case IResource.FILE : + // single file: + ExternalPHPParser parser = new ExternalPHPParser((IFile)resource); + parser.phpExternalParse(); + } + } + } + } + + /** + * @see IActionDelegate#selectionChanged(IAction, ISelection) + */ + public void selectionChanged(IAction action, ISelection selection) { + } + +} diff --git a/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/actions/PHPRestartApacheAction.java b/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/actions/PHPRestartApacheAction.java new file mode 100644 index 0000000..0a13cfa --- /dev/null +++ b/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/actions/PHPRestartApacheAction.java @@ -0,0 +1,30 @@ +/********************************************************************** +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 + www.phpeclipse.de +**********************************************************************/ +package net.sourceforge.phpdt.externaltools.actions; + + +import net.sourceforge.phpeclipse.externaltools.ExternalToolsPlugin; + +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.preference.IPreferenceStore; + +public class PHPRestartApacheAction extends PHPStartApacheAction { + public void run(IAction action) { + final IPreferenceStore store = ExternalToolsPlugin.getDefault().getPreferenceStore(); + // execute(store.getString(PHPeclipsePlugin.APACHE_RESTART_PREF), "Restart Apache: "); + execute( + "apache_restart", + store.getString(ExternalToolsPlugin.APACHE_RUN_PREF), + store.getString(ExternalToolsPlugin.APACHE_RESTART_PREF), + store.getBoolean(ExternalToolsPlugin.APACHE_RESTART_BACKGROUND)); + } +} diff --git a/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/actions/PHPStartApacheAction.java b/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/actions/PHPStartApacheAction.java new file mode 100644 index 0000000..da819c2 --- /dev/null +++ b/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/actions/PHPStartApacheAction.java @@ -0,0 +1,74 @@ +/*********************************************************************************************************************************** + * 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 www.phpeclipse.de + **********************************************************************************************************************************/ +package net.sourceforge.phpdt.externaltools.actions; + +import java.text.MessageFormat; + +import net.sourceforge.phpdt.externaltools.launchConfigurations.ExternalToolsUtil; +import net.sourceforge.phpeclipse.externaltools.ExternalToolsPlugin; +import net.sourceforge.phpeclipse.externaltools.PHPConsole; +import net.sourceforge.phpeclipse.ui.WebUI; + +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.IWorkbenchWindowActionDelegate; + +public class PHPStartApacheAction implements IWorkbenchWindowActionDelegate { + protected IWorkbenchWindow activeWindow = null; + + public void run(IAction action) { + final IPreferenceStore store = ExternalToolsPlugin.getDefault().getPreferenceStore(); + String documentRoot = store.getString(WebUI.PHP_DOCUMENTROOT_PREF); + // replace backslash with slash in the DocumentRoot under Windows + documentRoot = documentRoot.replace('\\', '/'); + String[] arguments = { documentRoot }; + MessageFormat form = new MessageFormat(store.getString(ExternalToolsPlugin.APACHE_START_PREF)); + execute("apache_start", store.getString(ExternalToolsPlugin.APACHE_RUN_PREF), form.format(arguments), store + .getBoolean(ExternalToolsPlugin.APACHE_START_BACKGROUND)); + } + + /** + * Executes an external progam and saves the LaunchConfiguration under external tools + * + * @param command + * external tools command name + * @param executable + * executable path i.e.c:\apache\apache.exe + * @param arguments + * arguments for this configuration + * @param background + * run this configuration in background mode + */ + public static void execute(String command, String executable, String arguments, boolean background) { +// PHPConsole console = new PHPConsole(); +// String consoleMessage; +// if (background) { +// consoleMessage = "run in background mode-" + command + ": " + executable + " " + arguments; +// } else { +// consoleMessage = "run in foreground mode-" + command + ": " + executable + " " + arguments; +// } +// console.println(consoleMessage); + + ExternalToolsUtil.execute(command, executable, arguments, background); + } + + public void selectionChanged(IAction action, ISelection selection) { + + } + + public void init(IWorkbenchWindow window) { + this.activeWindow = window; + } + + public void dispose() { + + } + +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/actions/PHPStartMySQLAction.java b/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/actions/PHPStartMySQLAction.java new file mode 100644 index 0000000..860302a --- /dev/null +++ b/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/actions/PHPStartMySQLAction.java @@ -0,0 +1,29 @@ +/********************************************************************** +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 + www.phpeclipse.de +**********************************************************************/ +package net.sourceforge.phpdt.externaltools.actions; + +import net.sourceforge.phpeclipse.externaltools.ExternalToolsPlugin; + +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.preference.IPreferenceStore; + +public class PHPStartMySQLAction extends PHPStartApacheAction { + public void run(IAction action) { + final IPreferenceStore store = ExternalToolsPlugin.getDefault().getPreferenceStore(); + // execute(store.getString(PHPeclipsePlugin.MYSQL_PREF), "Start MySQL: "); + execute( + "mysql_start", + store.getString(ExternalToolsPlugin.MYSQL_RUN_PREF), + store.getString(ExternalToolsPlugin.MYSQL_PREF), + store.getBoolean(ExternalToolsPlugin.MYSQL_START_BACKGROUND)); + } +} diff --git a/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/actions/PHPStartXAMPPAction.java b/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/actions/PHPStartXAMPPAction.java new file mode 100644 index 0000000..d51afd3 --- /dev/null +++ b/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/actions/PHPStartXAMPPAction.java @@ -0,0 +1,73 @@ +/*********************************************************************************************************************************** + * 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 www.phpeclipse.de + **********************************************************************************************************************************/ +package net.sourceforge.phpdt.externaltools.actions; + +import java.io.File; + +import net.sourceforge.phpdt.externaltools.launchConfigurations.ExternalToolsUtil; +import net.sourceforge.phpeclipse.externaltools.ExternalToolsPlugin; +import net.sourceforge.phpeclipse.externaltools.PHPConsole; + +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.IWorkbenchWindowActionDelegate; + +public class PHPStartXAMPPAction implements IWorkbenchWindowActionDelegate { + protected IWorkbenchWindow activeWindow = null; + + public void run(IAction action) { + final IPreferenceStore store = ExternalToolsPlugin.getDefault().getPreferenceStore(); + String executable = store.getString(ExternalToolsPlugin.XAMPP_START_PREF); + String workingDirectory = null; + if (executable != null && executable.length() > 0) { + int index = executable.lastIndexOf(File.separatorChar); + if (index > 0) { + workingDirectory = executable.substring(0, index); + } + } + execute("xampp_start", executable, workingDirectory, true); + } + + /** + * Executes an external progam and saves the LaunchConfiguration under external tools + * + * @param command + * external tools command name + * @param executable + * executable path i.e.c:\apache\apache.exe + * @param background + * run this configuration in background mode + */ + public static void execute(String command, String executable, String workingDirectory, boolean background) { +// PHPConsole console = new PHPConsole(); +// String consoleMessage; +// if (background) { +// consoleMessage = "run in background mode-" + command + ": " + executable; +// } else { +// consoleMessage = "run in foreground mode-" + command + ": " + executable; +// } +// console.println(consoleMessage); + + ExternalToolsUtil.execute(command, executable, workingDirectory, null, background); + } + + public void selectionChanged(IAction action, ISelection selection) { + + } + + public void init(IWorkbenchWindow window) { + this.activeWindow = window; + } + + public void dispose() { + + } + +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/actions/PHPStopApacheAction.java b/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/actions/PHPStopApacheAction.java new file mode 100644 index 0000000..1bdf89b --- /dev/null +++ b/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/actions/PHPStopApacheAction.java @@ -0,0 +1,29 @@ +/********************************************************************** +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 + www.phpeclipse.de +**********************************************************************/ +package net.sourceforge.phpdt.externaltools.actions; + +import net.sourceforge.phpeclipse.externaltools.ExternalToolsPlugin; + +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.preference.IPreferenceStore; + +public class PHPStopApacheAction extends PHPStartApacheAction { + public void run(IAction action) { + final IPreferenceStore store = ExternalToolsPlugin.getDefault().getPreferenceStore(); + // execute(store.getString(PHPeclipsePlugin.APACHE_STOP_PREF), "Stop Apache: "); + execute( + "apache_stop", + store.getString(ExternalToolsPlugin.APACHE_RUN_PREF), + store.getString(ExternalToolsPlugin.APACHE_STOP_PREF), + store.getBoolean(ExternalToolsPlugin.APACHE_STOP_BACKGROUND)); + } +} diff --git a/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/actions/PHPStopXAMPPAction.java b/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/actions/PHPStopXAMPPAction.java new file mode 100644 index 0000000..f01e88f --- /dev/null +++ b/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/actions/PHPStopXAMPPAction.java @@ -0,0 +1,73 @@ +/*********************************************************************************************************************************** + * 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 www.phpeclipse.de + **********************************************************************************************************************************/ +package net.sourceforge.phpdt.externaltools.actions; + +import java.io.File; + +import net.sourceforge.phpdt.externaltools.launchConfigurations.ExternalToolsUtil; +import net.sourceforge.phpeclipse.externaltools.ExternalToolsPlugin; +import net.sourceforge.phpeclipse.externaltools.PHPConsole; + +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.IWorkbenchWindowActionDelegate; + +public class PHPStopXAMPPAction implements IWorkbenchWindowActionDelegate { + protected IWorkbenchWindow activeWindow = null; + + public void run(IAction action) { + final IPreferenceStore store = ExternalToolsPlugin.getDefault().getPreferenceStore(); + String executable = store.getString(ExternalToolsPlugin.XAMPP_STOP_PREF); + String workingDirectory = null; + if (executable != null && executable.length() > 0) { + int index = executable.lastIndexOf(File.separatorChar); + if (index > 0) { + workingDirectory = executable.substring(0, index); + } + } + execute("xampp_stop", executable, workingDirectory, true); + } + + /** + * Executes an external progam and saves the LaunchConfiguration under external tools + * + * @param command + * external tools command name + * @param executable + * executable path i.e.c:\apache\apache.exe + * @param background + * run this configuration in background mode + */ + public static void execute(String command, String executable, String workingDirectory, boolean background) { +// PHPConsole console = new PHPConsole(); +// String consoleMessage; +// if (background) { +// consoleMessage = "run in background mode-" + command + ": " + executable; +// } else { +// consoleMessage = "run in foreground mode-" + command + ": " + executable; +// } +// console.println(consoleMessage); + + ExternalToolsUtil.execute(command, executable, workingDirectory, null, background); + } + + public void selectionChanged(IAction action, ISelection selection) { + + } + + public void init(IWorkbenchWindow window) { + this.activeWindow = window; + } + + public void dispose() { + + } + +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/preferences/PHPExternalToolsPreferencePage.java b/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/preferences/PHPExternalToolsPreferencePage.java new file mode 100644 index 0000000..fbc578a --- /dev/null +++ b/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/preferences/PHPExternalToolsPreferencePage.java @@ -0,0 +1,247 @@ +package net.sourceforge.phpdt.externaltools.preferences; + + +import net.sourceforge.phpeclipse.externaltools.ExternalToolsPlugin; + +import org.eclipse.jface.preference.BooleanFieldEditor; +import org.eclipse.jface.preference.FileFieldEditor; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.preference.PreferencePage; +import org.eclipse.jface.preference.StringFieldEditor; +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.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; + +public class PHPExternalToolsPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { + +// StringFieldEditor phpParserExtensionsSFE; + StringFieldEditor xamppStartSFE; + StringFieldEditor xamppStopSFE; + StringFieldEditor apacheStartSFE; + + StringFieldEditor apacheStopSFE; + + StringFieldEditor apacheRestartSFE; + + StringFieldEditor mySQLCommandSFE; + + StringFieldEditor externalParserSFE; + + FileFieldEditor apacheRunFFE; + + FileFieldEditor mysqlRunFFE; + + FileFieldEditor phpRunFFE; + + BooleanFieldEditor apacheStartBFE; + + BooleanFieldEditor apacheStopBFE; + + BooleanFieldEditor apacheRestartBFE; + + BooleanFieldEditor mysqlStartBFE; + + public PHPExternalToolsPreferencePage() { + super(); + setPreferenceStore(ExternalToolsPlugin.getDefault().getPreferenceStore()); + setDescription(PHPPreferencesMessages.getString("PHPBasePreferencePage.description")); //$NON-NLS-1$ + } + + public void init(IWorkbench workbench) { + } + + protected void performDefaults() { +// phpParserExtensionsSFE.loadDefault(); + xamppStartSFE.loadDefault(); + xamppStopSFE.loadDefault(); + apacheStartSFE.loadDefault(); + apacheStopSFE.loadDefault(); + apacheRestartSFE.loadDefault(); + mySQLCommandSFE.loadDefault(); + externalParserSFE.loadDefault(); + phpRunFFE.loadDefault(); + apacheRunFFE.loadDefault(); + mysqlRunFFE.loadDefault(); + apacheStartBFE.loadDefault(); + apacheStopBFE.loadDefault(); + apacheRestartBFE.loadDefault(); + mysqlStartBFE.loadDefault(); + super.performDefaults(); + } + + public boolean performOk() { +// PHPFileUtil.setExtensions(null); +// phpParserExtensionsSFE.store(); + xamppStartSFE.store(); + xamppStopSFE.store(); + apacheStartSFE.store(); + apacheStopSFE.store(); + apacheRestartSFE.store(); + mySQLCommandSFE.store(); + externalParserSFE.store(); + phpRunFFE.store(); + apacheRunFFE.store(); + mysqlRunFFE.store(); + + apacheStartBFE.store(); + apacheStopBFE.store(); + apacheRestartBFE.store(); + mysqlStartBFE.store(); + return super.performOk(); + } + + protected Control createContents(Composite parent) { + initializeDialogUnits(parent); + final IPreferenceStore store = ExternalToolsPlugin.getDefault().getPreferenceStore(); + Composite composite = new Composite(parent, SWT.LEFT); + composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + composite.setLayout(new GridLayout()); + + // allowed PHP file extensions for parsing + Composite phpParserExtensionsComposite = new Composite(composite, SWT.NULL); + phpParserExtensionsComposite.setLayout(new GridLayout()); + phpParserExtensionsComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); +// phpParserExtensionsSFE = new StringFieldEditor(IPreferenceConstants.PHP_EXTENSION_PREFS, PHPPreferencesMessages +// .getString("PHPBasePreferencePage.phpExtensionPrefs"), phpParserExtensionsComposite); +// phpParserExtensionsSFE.setPreferencePage(this); +// phpParserExtensionsSFE.setPreferenceStore(getPreferenceStore()); +// phpParserExtensionsSFE.load(); + + //Create apache + Composite apacheSettingsComposite = new Composite(composite, SWT.NULL); + apacheSettingsComposite.setLayout(new GridLayout()); + apacheSettingsComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + Group apacheSettingsGroup = new Group(apacheSettingsComposite, SWT.NONE); + apacheSettingsGroup.setText(PHPPreferencesMessages.getString("PHPBasePreferencePage.apacheGroup")); + apacheSettingsGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + apacheSettingsGroup.setLayout(new GridLayout()); + + + xamppStartSFE = new StringFieldEditor(ExternalToolsPlugin.XAMPP_START_PREF, PHPPreferencesMessages + .getString("PHPBasePreferencePage.apacheGroup.xampp_start"), apacheSettingsGroup); + xamppStartSFE.setPreferencePage(this); + xamppStartSFE.setPreferenceStore(getPreferenceStore()); + xamppStartSFE.load(); + new Label(apacheSettingsGroup, SWT.NONE); + + xamppStopSFE = new StringFieldEditor(ExternalToolsPlugin.XAMPP_STOP_PREF, PHPPreferencesMessages + .getString("PHPBasePreferencePage.apacheGroup.xampp_stop"), apacheSettingsGroup); + xamppStopSFE.setPreferencePage(this); + xamppStopSFE.setPreferenceStore(getPreferenceStore()); + xamppStopSFE.load(); + new Label(apacheSettingsGroup, SWT.NONE); + + apacheStartBFE = new BooleanFieldEditor(ExternalToolsPlugin.APACHE_START_BACKGROUND, PHPPreferencesMessages + .getString("PHPBasePreferencePage.apacheGroup.start_background"), apacheSettingsGroup); + apacheStartBFE.setPreferencePage(this); + apacheStartBFE.setPreferenceStore(getPreferenceStore()); + apacheStartBFE.load(); + + new Label(apacheSettingsGroup, SWT.NONE); + new Label(apacheSettingsGroup, SWT.NONE); + apacheStartSFE = new StringFieldEditor(ExternalToolsPlugin.APACHE_START_PREF, PHPPreferencesMessages + .getString("PHPBasePreferencePage.apacheGroup.start"), apacheSettingsGroup); + apacheStartSFE.setPreferencePage(this); + apacheStartSFE.setPreferenceStore(getPreferenceStore()); + apacheStartSFE.load(); + new Label(apacheSettingsGroup, SWT.NONE); + + apacheStopBFE = new BooleanFieldEditor(ExternalToolsPlugin.APACHE_STOP_BACKGROUND, PHPPreferencesMessages + .getString("PHPBasePreferencePage.apacheGroup.stop_background"), apacheSettingsGroup); + apacheStopBFE.setPreferencePage(this); + apacheStopBFE.setPreferenceStore(getPreferenceStore()); + apacheStopBFE.load(); + new Label(apacheSettingsGroup, SWT.NONE); + new Label(apacheSettingsGroup, SWT.NONE); + apacheStopSFE = new StringFieldEditor(ExternalToolsPlugin.APACHE_STOP_PREF, PHPPreferencesMessages + .getString("PHPBasePreferencePage.apacheGroup.stop"), apacheSettingsGroup); + apacheStopSFE.setPreferencePage(this); + apacheStopSFE.setPreferenceStore(getPreferenceStore()); + apacheStopSFE.load(); + new Label(apacheSettingsGroup, SWT.NONE); + + apacheRestartBFE = new BooleanFieldEditor(ExternalToolsPlugin.APACHE_RESTART_BACKGROUND, PHPPreferencesMessages + .getString("PHPBasePreferencePage.apacheGroup.restart_background"), apacheSettingsGroup); + apacheRestartBFE.setPreferencePage(this); + apacheRestartBFE.setPreferenceStore(getPreferenceStore()); + apacheRestartBFE.load(); + new Label(apacheSettingsGroup, SWT.NONE); + new Label(apacheSettingsGroup, SWT.NONE); + apacheRestartSFE = new StringFieldEditor(ExternalToolsPlugin.APACHE_RESTART_PREF, PHPPreferencesMessages + .getString("PHPBasePreferencePage.apacheGroup.restart"), apacheSettingsGroup); + apacheRestartSFE.setPreferencePage(this); + apacheRestartSFE.setPreferenceStore(getPreferenceStore()); + apacheRestartSFE.load(); + new Label(apacheSettingsGroup, SWT.NONE); + + apacheRunFFE = new FileFieldEditor(ExternalToolsPlugin.APACHE_RUN_PREF, PHPPreferencesMessages + .getString("PHPBasePreferencePage.apacheGroup.run"), apacheSettingsGroup); + apacheRunFFE.setPreferencePage(this); + apacheRunFFE.setPreferenceStore(getPreferenceStore()); + apacheRunFFE.load(); + + phpRunFFE = new FileFieldEditor(ExternalToolsPlugin.PHP_RUN_PREF, PHPPreferencesMessages + .getString("PHPBasePreferencePage.console.php"), apacheSettingsGroup); + phpRunFFE.setPreferencePage(this); + phpRunFFE.setPreferenceStore(getPreferenceStore()); + phpRunFFE.load(); + + //Create mySQL + Composite mySQLSettingsComposite = new Composite(composite, SWT.NULL); + mySQLSettingsComposite.setLayout(new GridLayout()); + mySQLSettingsComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + Group mySQLSettingsGroup = new Group(mySQLSettingsComposite, SWT.NONE); + mySQLSettingsGroup.setText(PHPPreferencesMessages.getString("PHPBasePreferencePage.mySQLGroup")); + mySQLSettingsGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + mySQLSettingsGroup.setLayout(new GridLayout()); + + mysqlStartBFE = new BooleanFieldEditor(ExternalToolsPlugin.MYSQL_START_BACKGROUND, PHPPreferencesMessages + .getString("PHPBasePreferencePage.mySQLGroup.start_background"), mySQLSettingsGroup); + mysqlStartBFE.setPreferencePage(this); + mysqlStartBFE.setPreferenceStore(getPreferenceStore()); + mysqlStartBFE.load(); + new Label(mySQLSettingsGroup, SWT.NONE); + new Label(mySQLSettingsGroup, SWT.NONE); + + mySQLCommandSFE = new StringFieldEditor(ExternalToolsPlugin.MYSQL_PREF, PHPPreferencesMessages + .getString("PHPBasePreferencePage.mySQLGroup.command"), mySQLSettingsGroup); + mySQLCommandSFE.setPreferencePage(this); + mySQLCommandSFE.setPreferenceStore(getPreferenceStore()); + mySQLCommandSFE.load(); + new Label(mySQLSettingsGroup, SWT.NONE); + + mysqlRunFFE = new FileFieldEditor(ExternalToolsPlugin.MYSQL_RUN_PREF, PHPPreferencesMessages + .getString("PHPBasePreferencePage.mySQLGroup.run"), mySQLSettingsGroup); + mysqlRunFFE.setPreferencePage(this); + mysqlRunFFE.setPreferenceStore(getPreferenceStore()); + mysqlRunFFE.load(); + + Composite parserSettingsComposite = new Composite(composite, SWT.NULL); + parserSettingsComposite.setLayout(new GridLayout()); + parserSettingsComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + Group parserSettingsGroup = new Group(parserSettingsComposite, SWT.NONE); + parserSettingsGroup.setText("External parser command"); + parserSettingsGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + parserSettingsGroup.setLayout(new GridLayout()); + + externalParserSFE = + new StringFieldEditor( + ExternalToolsPlugin.EXTERNAL_PARSER_PREF, + PHPPreferencesMessages.getString("PHPBasePreferencePage.parsers.extcommand"), + parserSettingsGroup + ); + externalParserSFE.setPreferencePage(this); + externalParserSFE.setPreferenceStore(getPreferenceStore()); + externalParserSFE.load(); + + return composite; + } +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/preferences/PHPPreferencesMessages.java b/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/preferences/PHPPreferencesMessages.java new file mode 100644 index 0000000..6eecbdc --- /dev/null +++ b/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/preferences/PHPPreferencesMessages.java @@ -0,0 +1,39 @@ +package net.sourceforge.phpdt.externaltools.preferences; + +import java.text.MessageFormat; +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +public class PHPPreferencesMessages { + + private static final String RESOURCE_BUNDLE= PHPPreferencesMessages.class.getName(); + private static ResourceBundle fgResourceBundle= ResourceBundle.getBundle(RESOURCE_BUNDLE); + + private PHPPreferencesMessages() { + } + + public static String getString(String key) { + try { + return fgResourceBundle.getString(key); + } catch (MissingResourceException e) { + return '!' + key + '!'; + } + } + + /** + * Gets a string from the resource bundle and formats it with the argument + * + * @param key the string used to get the bundle value, must not be null + */ + public static String getFormattedString(String key, Object arg) { + return MessageFormat.format(getString(key), new Object[] { arg }); + } + + + /** + * Gets a string from the resource bundle and formats it with arguments + */ + public static String getFormattedString(String key, Object[] args) { + return MessageFormat.format(getString(key), args); + } +} diff --git a/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/preferences/PHPPreferencesMessages.properties b/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/preferences/PHPPreferencesMessages.properties new file mode 100644 index 0000000..7db8fcf --- /dev/null +++ b/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/preferences/PHPPreferencesMessages.properties @@ -0,0 +1,91 @@ +######################################### +# PHPProjectLibraryPage +######################################### + +PHPProjectLibraryPage.elementNotIProject=ERROR: Element not IProject +PHPProjectLibraryPage.project=Project +PHPProjectLibraryPage.tabName=Projects + + +######################################### +# Property Pages +######################################### + +PHPProjectPropertyPage.phpProjectClosed=The project selected is a PHP project, but is closed. +PHPProjectPropertyPage.performOkExceptionDialogTitle=Unable to save +PHPProjectPropertyPage.performOkExceptionDialogMessage=ERROR: Unable to save project properties. + +PHPMiscProjectPreferences.localhost=Localhost +PHPMiscProjectPreferences.documentroot=DocumentRoot +PHPMiscProjectPreferences.bookmark=SQL default bookmark: + +PHPMiscProjectPreferences.obfuscator=Obfuscator directory: + +PHPPreviewProjectPreferences.auto_preview=Refresh PHP browser view when opening editor +PHPPreviewProjectPreferences.bring_to_top_preview=Show PHP browser view when opening editor +PHPPreviewProjectPreferences.show_html_files_local=Show HTML files as local resources (no 'http://' url) + +######################################### +# Preference Pages +######################################### +PHPBasePreferencePage.description=PHP Preferences +PHPBasePreferencePage.websettingsGroup=Webserver Settings +PHPBasePreferencePage.websettingsGroup.localhost=Localhost +PHPBasePreferencePage.websettingsGroup.docroot=DocumentRoot +PHPBasePreferencePage.websettingsGroup.browser=External browser command +PHPBasePreferencePage.websettingsGroup.useexternal=Use external browser +#PHPBasePreferencePage.websettingsGroup.showexternalpreview=Show preview on editor load (win32 only) +PHPBasePreferencePage.apacheGroup=Apache Settings +PHPBasePreferencePage.apacheGroup.xampp_start=XAMPP Start +PHPBasePreferencePage.apacheGroup.xampp_stop=XAMPP Stop +PHPBasePreferencePage.apacheGroup.run=Apache +PHPBasePreferencePage.apacheGroup.start=Start Apache +PHPBasePreferencePage.apacheGroup.start_background=Run in background mode +PHPBasePreferencePage.apacheGroup.stop=Stop Apache +PHPBasePreferencePage.apacheGroup.stop_background=Run in background mode +PHPBasePreferencePage.apacheGroup.restart=Restart Apache +PHPBasePreferencePage.apacheGroup.restart_background=Run in background mode +PHPBasePreferencePage.console.php=Run PHP command +PHPBasePreferencePage.mySQLGroup=MySQL Settings +PHPBasePreferencePage.mySQLGroup.run=MySQL +PHPBasePreferencePage.mySQLGroup.start_background=Run in background mode +PHPBasePreferencePage.mySQLGroup.command=Start MySQL +PHPBasePreferencePage.parsers=Parsing settings +PHPBasePreferencePage.parsers.pos=Parse on save +PHPBasePreferencePage.parsers.external=External +PHPBasePreferencePage.parsers.internal=Internal +PHPBasePreferencePage.parsers.extcommand=Parser command +PHPBasePreferencePage.parsers.choose=Choose PHP Parser +PHPBasePreferencePage.phpExtensionPrefs=PHP file extensions (internal Parser) + +PHPEditorSyntaxPreferencePage.description:PHP Editor Preferences +PHPEditorSyntaxPreferencePage.background:Background settings +PHPEditorSyntaxPreferencePage.foreground:Foreground settings +PHPEditorSyntaxPreferencePage.syntax:Syntax highlighting +PHPEditorSyntaxPreferencePage.color:Colour +PHPEditorSyntaxPreferencePage.bold:Bold +PHPEditorSyntaxPreferencePage.italic:Italic +PHPEditorSyntaxPreferencePage.underline:Underline +PHPEditorSyntaxPreferencePage.multiLineComment=Multi-line comment +PHPEditorSyntaxPreferencePage.singleLineComment=Single-line comment +PHPEditorSyntaxPreferencePage.tags=PHP Tags +PHPEditorSyntaxPreferencePage.keywords=Keywords +PHPEditorSyntaxPreferencePage.variables=Variables +PHPEditorSyntaxPreferencePage.types=Types +PHPEditorSyntaxPreferencePage.functions=Functions +PHPEditorSyntaxPreferencePage.constants=Constants +PHPEditorSyntaxPreferencePage.strings_dq=Double Quoted Strings +PHPEditorSyntaxPreferencePage.strings_sq=Single Quoted Strings +PHPEditorSyntaxPreferencePage.others=Others +PHPEditorSyntaxPreferencePage.syntaxdialog=Custom PHP Syntax File: +PHPEditorSyntaxPreferencePage.browse=Browse.. +PHPEditorSyntaxPreferencePage.textfont=Text font + +PHPLanguagePreferencePage.description=PHP Editor Language +PHPLanguagePreferencePage.preflingo=PHP Language Preference +PHPLanguagePreferencePage.choose=Choose Language +PHPLanguagePreferencePage.english=English +PHPLanguagePreferencePage.german=German +PHPLanguagePreferencePage.french=French +PHPLanguagePreferencePage.spanish=Spanish +PHPLanguagePreferencePage.japanese=Japanese \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/util/StringUtil.java b/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/util/StringUtil.java new file mode 100644 index 0000000..c5ef81d --- /dev/null +++ b/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/util/StringUtil.java @@ -0,0 +1,34 @@ +/* + * Created on 28.06.2003 + * + */ +package net.sourceforge.phpdt.externaltools.util; + +/** + * some string utilities + * + */ +public class StringUtil { + + /** + * Replace each substring of str which matches findStr with replaceStr + * + * @param str the string the substrings should be replaced in + * @param findStr the substring to be replaced + * @param replaceStr the replacement + * @return the resultstring + */ + public static final String replaceAll(String str, String findStr, String replaceStr) { + StringBuffer buf = new StringBuffer(); + + int lastindex = 0; + int indexOf = 0; + while ((indexOf=str.indexOf(findStr, lastindex)) != -1) { + buf.append(str.substring(lastindex, indexOf)).append(replaceStr); + lastindex = indexOf + findStr.length(); + } + buf.append(str.substring(lastindex)); + return buf.toString(); + } + +} diff --git a/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpeclipse/externaltools/ExternalToolsPlugin.java b/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpeclipse/externaltools/ExternalToolsPlugin.java index 314cd05..0a2219a 100644 --- a/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpeclipse/externaltools/ExternalToolsPlugin.java +++ b/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpeclipse/externaltools/ExternalToolsPlugin.java @@ -9,8 +9,11 @@ package net.sourceforge.phpeclipse.externaltools; Contributors: **********************************************************************/ +import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; +import java.util.Enumeration; +import java.util.PropertyResourceBundle; import net.sourceforge.phpdt.externaltools.internal.model.ColorManager; import net.sourceforge.phpdt.externaltools.internal.model.ExternalToolsImages; @@ -22,7 +25,10 @@ import net.sourceforge.phpdt.externaltools.internal.registry.RefreshScopeVariabl import net.sourceforge.phpdt.externaltools.model.IExternalToolConstants; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPluginDescriptor; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.PreferenceConverter; @@ -63,10 +69,12 @@ public final class ExternalToolsPlugin extends AbstractUIPlugin { public static final String APACHE_RESTART_PREF = "__apache_restart"; - public static final String SHOW_OUTPUT_IN_CONSOLE = "_show_output_in_console"; + // public static final String SHOW_OUTPUT_IN_CONSOLE = "_show_output_in_console"; public static final String PHP_RUN_PREF = "_php_run_pref"; + public static final String EXTERNAL_PARSER_PREF = "_external_parser"; + /** * Status representing no problems encountered during operation. */ @@ -82,11 +90,12 @@ public final class ExternalToolsPlugin extends AbstractUIPlugin { private ArgumentVariableRegistry argumentVarRegistry; + /** - * Create an instance of the External Tools plug-in. + * This version is recommended for eclipse3.0 and above */ - public ExternalToolsPlugin() { // IPluginDescriptor descriptor) { - // super(descriptor); + public ExternalToolsPlugin() { + super(); plugin = this; } @@ -182,15 +191,56 @@ public final class ExternalToolsPlugin extends AbstractUIPlugin { /* * (non-Javadoc) Method declared in AbstractUIPlugin. */ - public void initializeDefaultPreferences(IPreferenceStore prefs) { - prefs.setDefault(IPreferenceConstants.PROMPT_FOR_MIGRATION, true); - PreferenceConverter.setDefault(prefs, IPreferenceConstants.CONSOLE_ERROR_RGB, new RGB(255, 0, 0)); // red - exactly the same as - // debug Consol - PreferenceConverter.setDefault(prefs, IPreferenceConstants.CONSOLE_WARNING_RGB, new RGB(255, 100, 0)); // orange - PreferenceConverter.setDefault(prefs, IPreferenceConstants.CONSOLE_INFO_RGB, new RGB(0, 0, 255)); // blue - PreferenceConverter.setDefault(prefs, IPreferenceConstants.CONSOLE_VERBOSE_RGB, new RGB(0, 200, 125)); // green - PreferenceConverter.setDefault(prefs, IPreferenceConstants.CONSOLE_DEBUG_RGB, new RGB(0, 0, 0)); // black + protected void initializeDefaultPreferences(IPreferenceStore store) { + String operatingSystem = Platform.getOS(); + // maxosx, linux, solaris, win32,... + try { + InputStream is = getDefault().openStream(new Path("prefs/default_" + operatingSystem + ".properties")); + PropertyResourceBundle resourceBundle = new PropertyResourceBundle(is); + Enumeration enum = resourceBundle.getKeys(); + String key; + while (enum.hasMoreElements()) { + key = (String) enum.nextElement(); + store.setDefault(key, resourceBundle.getString(key)); + } + } catch (Exception e) { + // no default properties found + if (operatingSystem.equals(Platform.OS_WIN32)) { + store.setDefault(PHP_RUN_PREF, "c:\\apache\\php\\php.exe"); + store.setDefault(EXTERNAL_PARSER_PREF, "c:\\apache\\php\\php -l -f {0}"); + store.setDefault(MYSQL_RUN_PREF, "c:\\apache\\mysql\\bin\\mysqld-nt.exe"); + store.setDefault(APACHE_RUN_PREF, "c:\\apache\\apache.exe"); + store.setDefault(XAMPP_START_PREF, "c:\\xampp\\xampp_start.exe"); + store.setDefault(XAMPP_STOP_PREF, "c:\\xampp\\xampp_stop.exe"); + } else { + store.setDefault(PHP_RUN_PREF, "/apache/php/php"); + store.setDefault(EXTERNAL_PARSER_PREF, "/apache/php/php -l -f {0}"); + store.setDefault(MYSQL_RUN_PREF, "/apache/mysql/bin/mysqld"); + store.setDefault(APACHE_RUN_PREF, "/apache/apache"); + store.setDefault(XAMPP_START_PREF, "xamp/xampp_start"); + store.setDefault(XAMPP_STOP_PREF, "xampp/xampp_stop"); + } + store.setDefault(MYSQL_PREF, "--standalone"); + store.setDefault(APACHE_START_PREF, "-c \"DocumentRoot \"{0}\"\""); + store.setDefault(APACHE_STOP_PREF, "-k shutdown"); + store.setDefault(APACHE_RESTART_PREF, "-k restart"); + store.setDefault(MYSQL_START_BACKGROUND, "true"); + store.setDefault(APACHE_START_BACKGROUND, "true"); + store.setDefault(APACHE_STOP_BACKGROUND, "true"); + store.setDefault(APACHE_RESTART_BACKGROUND, "true"); + } + + // store.setDefault(SHOW_OUTPUT_IN_CONSOLE, "true"); + + store.setDefault(IPreferenceConstants.PROMPT_FOR_MIGRATION, true); + + PreferenceConverter.setDefault(store, IPreferenceConstants.CONSOLE_ERROR_RGB, new RGB(255, 0, 0)); // red - exactly the same as + // debug Console + PreferenceConverter.setDefault(store, IPreferenceConstants.CONSOLE_WARNING_RGB, new RGB(255, 100, 0)); // orange + PreferenceConverter.setDefault(store, IPreferenceConstants.CONSOLE_INFO_RGB, new RGB(0, 0, 255)); // blue + PreferenceConverter.setDefault(store, IPreferenceConstants.CONSOLE_VERBOSE_RGB, new RGB(0, 200, 125)); // green + PreferenceConverter.setDefault(store, IPreferenceConstants.CONSOLE_DEBUG_RGB, new RGB(0, 0, 0)); // black } public static IWorkbenchWindow getActiveWorkbenchWindow() { diff --git a/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpeclipse/externaltools/PHPConsole.java b/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpeclipse/externaltools/PHPConsole.java new file mode 100644 index 0000000..817ec47 --- /dev/null +++ b/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpeclipse/externaltools/PHPConsole.java @@ -0,0 +1,107 @@ +package net.sourceforge.phpeclipse.externaltools; + +import java.io.IOException; +import java.io.InputStream; + +import org.eclipse.swt.graphics.Color; +import org.eclipse.ui.console.ConsolePlugin; +import org.eclipse.ui.console.IConsole; +import org.eclipse.ui.console.MessageConsole; +import org.eclipse.ui.console.MessageConsoleStream; + +public class PHPConsole { + private MessageConsole myConsole; + + private MessageConsoleStream stream; + + private boolean hasMessages; + + public PHPConsole() { + hasMessages = false; + myConsole = new MessageConsole("PHPeclipse Console", null); + ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] { myConsole }); + ConsolePlugin.getDefault().getConsoleManager().showConsoleView(myConsole); + // layout.addView(IConsoleConstants.ID_CONSOLE_VIEW, IPageLayout.BOTTOM, .5f,IPageLayout.ID_EDITOR_AREA); + stream = myConsole.newMessageStream(); + } + + /** + * @return + */ + public Color getColor() { + return stream.getColor(); + } + + /** + * @return + */ + public MessageConsole getConsole() { + return stream.getConsole(); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#hashCode() + */ + public int hashCode() { + return stream.hashCode(); + } + + /** + * @param message + */ + public void print(String message) { + hasMessages = true; + stream.print(message); + } + + /** + * + */ + public void println() { + hasMessages = true; + stream.println(); + } + + /** + * @param message + */ + public void println(String message) { + hasMessages = true; + stream.println(message); + } + + /** + * @param color + */ + public void setColor(Color color) { + stream.setColor(color); + } + + // public void reportError(String title, String message) { + // if (hasMessages) { + // WikiEditorPlugin.getDefault().reportError(title, message); + // } + // } + + // public void reportError() { + // reportError("Problems listed", "Open console view for problems log!"); + // } + /** + * Creates a string buffer from the given input stream + */ + public static String getStringFromStream(InputStream stream) throws IOException { + StringBuffer buffer = new StringBuffer(); + byte[] b = new byte[100]; + int finished = 0; + while (finished != -1) { + finished = stream.read(b); + if (finished != -1) { + String current = new String(b, 0, finished); + buffer.append(current); + } + } + return buffer.toString(); + } +} \ No newline at end of file -- 1.7.1