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 parserAction;
54 protected ShowExternalPreviewAction showExternalPreviewAction;
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 parserAction = PHPParserAction.getInstance();
81 if (SWT.getPlatform().equals("win32")) {
82 showExternalPreviewAction = ShowExternalPreviewAction.getInstance();
87 * @see EditorActionBarContributor#contributeToMenu(IMenuManager)
89 // public void contributeToMenu(IMenuManager menu) {
90 // super.contributeToMenu(menu);
91 // IMenuManager editMenu= menu.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
92 // if (editMenu != null) {
93 // MenuManager structureSelection= new MenuManager(JavaEditorMessages.getString("ExpandSelectionMenu.label")); //$NON-NLS-1$
94 // structureSelection.add(fStructureSelectEnclosingAction);
95 // structureSelection.add(fStructureSelectNextAction);
96 // structureSelection.add(fStructureSelectPreviousAction);
97 // structureSelection.add(fStructureSelectHistoryAction);
98 // editMenu.appendToGroup(IContextMenuConstants.GROUP_OPEN, structureSelection);
99 // editMenu.appendToGroup(IContextMenuConstants.GROUP_OPEN, fGotoPreviousMemberAction);
100 // editMenu.appendToGroup(IContextMenuConstants.GROUP_OPEN, fGotoNextMemberAction);
101 // editMenu.appendToGroup(IContextMenuConstants.GROUP_OPEN, fGotoMatchingBracket);
103 // editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE, fShowOutline);
107 * @see EditorActionBarContributor#contributeToMenu(IMenuManager)
109 // public void contributeToMenu(IMenuManager menu) {
111 // super.contributeToMenu(menu);
113 // IMenuManager editMenu= menu.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
114 // if (editMenu != null) {
115 // editMenu.add(new Separator(IContextMenuConstants.GROUP_OPEN));
116 // editMenu.add(new Separator(IContextMenuConstants.GROUP_GENERATE));
118 // editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE, fRetargetContentAssist);
123 * @see EditorActionBarContributor#contributeToToolBar(IToolBarManager)
125 public void contributeToToolBar(IToolBarManager tbm) {
126 tbm.add(new Separator());
127 Iterator e = fRetargetToolbarActions.iterator();
129 tbm.add((IAction) e.next());
133 * @see IEditorActionBarContributor#init(IActionBars)
135 public void init(IActionBars bars) {
138 IMenuManager menuManager = bars.getMenuManager();
139 IMenuManager editMenu = menuManager.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
140 if (editMenu != null) {
141 editMenu.add(new Separator());
142 editMenu.add(fContentAssist);
143 editMenu.add(fGotoMatchingBracket);
145 // editMenu.add(fContentAssistTip);
148 bars.setGlobalActionHandler(PHPdtActionConstants.CONTENT_ASSIST, fContentAssist);
149 // IToolBarManager toolBarManager = bars.getToolBarManager();
150 // if (toolBarManager != null) {
151 // toolBarManager.add(new Separator());
152 // toolBarManager.add(fTogglePresentation);
156 private void doSetActiveEditor(IEditorPart part) {
157 super.setActiveEditor(part);
159 ITextEditor textEditor = null;
160 if (part instanceof ITextEditor)
161 textEditor = (ITextEditor) part;
163 fContentAssist.setAction(getAction(textEditor, "ContentAssistProposal")); //$NON-NLS-1$
164 // fContentAssistTip.setAction(getAction(editor, "ContentAssistTip")); //$NON-NLS-1$
165 fGotoMatchingBracket.setAction(getAction(textEditor, GotoMatchingBracketAction.GOTO_MATCHING_BRACKET));
167 IActionBars bars = getActionBars();
168 bars.setGlobalActionHandler(PHPdtActionConstants.COMMENT, getAction(textEditor, "Comment"));
169 bars.setGlobalActionHandler(PHPdtActionConstants.UNCOMMENT, getAction(textEditor, "Uncomment"));
170 bars.setGlobalActionHandler(PHPdtActionConstants.FORMAT, getAction(textEditor, "Format"));
172 if (part instanceof PHPEditor) {
173 PHPEditor cuEditor = (PHPEditor) part;
174 ActionGroup group = cuEditor.getActionGroup();
176 group.fillActionBars(bars);
178 // fTogglePresentation.setEditor(editor);
179 // fTogglePresentation.update();
181 parserAction.setEditor(textEditor);
182 parserAction.update();
183 if (SWT.getPlatform().equals("win32") &&
184 textEditor instanceof AbstractTextEditor) {
185 showExternalPreviewAction.setEditor(textEditor);
186 showExternalPreviewAction.update();
187 IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
188 if (store.getBoolean(PHPeclipsePlugin.SHOW_EXTERNAL_PREVIEW_PREF)) {
189 IAction a = ShowExternalPreviewAction.getInstance();
197 * @see IEditorActionBarContributor#setActiveEditor(IEditorPart)
199 public void setActiveEditor(IEditorPart part) {
200 doSetActiveEditor(part);
204 * @see IEditorActionBarContributor#dispose()
206 public void dispose() {
207 doSetActiveEditor(null);