fix browse button in create new PHP file wizard
[phpeclipse.git] / net.sourceforge.phpeclipse.externaltools / src / net / sourceforge / phpeclipse / externaltools / ExternalToolsPlugin.java
index 314cd05..3ecc289 100644 (file)
@@ -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;
@@ -23,6 +26,8 @@ import net.sourceforge.phpdt.externaltools.model.IExternalToolConstants;
 
 import org.eclipse.core.runtime.CoreException;
 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 +68,15 @@ 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 HTTPD_CONF_PATH_PREF = "__httpd_conf_path";
+  
+  public static final String ETC_HOSTS_PATH_PREF = "__etc_hosts_path";
+  //  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 +92,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 +193,57 @@ 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");
+        store.setDefault(ETC_HOSTS_PATH_PREF, "c:\\windows\\system32\\drivers\\etc\\hosts");
+      } 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() {