added new error messages for keywords function, class
[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.ArrayList;
16 import java.util.Iterator;
17 import java.util.List;
18 import java.util.ResourceBundle;
19
20 import net.sourceforge.phpdt.ui.actions.GotoMatchingBracketAction;
21 import net.sourceforge.phpdt.ui.actions.PHPdtActionConstants;
22
23 import org.eclipse.jface.action.IAction;
24 import org.eclipse.jface.action.IMenuManager;
25 import org.eclipse.jface.action.IToolBarManager;
26 import org.eclipse.jface.action.Separator;
27 import org.eclipse.ui.IActionBars;
28 import org.eclipse.ui.IEditorPart;
29 import org.eclipse.ui.IWorkbenchActionConstants;
30 import org.eclipse.ui.actions.ActionGroup;
31 import org.eclipse.ui.actions.RetargetAction;
32 import org.eclipse.ui.texteditor.BasicTextEditorActionContributor;
33 import org.eclipse.ui.texteditor.ITextEditor;
34 import org.eclipse.ui.texteditor.ITextEditorActionConstants;
35 import org.eclipse.ui.texteditor.RetargetTextEditorAction;
36
37 /**
38  * Contributes interesting PHP actions to the desktop's Edit menu and the toolbar.
39  */
40 public class PHPActionContributor extends BasicTextEditorActionContributor {
41
42   // protected RetargetTextEditorAction fContentAssistTip;
43   // protected TextEditorAction fTogglePresentation;
44   protected RetargetAction fRetargetContentAssist;
45
46   protected RetargetTextEditorAction fContentAssist;
47   private RetargetTextEditorAction fGotoMatchingBracket;
48   private List fRetargetToolbarActions = new ArrayList();
49
50   protected PHPParserAction parserAction;
51
52   /**
53    * Default constructor.
54    */
55   public PHPActionContributor() {
56     super();
57
58     ResourceBundle b = PHPEditorMessages.getResourceBundle();
59
60     fRetargetContentAssist = new RetargetAction(PHPdtActionConstants.CONTENT_ASSIST, PHPEditorMessages.getString("ContentAssistProposal.label")); //$NON-NLS-1$
61     fRetargetContentAssist.setActionDefinitionId(
62       PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
63
64     fContentAssist = new RetargetTextEditorAction(b, "ContentAssistProposal."); //$NON-NLS-1$
65     fContentAssist.setActionDefinitionId(
66       PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
67
68     fGotoMatchingBracket = new RetargetTextEditorAction(b, "GotoMatchingBracket."); //$NON-NLS-1$
69     fGotoMatchingBracket.setActionDefinitionId(
70       PHPEditorActionDefinitionIds.GOTO_MATCHING_BRACKET);
71
72     //  fContentAssist.setImageDescriptor(JavaPluginImages.DESC_CLCL_CODE_ASSIST);
73     //  fContentAssist.setDisabledImageDescriptor(JavaPluginImages.DESC_DLCL_CODE_ASSIST);
74
75     // fContentAssist = new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "ContentAssistProposal."); //$NON-NLS-1$
76     //  fContentAssistTip = new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "ContentAssistTip."); //$NON-NLS-1$
77     //  fTogglePresentation = new PresentationAction();
78
79     parserAction = PHPParserAction.getInstance();
80   }
81
82   /*
83    * @see EditorActionBarContributor#contributeToMenu(IMenuManager)
84    */
85   //  public void contributeToMenu(IMenuManager menu) {         
86   //    super.contributeToMenu(menu);
87   //    IMenuManager editMenu= menu.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
88   //    if (editMenu != null) {
89   //      MenuManager structureSelection= new MenuManager(JavaEditorMessages.getString("ExpandSelectionMenu.label")); //$NON-NLS-1$
90   //      structureSelection.add(fStructureSelectEnclosingAction);
91   //      structureSelection.add(fStructureSelectNextAction);
92   //      structureSelection.add(fStructureSelectPreviousAction);
93   //      structureSelection.add(fStructureSelectHistoryAction);
94   //      editMenu.appendToGroup(IContextMenuConstants.GROUP_OPEN, structureSelection);
95   //      editMenu.appendToGroup(IContextMenuConstants.GROUP_OPEN, fGotoPreviousMemberAction);
96   //      editMenu.appendToGroup(IContextMenuConstants.GROUP_OPEN, fGotoNextMemberAction);
97   //      editMenu.appendToGroup(IContextMenuConstants.GROUP_OPEN, fGotoMatchingBracket);
98
99   //      editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE, fShowOutline);
100   //    }
101   //  }
102   /*
103    * @see EditorActionBarContributor#contributeToMenu(IMenuManager)
104    */
105   //  public void contributeToMenu(IMenuManager menu) {
106   //            
107   //      super.contributeToMenu(menu);
108   //            
109   //      IMenuManager editMenu= menu.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
110   //      if (editMenu != null) {
111   //              editMenu.add(new Separator(IContextMenuConstants.GROUP_OPEN));
112   //              editMenu.add(new Separator(IContextMenuConstants.GROUP_GENERATE));
113   //                    
114   //              editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE, fRetargetContentAssist);
115   //      }             
116   //  }
117
118   /*
119    * @see EditorActionBarContributor#contributeToToolBar(IToolBarManager)
120    */
121   public void contributeToToolBar(IToolBarManager tbm) {
122     tbm.add(new Separator());
123     Iterator e = fRetargetToolbarActions.iterator();
124     while (e.hasNext())
125       tbm.add((IAction) e.next());
126   }
127
128   /*
129    * @see IEditorActionBarContributor#init(IActionBars)
130    */
131   public void init(IActionBars bars) {
132     super.init(bars);
133
134     IMenuManager menuManager = bars.getMenuManager();
135     IMenuManager editMenu =
136       menuManager.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
137     if (editMenu != null) {
138       editMenu.add(new Separator());
139       editMenu.add(fContentAssist);
140       editMenu.add(fGotoMatchingBracket);
141       
142       //   editMenu.add(fContentAssistTip);
143     }
144
145     bars.setGlobalActionHandler(
146       PHPdtActionConstants.CONTENT_ASSIST,
147       fContentAssist);
148     //    IToolBarManager toolBarManager = bars.getToolBarManager();
149     //    if (toolBarManager != null) {
150     //      toolBarManager.add(new Separator());
151     //      toolBarManager.add(fTogglePresentation);
152     //    }
153   }
154
155   private void doSetActiveEditor(IEditorPart part) {
156     super.setActiveEditor(part);
157
158     ITextEditor textEditor = null;
159     if (part instanceof ITextEditor)
160       textEditor = (ITextEditor) part;
161
162     fContentAssist.setAction(getAction(textEditor, "ContentAssistProposal")); //$NON-NLS-1$
163     //  fContentAssistTip.setAction(getAction(editor, "ContentAssistTip")); //$NON-NLS-1$
164     fGotoMatchingBracket.setAction(
165       getAction(textEditor, GotoMatchingBracketAction.GOTO_MATCHING_BRACKET));
166
167     IActionBars bars = getActionBars();
168     bars.setGlobalActionHandler(
169       PHPdtActionConstants.COMMENT,
170       getAction(textEditor, "Comment"));
171     bars.setGlobalActionHandler(
172       PHPdtActionConstants.UNCOMMENT,
173       getAction(textEditor, "Uncomment"));
174     bars.setGlobalActionHandler(
175       PHPdtActionConstants.FORMAT,
176       getAction(textEditor, "Format"));
177
178     if (part instanceof PHPEditor) {
179       PHPEditor cuEditor = (PHPEditor) part;
180       ActionGroup group = cuEditor.getActionGroup();
181       if (group != null)
182         group.fillActionBars(bars);
183     }
184     //    fTogglePresentation.setEditor(editor);
185     //    fTogglePresentation.update();
186
187     parserAction.setEditor(textEditor);
188     parserAction.update();
189   }
190
191   /*
192    * @see IEditorActionBarContributor#setActiveEditor(IEditorPart)
193    */
194   public void setActiveEditor(IEditorPart part) {
195     doSetActiveEditor(part);
196   }
197
198   /*
199    * @see IEditorActionBarContributor#dispose()
200    */
201   public void dispose() {
202     doSetActiveEditor(null);
203     super.dispose();
204   }
205 }