bc03293aca56ceec0649258a97d5706dfc8f0514
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / actions / PHPEclipseShowContextHelp.java
1 /**********************************************************************
2 Copyright (c) 2000, 2002 IBM Corp. and others.
3 All rights reserved. This program and the accompanying materials
4 are made available under the terms of the Common Public License v1.0
5 which accompanies this distribution, and is available at
6 http://www.eclipse.org/legal/cpl-v10.html
7
8 Contributors:
9     IBM Corporation - Initial implementation
10     Klaus Hartlage - www.eclipseproject.de
11 **********************************************************************/
12 package net.sourceforge.phpeclipse.actions;
13
14 import net.sourceforge.phpeclipse.phpeditor.PHPEditor;
15 import org.eclipse.jface.action.IAction;
16 import org.eclipse.jface.text.TextSelection;
17 import org.eclipse.jface.viewers.ISelection;
18 import org.eclipse.ui.IEditorActionDelegate;
19 import org.eclipse.ui.IEditorPart;
20 import org.eclipse.ui.IWorkbenchWindow;
21 import org.eclipse.ui.actions.ActionDelegate;
22
23 public class PHPEclipseShowContextHelp extends ActionDelegate implements IEditorActionDelegate {
24
25   private IWorkbenchWindow window;
26   private PHPEditor editor;
27
28   public void dispose() {
29   }
30
31   public void init(IWorkbenchWindow window) {
32     this.window = window;
33   }
34
35   public void selectionChanged(IAction action, ISelection selection) {
36     if (!selection.isEmpty()) {
37       if (selection instanceof TextSelection) {
38         action.setEnabled(true);
39       } else if (window.getActivePage() != null && window.getActivePage().getActivePart() != null) {
40         //
41       }
42     }
43   }
44
45   public void run(IAction action) {
46     if (editor == null) {
47       IEditorPart targetEditor = window.getActivePage().getActiveEditor();
48       if (targetEditor != null && (targetEditor instanceof PHPEditor)) {
49         editor = (PHPEditor) targetEditor;
50       }
51     }
52     if (editor != null) {
53       editor.openContextHelp();
54     }
55   }
56
57   public void setActiveEditor(IAction action, IEditorPart targetEditor) {
58     if (targetEditor != null && (targetEditor instanceof PHPEditor)) {
59       editor = (PHPEditor) targetEditor;
60     }
61   }
62
63 }