--- /dev/null
+/**********************************************************************
+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
--- /dev/null
+package net.sourceforge.phpdt.phphelp;
+
+import org.eclipse.jface.preference.BooleanFieldEditor;
+import org.eclipse.jface.preference.DirectoryFieldEditor;
+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 PHPHelpPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
+
+
+ FileFieldEditor phpCHMHelpFile;
+ BooleanFieldEditor phpCHMHelpEnabled;
+ StringFieldEditor phpCHMHelpCommand;
+
+ public PHPHelpPreferencePage() {
+ super();
+ setPreferenceStore(PHPHelpPlugin.getDefault().getPreferenceStore());
+ setDescription("PHP Help Settings (WIN_32 only)"); //$NON-NLS-1$
+ }
+
+ public void init(IWorkbench workbench) {
+ }
+
+ protected void performDefaults() {
+ phpCHMHelpFile.loadDefault();
+ phpCHMHelpEnabled.loadDefault();
+ phpCHMHelpCommand.loadDefault();
+ super.performDefaults();
+ }
+
+ public boolean performOk() {
+ phpCHMHelpFile.store();
+ phpCHMHelpEnabled.store();
+ phpCHMHelpCommand.store();
+ return super.performOk();
+ }
+
+ protected Control createContents(Composite parent) {
+ initializeDialogUnits(parent);
+ final IPreferenceStore store = PHPHelpPlugin.getDefault().getPreferenceStore();
+ Composite composite = new Composite(parent, SWT.LEFT);
+ composite.setLayout(new GridLayout());
+ composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+
+// Composite helpSettingsComposite = new Composite(composite, SWT.NONE);
+// helpSettingsComposite.setLayout(new GridLayout());
+// helpSettingsComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+// Group helpSettingsGroup = new Group(helpSettingsComposite, SWT.NONE);
+// helpSettingsGroup.setText("Windows CHM settings");
+// helpSettingsGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+// helpSettingsGroup.setLayout(new GridLayout());
+
+ phpCHMHelpEnabled =
+ new BooleanFieldEditor(
+ PHPHelpPlugin.PHP_CHM_ENABLED,
+ "Show Help in *.chm format?",
+ composite);
+ phpCHMHelpEnabled.setPreferencePage(this);
+ phpCHMHelpEnabled.setPreferenceStore(getPreferenceStore());
+ phpCHMHelpEnabled.load();
+
+ new Label(composite, SWT.NONE);
+ phpCHMHelpFile =
+ new FileFieldEditor(
+ PHPHelpPlugin.PHP_CHM_FILE,"PHP *.chm file:",
+ composite);
+ phpCHMHelpFile.setPreferencePage(this);
+ phpCHMHelpFile.setPreferenceStore(getPreferenceStore());
+ phpCHMHelpFile.load();
+
+ new Label(composite, SWT.NONE);
+ phpCHMHelpCommand =
+ new StringFieldEditor(
+ PHPHelpPlugin.PHP_CHM_COMMAND,
+ "PHP Help command:",
+ composite);
+ phpCHMHelpCommand.setPreferencePage(this);
+ phpCHMHelpCommand.setPreferenceStore(getPreferenceStore());
+ phpCHMHelpCommand.load();
+
+
+ return composite;
+ }
+}
**********************************************************************/
package net.sourceforge.phpdt.phphelp.actions;
+import java.io.IOException;
+import java.text.MessageFormat;
+
+import net.sourceforge.phpdt.phphelp.PHPHelpPlugin;
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.preference.IPreferenceStore;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextSelection;
}
public static void openContextHelp(String word) {
- IHelp help = WorkbenchHelp.getHelpSupport();
- if (help != null) {
- IHelpResource helpResource = new PHPFunctionHelpResource(word);
- WorkbenchHelp.getHelpSupport().displayHelpResource(helpResource);
+ IPreferenceStore store = PHPHelpPlugin.getDefault().getPreferenceStore();
+ if (store.getBoolean(PHPHelpPlugin.PHP_CHM_ENABLED)) {
+ String[] arguments = { store.getString(PHPHelpPlugin.PHP_CHM_FILE), word };
+ MessageFormat form = new MessageFormat(store.getString(PHPHelpPlugin.PHP_CHM_COMMAND));
+ try {
+ Runtime runtime = Runtime.getRuntime();
+ String command = form.format(arguments);
+
+ runtime.exec(command);
+ } catch (IOException e) {
+ }
} else {
- // showMessage(shell, dialogTitle, ActionMessages.getString("Open help not available"), false); //$NON-NLS-1$
+ IHelp help = WorkbenchHelp.getHelpSupport();
+ if (help != null) {
+ PHPFunctionHelpResource helpResource = new PHPFunctionHelpResource(word);
+ WorkbenchHelp.getHelpSupport().displayHelpResource(helpResource);
+ } else {
+ // showMessage(shell, dialogTitle, ActionMessages.getString("Open help not available"), false); //$NON-NLS-1$
+ }
}
}