Call WIN_32 CHM files for "function help"
[phpeclipse.git] / net.sourceforge.phpeclipse.phphelp / src / net / sourceforge / phpdt / phphelp / PHPHelpPlugin.java
diff --git a/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/phphelp/PHPHelpPlugin.java b/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/phphelp/PHPHelpPlugin.java
new file mode 100644 (file)
index 0000000..f12c1f9
--- /dev/null
@@ -0,0 +1,169 @@
+/**********************************************************************
+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;
+
+import net.sourceforge.phpdt.externaltools.internal.model.ColorManager;
+import net.sourceforge.phpdt.externaltools.internal.model.VariableContextManager;
+import net.sourceforge.phpeclipse.resourcesview.PHPElement;
+import net.sourceforge.phpeclipse.resourcesview.PHPElementAdapterFactory;
+import net.sourceforge.phpeclipse.resourcesview.ResourceAdapterFactory;
+
+import org.eclipse.core.boot.BootLoader;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdapterManager;
+import org.eclipse.core.runtime.IPath;
+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.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+
+/**
+ * The main plugin class to be used in the desktop.
+ */
+public class PHPHelpPlugin extends AbstractUIPlugin {
+  public static final String PHP_CHM_ENABLED = "_php_chm_enabled";
+  public static final String PHP_CHM_FILE = "_php_chm_file";
+  public static final String PHP_CHM_COMMAND = "_php_chm_command";
+
+  /**
+   * The id of the PHP plugin (value <code>"net.sourceforge.phpeclipse.phphelp"</code>).
+   */
+  public static final String PLUGIN_ID = "net.sourceforge.phpeclipse.phphelp"; //$NON-NLS-1$
+
+  //The shared instance.
+  private static PHPHelpPlugin plugin;
+  /**
+   * The constructor.
+   */
+  public PHPHelpPlugin(IPluginDescriptor descriptor) {
+    super(descriptor);
+    plugin = this;
+  }
+
+  /**
+   * Returns the shared instance.
+   */
+  public static PHPHelpPlugin getDefault() {
+    return plugin;
+  }
+  /**
+   * Returns the workspace instance.
+   */
+  public static IWorkspace getWorkspace() {
+    return ResourcesPlugin.getWorkspace();
+  }
+
+  public static IWorkbenchPage getActivePage() {
+    return getDefault().internalGetActivePage();
+  }
+
+  private IWorkbenchPage internalGetActivePage() {
+    IWorkbenchWindow window = getWorkbench().getActiveWorkbenchWindow();
+    if (window != null)
+      return window.getActivePage();
+    return null;
+  }
+
+  public static IWorkbenchWindow getActiveWorkbenchWindow() {
+    return getDefault().getWorkbench().getActiveWorkbenchWindow();
+  }
+
+  public static Shell getActiveWorkbenchShell() {
+    return getActiveWorkbenchWindow().getShell();
+  }
+
+  public static String getPluginId() {
+    return getDefault().getDescriptor().getUniqueIdentifier();
+  }
+
+  public static void log(IStatus status) {
+    getDefault().getLog().log(status);
+  }
+
+  public static void log(int severity, String message) {
+    Status status = new Status(severity, PLUGIN_ID, IStatus.OK, message, null);
+    log(status);
+  }
+  public static void log(Throwable e) {
+    log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "PHPeclipsePlugin.internalErrorOccurred", e)); //$NON-NLS-1$
+  }
+
+  public static boolean isDebug() {
+    return getDefault().isDebugging();
+  }
+
+  static IPath getInstallLocation() {
+    return new Path(getDefault().getDescriptor().getInstallURL().getFile());
+  }
+
+  protected void initializeDefaultPreferences(IPreferenceStore store) {
+    // windows preferences:
+    String windowsSystem = BootLoader.getWS();
+
+    if (windowsSystem.equals(BootLoader.WS_WIN32)) {
+      store.setDefault(PHP_CHM_ENABLED, "false");
+      store.setDefault(PHP_CHM_FILE, "");
+      store.setDefault(PHP_CHM_COMMAND, "hh.exe \"mk:@MSITStore:{0}::/en/function.{1}.html\"");
+    } else {
+      store.setDefault(PHP_CHM_ENABLED, "false");
+      store.setDefault(PHP_CHM_FILE, "");
+      store.setDefault(PHP_CHM_COMMAND, "");
+    }
+
+  }
+
+  /**
+   * Returns the standard display to be used. The method first checks, if
+   * the thread calling this method has an associated display. If so, this
+   * display is returned. Otherwise the method returns the default display.
+   */
+  public static Display getStandardDisplay() {
+    Display display = Display.getCurrent();
+    if (display == null) {
+      display = Display.getDefault();
+    }
+    return display;
+  }
+
+  public void startup() throws CoreException {
+    super.startup();
+    IAdapterManager manager = Platform.getAdapterManager();
+    manager.registerAdapters(new PHPElementAdapterFactory(), PHPElement.class);
+    manager.registerAdapters(new ResourceAdapterFactory(), IResource.class);
+    //  externalTools.startUp(); 
+    getStandardDisplay().asyncExec(new Runnable() {
+      public void run() {
+        //initialize the variable context manager
+        VariableContextManager.getDefault();
+      }
+    });
+  }
+
+  /**
+   * @see org.eclipse.core.runtime.Plugin#shutdown()
+   */
+  public void shutdown() throws CoreException {
+    //  externalTools.shutDown();
+    ColorManager.getDefault().dispose();
+  }
+
+}
\ No newline at end of file