use module net.sourceforge.phpeclipse.phphelp instead of net.sourceforge.phpeclipse...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / PHPActionContributor.java
1 package net.sourceforge.phpeclipse.phpeditor;
2
3 /**********************************************************************
4 Copyright (c) 2000, 2002 IBM Corp. and others.
5 All rights reserved. This program and the accompanying materials
6 are made available under the terms of the Common Public License v1.0
7 which accompanies this distribution, and is available at
8 http://www.eclipse.org/legal/cpl-v10.html
9
10 Contributors:
11     IBM Corporation - Initial implementation
12     Klaus Hartlage - www.eclipseproject.de
13 **********************************************************************/
14
15 import java.util.ResourceBundle;
16 import org.eclipse.jface.action.IMenuManager;
17 import org.eclipse.jface.action.IToolBarManager;
18 import org.eclipse.jface.action.Separator;
19 import org.eclipse.ui.IActionBars;
20 import org.eclipse.ui.IEditorPart;
21 import org.eclipse.ui.IWorkbenchActionConstants;
22 import org.eclipse.ui.editors.text.TextEditorActionContributor;
23 import org.eclipse.ui.texteditor.BasicTextEditorActionContributor;
24 import org.eclipse.ui.texteditor.ITextEditor;
25 import org.eclipse.ui.texteditor.RetargetTextEditorAction;
26 import org.eclipse.ui.texteditor.TextEditorAction;
27
28 /**
29  * Contributes interesting PHP actions to the desktop's Edit menu and the toolbar.
30  */
31 public class PHPActionContributor extends BasicTextEditorActionContributor implements PHPEditorActionDefinitionIds {
32
33   protected RetargetTextEditorAction fContentAssistProposal;
34   // protected RetargetTextEditorAction fContentAssistTip;
35   // protected TextEditorAction fTogglePresentation;
36   protected PHPParserAction parserAction;
37
38   /**
39    * Default constructor.
40    */
41   public PHPActionContributor() {
42     super();
43     fContentAssistProposal = new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "ContentAssistProposal."); //$NON-NLS-1$
44     //  fContentAssistTip = new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "ContentAssistTip."); //$NON-NLS-1$
45     //  fTogglePresentation = new PresentationAction();
46     parserAction = PHPParserAction.getInstance();
47   }
48
49   /*
50    * @see IEditorActionBarContributor#init(IActionBars)
51    */
52   public void init(IActionBars bars) {
53     super.init(bars);
54
55     IMenuManager menuManager = bars.getMenuManager();
56     IMenuManager editMenu = menuManager.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
57     if (editMenu != null) {
58       editMenu.add(new Separator());
59       editMenu.add(fContentAssistProposal);
60       //   editMenu.add(fContentAssistTip);
61     }
62
63     //    IToolBarManager toolBarManager = bars.getToolBarManager();
64     //    if (toolBarManager != null) {
65     //      toolBarManager.add(new Separator());
66     //      toolBarManager.add(fTogglePresentation);
67     //    }
68   }
69
70   private void doSetActiveEditor(IEditorPart part) {
71     super.setActiveEditor(part);
72
73     ITextEditor textEditor = null;
74     if (part instanceof ITextEditor)
75       textEditor = (ITextEditor) part;
76
77     fContentAssistProposal.setAction(getAction(textEditor, "ContentAssistProposal")); //$NON-NLS-1$
78     //  fContentAssistTip.setAction(getAction(editor, "ContentAssistTip")); //$NON-NLS-1$
79
80     IActionBars bars = getActionBars();
81     bars.setGlobalActionHandler(COMMENT, getAction(textEditor, "Comment"));
82     bars.setGlobalActionHandler(UNCOMMENT, getAction(textEditor, "Uncomment"));
83
84     //    fTogglePresentation.setEditor(editor);
85     //    fTogglePresentation.update();
86
87     parserAction.setEditor(textEditor);
88     parserAction.update();
89   }
90
91   /*
92    * @see IEditorActionBarContributor#setActiveEditor(IEditorPart)
93    */
94   public void setActiveEditor(IEditorPart part) {
95     super.setActiveEditor(part);
96     doSetActiveEditor(part);
97
98   }
99
100   /*
101    * @see IEditorActionBarContributor#dispose()
102    */
103   public void dispose() {
104     doSetActiveEditor(null);
105     super.dispose();
106   }
107 }