improved php parser (if-statement); but a lot of things don't work yet
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / actions / PHPEclipseShowContextHelp.java
index 9a638e2..bc03293 100644 (file)
@@ -11,37 +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.IEditorInput;
 import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.actions.ActionDelegate;
-import org.eclipse.ui.internal.EditorPluginAction;
-
-public class PHPEclipseShowContextHelp
-  extends ActionDelegate
-  implements IEditorActionDelegate {
-    
-private IEditorPart editor;
-  /**
-   * @see ActionDelegate#run(IAction)
-   */
+
+public class PHPEclipseShowContextHelp extends ActionDelegate implements IEditorActionDelegate {
+
+  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;
-    IEditorInput input = 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 = targetEditor;
+    if (targetEditor != null && (targetEditor instanceof PHPEditor)) {
+      editor = (PHPEditor) targetEditor;
+    }
   }
 
 }