improved php parser for keywords do-while, null, false, true...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / actions / PHPEclipseShowContextHelp.java
index 2b5bd88..bc03293 100644 (file)
@@ -11,33 +11,53 @@ Contributors:
 **********************************************************************/
 package net.sourceforge.phpeclipse.actions;
 
+import net.sourceforge.phpeclipse.phpeditor.PHPEditor;
 import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.text.TextSelection;
+import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.ui.IEditorActionDelegate;
 import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.actions.ActionDelegate;
-import org.eclipse.ui.editors.text.TextEditor;
-import org.eclipse.ui.internal.EditorPluginAction;
-import org.eclipse.ui.part.FileEditorInput;
 
 public class PHPEclipseShowContextHelp extends ActionDelegate implements IEditorActionDelegate {
 
-  private TextEditor editor;
-  /**
-   * @see ActionDelegate#run(IAction)
-   */
+  private IWorkbenchWindow window;
+  private PHPEditor editor;
+
+  public void dispose() {
+  }
+
+  public void init(IWorkbenchWindow window) {
+    this.window = window;
+  }
+
+  public void selectionChanged(IAction action, ISelection selection) {
+    if (!selection.isEmpty()) {
+      if (selection instanceof TextSelection) {
+        action.setEnabled(true);
+      } else if (window.getActivePage() != null && window.getActivePage().getActivePart() != null) {
+        //
+      }
+    }
+  }
+
   public void run(IAction action) {
-    EditorPluginAction editorPluginAction = (EditorPluginAction) action;
-    FileEditorInput input = (FileEditorInput) editor.getEditorInput();
-    // Add your code here to perform the action
-    MessageDialog.openInformation(editor.getSite().getShell(), "Context Help: ", input.toString());
+    if (editor == null) {
+      IEditorPart targetEditor = window.getActivePage().getActiveEditor();
+      if (targetEditor != null && (targetEditor instanceof PHPEditor)) {
+        editor = (PHPEditor) targetEditor;
+      }
+    }
+    if (editor != null) {
+      editor.openContextHelp();
+    }
   }
 
-  /**
-   * @see IEditorActionDelegate#setActiveEditor(IAction, IEditorPart)
-   */
   public void setActiveEditor(IAction action, IEditorPart targetEditor) {
-    this.editor = (TextEditor) targetEditor;
+    if (targetEditor != null && (targetEditor instanceof PHPEditor)) {
+      editor = (PHPEditor) targetEditor;
+    }
   }
 
 }