Call WIN_32 CHM files for "function help"
[phpeclipse.git] / net.sourceforge.phpeclipse.phphelp / src / net / sourceforge / phpdt / phphelp / PHPHelpPlugin.java
1 /**********************************************************************
2 Copyright (c) 2000, 2002 IBM Corp. and others.
3 All rights reserved. This program and the accompanying materials
4 are made available under the terms of the Common Public License v1.0
5 which accompanies this distribution, and is available at
6 http://www.eclipse.org/legal/cpl-v10.html
7
8 Contributors:
9     IBM Corporation - Initial implementation
10     Klaus Hartlage - www.eclipseproject.de
11 **********************************************************************/
12 package net.sourceforge.phpdt.phphelp;
13
14 import net.sourceforge.phpdt.externaltools.internal.model.ColorManager;
15 import net.sourceforge.phpdt.externaltools.internal.model.VariableContextManager;
16 import net.sourceforge.phpeclipse.resourcesview.PHPElement;
17 import net.sourceforge.phpeclipse.resourcesview.PHPElementAdapterFactory;
18 import net.sourceforge.phpeclipse.resourcesview.ResourceAdapterFactory;
19
20 import org.eclipse.core.boot.BootLoader;
21 import org.eclipse.core.resources.IResource;
22 import org.eclipse.core.resources.IWorkspace;
23 import org.eclipse.core.resources.ResourcesPlugin;
24 import org.eclipse.core.runtime.CoreException;
25 import org.eclipse.core.runtime.IAdapterManager;
26 import org.eclipse.core.runtime.IPath;
27 import org.eclipse.core.runtime.IPluginDescriptor;
28 import org.eclipse.core.runtime.IStatus;
29 import org.eclipse.core.runtime.Path;
30 import org.eclipse.core.runtime.Platform;
31 import org.eclipse.core.runtime.Status;
32 import org.eclipse.jface.preference.IPreferenceStore;
33 import org.eclipse.swt.widgets.Display;
34 import org.eclipse.swt.widgets.Shell;
35 import org.eclipse.ui.IWorkbenchPage;
36 import org.eclipse.ui.IWorkbenchWindow;
37 import org.eclipse.ui.plugin.AbstractUIPlugin;
38
39 /**
40  * The main plugin class to be used in the desktop.
41  */
42 public class PHPHelpPlugin extends AbstractUIPlugin {
43   public static final String PHP_CHM_ENABLED = "_php_chm_enabled";
44   public static final String PHP_CHM_FILE = "_php_chm_file";
45   public static final String PHP_CHM_COMMAND = "_php_chm_command";
46
47   /**
48    * The id of the PHP plugin (value <code>"net.sourceforge.phpeclipse.phphelp"</code>).
49    */
50   public static final String PLUGIN_ID = "net.sourceforge.phpeclipse.phphelp"; //$NON-NLS-1$
51
52   //The shared instance.
53   private static PHPHelpPlugin plugin;
54   /**
55    * The constructor.
56    */
57   public PHPHelpPlugin(IPluginDescriptor descriptor) {
58     super(descriptor);
59     plugin = this;
60   }
61
62   /**
63    * Returns the shared instance.
64    */
65   public static PHPHelpPlugin getDefault() {
66     return plugin;
67   }
68   /**
69    * Returns the workspace instance.
70    */
71   public static IWorkspace getWorkspace() {
72     return ResourcesPlugin.getWorkspace();
73   }
74
75   public static IWorkbenchPage getActivePage() {
76     return getDefault().internalGetActivePage();
77   }
78
79   private IWorkbenchPage internalGetActivePage() {
80     IWorkbenchWindow window = getWorkbench().getActiveWorkbenchWindow();
81     if (window != null)
82       return window.getActivePage();
83     return null;
84   }
85
86   public static IWorkbenchWindow getActiveWorkbenchWindow() {
87     return getDefault().getWorkbench().getActiveWorkbenchWindow();
88   }
89
90   public static Shell getActiveWorkbenchShell() {
91     return getActiveWorkbenchWindow().getShell();
92   }
93
94   public static String getPluginId() {
95     return getDefault().getDescriptor().getUniqueIdentifier();
96   }
97
98   public static void log(IStatus status) {
99     getDefault().getLog().log(status);
100   }
101
102   public static void log(int severity, String message) {
103     Status status = new Status(severity, PLUGIN_ID, IStatus.OK, message, null);
104     log(status);
105   }
106   public static void log(Throwable e) {
107     log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "PHPeclipsePlugin.internalErrorOccurred", e)); //$NON-NLS-1$
108   }
109
110   public static boolean isDebug() {
111     return getDefault().isDebugging();
112   }
113
114   static IPath getInstallLocation() {
115     return new Path(getDefault().getDescriptor().getInstallURL().getFile());
116   }
117
118   protected void initializeDefaultPreferences(IPreferenceStore store) {
119     // windows preferences:
120     String windowsSystem = BootLoader.getWS();
121
122     if (windowsSystem.equals(BootLoader.WS_WIN32)) {
123       store.setDefault(PHP_CHM_ENABLED, "false");
124       store.setDefault(PHP_CHM_FILE, "");
125       store.setDefault(PHP_CHM_COMMAND, "hh.exe \"mk:@MSITStore:{0}::/en/function.{1}.html\"");
126     } else {
127       store.setDefault(PHP_CHM_ENABLED, "false");
128       store.setDefault(PHP_CHM_FILE, "");
129       store.setDefault(PHP_CHM_COMMAND, "");
130     }
131
132   }
133
134   /**
135    * Returns the standard display to be used. The method first checks, if
136    * the thread calling this method has an associated display. If so, this
137    * display is returned. Otherwise the method returns the default display.
138    */
139   public static Display getStandardDisplay() {
140     Display display = Display.getCurrent();
141     if (display == null) {
142       display = Display.getDefault();
143     }
144     return display;
145   }
146
147   public void startup() throws CoreException {
148     super.startup();
149     IAdapterManager manager = Platform.getAdapterManager();
150     manager.registerAdapters(new PHPElementAdapterFactory(), PHPElement.class);
151     manager.registerAdapters(new ResourceAdapterFactory(), IResource.class);
152     //  externalTools.startUp(); 
153     getStandardDisplay().asyncExec(new Runnable() {
154       public void run() {
155         //initialize the variable context manager
156         VariableContextManager.getDefault();
157       }
158     });
159   }
160
161   /**
162    * @see org.eclipse.core.runtime.Plugin#shutdown()
163    */
164   public void shutdown() throws CoreException {
165     //  externalTools.shutDown();
166     ColorManager.getDefault().dispose();
167   }
168
169 }