1 package net.sourceforge.phpeclipse.phpeditor;
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
11 IBM Corporation - Initial implementation
12 Klaus Hartlage - www.eclipseproject.de
13 **********************************************************************/
15 import java.util.ArrayList;
16 import java.util.Iterator;
17 import java.util.List;
18 import java.util.ResourceBundle;
20 import net.sourceforge.phpdt.ui.actions.GotoMatchingBracketAction;
21 import net.sourceforge.phpdt.ui.actions.PHPdtActionConstants;
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;
38 * Contributes interesting PHP actions to the desktop's Edit menu and the toolbar.
40 public class PHPActionContributor extends BasicTextEditorActionContributor {
42 // protected RetargetTextEditorAction fContentAssistTip;
43 // protected TextEditorAction fTogglePresentation;
44 protected RetargetAction fRetargetContentAssist;
46 protected RetargetTextEditorAction fContentAssist;
47 private RetargetTextEditorAction fGotoMatchingBracket;
48 private List fRetargetToolbarActions = new ArrayList();
50 protected PHPParserAction parserAction;
53 * Default constructor.
55 public PHPActionContributor() {
58 ResourceBundle b = PHPEditorMessages.getResourceBundle();
60 fRetargetContentAssist = new RetargetAction(PHPdtActionConstants.CONTENT_ASSIST, PHPEditorMessages.getString("ContentAssistProposal.label")); //$NON-NLS-1$
61 fRetargetContentAssist.setActionDefinitionId(
62 PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
64 fContentAssist = new RetargetTextEditorAction(b, "ContentAssistProposal."); //$NON-NLS-1$
65 fContentAssist.setActionDefinitionId(
66 PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
68 fGotoMatchingBracket = new RetargetTextEditorAction(b, "GotoMatchingBracket."); //$NON-NLS-1$
69 fGotoMatchingBracket.setActionDefinitionId(
70 PHPEditorActionDefinitionIds.GOTO_MATCHING_BRACKET);
72 // fContentAssist.setImageDescriptor(JavaPluginImages.DESC_CLCL_CODE_ASSIST);
73 // fContentAssist.setDisabledImageDescriptor(JavaPluginImages.DESC_DLCL_CODE_ASSIST);
75 // fContentAssist = new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "ContentAssistProposal."); //$NON-NLS-1$
76 // fContentAssistTip = new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "ContentAssistTip."); //$NON-NLS-1$
77 // fTogglePresentation = new PresentationAction();
79 parserAction = PHPParserAction.getInstance();
83 * @see EditorActionBarContributor#contributeToMenu(IMenuManager)
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);
99 // editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE, fShowOutline);
103 * @see EditorActionBarContributor#contributeToMenu(IMenuManager)
105 // public void contributeToMenu(IMenuManager menu) {
107 // super.contributeToMenu(menu);
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));
114 // editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE, fRetargetContentAssist);
119 * @see EditorActionBarContributor#contributeToToolBar(IToolBarManager)
121 public void contributeToToolBar(IToolBarManager tbm) {
122 tbm.add(new Separator());
123 Iterator e = fRetargetToolbarActions.iterator();
125 tbm.add((IAction) e.next());
129 * @see IEditorActionBarContributor#init(IActionBars)
131 public void init(IActionBars bars) {
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);
142 // editMenu.add(fContentAssistTip);
145 bars.setGlobalActionHandler(
146 PHPdtActionConstants.CONTENT_ASSIST,
148 // IToolBarManager toolBarManager = bars.getToolBarManager();
149 // if (toolBarManager != null) {
150 // toolBarManager.add(new Separator());
151 // toolBarManager.add(fTogglePresentation);
155 private void doSetActiveEditor(IEditorPart part) {
156 super.setActiveEditor(part);
158 ITextEditor textEditor = null;
159 if (part instanceof ITextEditor)
160 textEditor = (ITextEditor) part;
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));
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"));
178 if (part instanceof PHPEditor) {
179 PHPEditor cuEditor = (PHPEditor) part;
180 ActionGroup group = cuEditor.getActionGroup();
182 group.fillActionBars(bars);
184 // fTogglePresentation.setEditor(editor);
185 // fTogglePresentation.update();
187 parserAction.setEditor(textEditor);
188 parserAction.update();
192 * @see IEditorActionBarContributor#setActiveEditor(IEditorPart)
194 public void setActiveEditor(IEditorPart part) {
195 doSetActiveEditor(part);
199 * @see IEditorActionBarContributor#dispose()
201 public void dispose() {
202 doSetActiveEditor(null);