3.x compatibility
[phpeclipse.git] / net.sourceforge.phpeclipse.phphelp / src / net / sourceforge / phpdt / phphelp / actions / PHPEclipseShowContextHelp.java
index 834d108..73957ae 100644 (file)
@@ -11,11 +11,15 @@ 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 +78,26 @@ 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.displayHelpResource(helpResource.getHref());
+        //getHelpSupport().displayHelpResource(helpResource);
+//      } else {
+        //   showMessage(shell, dialogTitle, ActionMessages.getString("Open help not available"), false); //$NON-NLS-1$
+//      }
     }
   }