Call WIN_32 CHM files for "function help"
authorkhartlage <khartlage>
Mon, 16 Jun 2003 21:45:11 +0000 (21:45 +0000)
committerkhartlage <khartlage>
Mon, 16 Jun 2003 21:45:11 +0000 (21:45 +0000)
net.sourceforge.phpeclipse.phphelp/plugin.xml
net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/phphelp/PHPHelpPlugin.java [new file with mode: 0644]
net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/phphelp/PHPHelpPreferencePage.java [new file with mode: 0644]
net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/phphelp/actions/PHPEclipseShowContextHelp.java
net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/phphelp/actions/PHPFunctionHelpResource.java

index 4e1aec9..bb1da88 100644 (file)
@@ -3,7 +3,8 @@
    id="net.sourceforge.phpeclipse.phphelp"
    name="%pluginName"
    version="1.0.4"
-   provider-name="%providerName">
+   provider-name="%providerName"
+   class="net.sourceforge.phpdt.phphelp.PHPHelpPlugin">
 
    <runtime>
       <library name="phphelp.jar"/>
             primary="true">
       </toc>
    </extension>
+   <extension
+         point="org.eclipse.ui.preferencePages">
+      <page
+            name="Help (WIN_32 chm format)"
+            category="net.sourceforge.phpeclipse.preference.PHPEclipsePreferencePage"
+            class="net.sourceforge.phpdt.phphelp.PHPHelpPreferencePage"
+            id="net.sourceforge.phpdt.phphelp.PHPHelpPreferencePage">
+      </page>
+   </extension>
 </plugin>
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
diff --git a/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/phphelp/PHPHelpPreferencePage.java b/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/phphelp/PHPHelpPreferencePage.java
new file mode 100644 (file)
index 0000000..2b5f3c1
--- /dev/null
@@ -0,0 +1,96 @@
+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;
+  }
+}
index 834d108..6895f51 100644 (file)
@@ -11,11 +11,16 @@ Contributors:
 **********************************************************************/
 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;
@@ -74,12 +79,25 @@ public class PHPEclipseShowContextHelp extends ActionDelegate implements IEditor
   }
 
   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$
+      }
     }
   }
 
index 7f0249f..ae1f34c 100644 (file)
@@ -24,6 +24,10 @@ public class PHPFunctionHelpResource implements IHelpResource {
     this.word = word;
   }
 
+  /**
+    * Get standard PHPEclipse html help URL 
+    * @return String
+    */
   public String getHref() {
     return "/net.sourceforge.phpeclipse.phphelp/doc/function." + word + ".html";
   }
@@ -31,5 +35,6 @@ public class PHPFunctionHelpResource implements IHelpResource {
   public String getLabel() {
     return "PHP Context Help";
   }
 
 }
\ No newline at end of file