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;
22 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
24 import org.eclipse.jface.action.IAction;
25 import org.eclipse.jface.action.IMenuManager;
26 import org.eclipse.jface.action.IToolBarManager;
27 import org.eclipse.jface.action.Separator;
28 import org.eclipse.jface.preference.IPreferenceStore;
29 import org.eclipse.swt.SWT;
30 import org.eclipse.ui.IActionBars;
31 import org.eclipse.ui.IEditorPart;
32 import org.eclipse.ui.IWorkbenchActionConstants;
33 import org.eclipse.ui.actions.ActionGroup;
34 import org.eclipse.ui.actions.RetargetAction;
35 import org.eclipse.ui.texteditor.AbstractTextEditor;
36 import org.eclipse.ui.texteditor.BasicTextEditorActionContributor;
37 import org.eclipse.ui.texteditor.ITextEditor;
38 import org.eclipse.ui.texteditor.RetargetTextEditorAction;
41 * Contributes interesting PHP actions to the desktop's Edit menu and the toolbar.
43 public class PHPActionContributor extends BasicTextEditorActionContributor {
45 // protected RetargetTextEditorAction fContentAssistTip;
46 // protected TextEditorAction fTogglePresentation;
47 protected RetargetAction fRetargetContentAssist;
49 protected RetargetTextEditorAction fContentAssist;
50 private RetargetTextEditorAction fGotoMatchingBracket;
51 private List fRetargetToolbarActions = new ArrayList();
53 protected PHPParserAction fParserAction;
54 protected ShowExternalPreviewAction fShowExternalPreviewAction;
57 * Default constructor.
59 public PHPActionContributor() {
62 ResourceBundle b = PHPEditorMessages.getResourceBundle();
64 fRetargetContentAssist = new RetargetAction(PHPdtActionConstants.CONTENT_ASSIST, PHPEditorMessages.getString("ContentAssistProposal.label")); //$NON-NLS-1$
65 fRetargetContentAssist.setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
67 fContentAssist = new RetargetTextEditorAction(b, "ContentAssistProposal."); //$NON-NLS-1$
68 fContentAssist.setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
70 fGotoMatchingBracket = new RetargetTextEditorAction(b, "GotoMatchingBracket."); //$NON-NLS-1$
71 fGotoMatchingBracket.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_MATCHING_BRACKET);
73 // fContentAssist.setImageDescriptor(JavaPluginImages.DESC_CLCL_CODE_ASSIST);
74 // fContentAssist.setDisabledImageDescriptor(JavaPluginImages.DESC_DLCL_CODE_ASSIST);
76 // fContentAssist = new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "ContentAssistProposal."); //$NON-NLS-1$
77 // fContentAssistTip = new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "ContentAssistTip."); //$NON-NLS-1$
78 // fTogglePresentation = new PresentationAction();
80 fParserAction = PHPParserAction.getInstance();
82 if (SWT.getPlatform().equals("win32")) {
83 fShowExternalPreviewAction = ShowExternalPreviewAction.getInstance();
88 * @see EditorActionBarContributor#contributeToMenu(IMenuManager)
90 // public void contributeToMenu(IMenuManager menu) {
91 // super.contributeToMenu(menu);
92 // IMenuManager editMenu= menu.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
93 // if (editMenu != null) {
94 // MenuManager structureSelection= new MenuManager(JavaEditorMessages.getString("ExpandSelectionMenu.label")); //$NON-NLS-1$
95 // structureSelection.add(fStructureSelectEnclosingAction);
96 // structureSelection.add(fStructureSelectNextAction);
97 // structureSelection.add(fStructureSelectPreviousAction);
98 // structureSelection.add(fStructureSelectHistoryAction);
99 // editMenu.appendToGroup(IContextMenuConstants.GROUP_OPEN, structureSelection);
100 // editMenu.appendToGroup(IContextMenuConstants.GROUP_OPEN, fGotoPreviousMemberAction);
101 // editMenu.appendToGroup(IContextMenuConstants.GROUP_OPEN, fGotoNextMemberAction);
102 // editMenu.appendToGroup(IContextMenuConstants.GROUP_OPEN, fGotoMatchingBracket);
104 // editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE, fShowOutline);
108 * @see EditorActionBarContributor#contributeToMenu(IMenuManager)
110 // public void contributeToMenu(IMenuManager menu) {
112 // super.contributeToMenu(menu);
114 // IMenuManager editMenu= menu.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
115 // if (editMenu != null) {
116 // editMenu.add(new Separator(IContextMenuConstants.GROUP_OPEN));
117 // editMenu.add(new Separator(IContextMenuConstants.GROUP_GENERATE));
119 // editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE, fRetargetContentAssist);
124 * @see EditorActionBarContributor#contributeToToolBar(IToolBarManager)
126 public void contributeToToolBar(IToolBarManager tbm) {
127 tbm.add(new Separator());
128 Iterator e = fRetargetToolbarActions.iterator();
130 tbm.add((IAction) e.next());
134 * @see IEditorActionBarContributor#init(IActionBars)
136 public void init(IActionBars bars) {
139 IMenuManager menuManager = bars.getMenuManager();
140 IMenuManager editMenu = menuManager.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
141 if (editMenu != null) {
142 editMenu.add(new Separator());
143 editMenu.add(fContentAssist);
144 editMenu.add(fGotoMatchingBracket);
146 // editMenu.add(fContentAssistTip);
149 bars.setGlobalActionHandler(PHPdtActionConstants.CONTENT_ASSIST, fContentAssist);
150 // IToolBarManager toolBarManager = bars.getToolBarManager();
151 // if (toolBarManager != null) {
152 // toolBarManager.add(new Separator());
153 // toolBarManager.add(fTogglePresentation);
157 private void doSetActiveEditor(IEditorPart part) {
158 super.setActiveEditor(part);
160 ITextEditor textEditor = null;
161 if (part instanceof ITextEditor)
162 textEditor = (ITextEditor) part;
164 fContentAssist.setAction(getAction(textEditor, "ContentAssistProposal")); //$NON-NLS-1$
165 // fContentAssistTip.setAction(getAction(editor, "ContentAssistTip")); //$NON-NLS-1$
166 fGotoMatchingBracket.setAction(getAction(textEditor, GotoMatchingBracketAction.GOTO_MATCHING_BRACKET));
168 IActionBars bars = getActionBars();
169 bars.setGlobalActionHandler(PHPdtActionConstants.COMMENT, getAction(textEditor, "Comment"));
170 bars.setGlobalActionHandler(PHPdtActionConstants.UNCOMMENT, getAction(textEditor, "Uncomment"));
171 bars.setGlobalActionHandler(PHPdtActionConstants.FORMAT, getAction(textEditor, "Format"));
173 if (part instanceof PHPEditor) {
174 PHPEditor cuEditor = (PHPEditor) part;
175 ActionGroup group = cuEditor.getActionGroup();
177 group.fillActionBars(bars);
179 // fTogglePresentation.setEditor(editor);
180 // fTogglePresentation.update();
182 PHPeclipsePlugin.getDefault().setTextEditor(textEditor);
183 fParserAction.setEditor(textEditor);
184 fParserAction.update();
185 if (SWT.getPlatform().equals("win32") &&
186 textEditor instanceof AbstractTextEditor) {
187 fShowExternalPreviewAction.setEditor(textEditor);
188 fShowExternalPreviewAction.update();
189 IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
190 if (store.getBoolean(PHPeclipsePlugin.SHOW_EXTERNAL_PREVIEW_PREF)) {
191 IAction a = ShowExternalPreviewAction.getInstance();
199 * @see IEditorActionBarContributor#setActiveEditor(IEditorPart)
201 public void setActiveEditor(IEditorPart part) {
202 doSetActiveEditor(part);
206 * @see IEditorActionBarContributor#dispose()
208 public void dispose() {
209 doSetActiveEditor(null);