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.core.resources.IFile;
25 import org.eclipse.jface.action.IAction;
26 import org.eclipse.jface.action.IMenuManager;
27 import org.eclipse.jface.action.IToolBarManager;
28 import org.eclipse.jface.action.Separator;
29 import org.eclipse.jface.preference.IPreferenceStore;
30 import org.eclipse.swt.SWT;
31 import org.eclipse.ui.IActionBars;
32 import org.eclipse.ui.IEditorInput;
33 import org.eclipse.ui.IEditorPart;
34 import org.eclipse.ui.IFileEditorInput;
35 import org.eclipse.ui.IWorkbenchActionConstants;
36 import org.eclipse.ui.actions.ActionGroup;
37 import org.eclipse.ui.actions.RetargetAction;
38 import org.eclipse.ui.texteditor.AbstractTextEditor;
39 import org.eclipse.ui.texteditor.BasicTextEditorActionContributor;
40 import org.eclipse.ui.texteditor.ITextEditor;
41 import org.eclipse.ui.texteditor.RetargetTextEditorAction;
44 * Contributes interesting PHP actions to the desktop's Edit menu and the toolbar.
46 public class PHPActionContributor extends BasicTextEditorActionContributor {
48 // protected RetargetTextEditorAction fContentAssistTip;
49 // protected TextEditorAction fTogglePresentation;
50 protected RetargetAction fRetargetContentAssist;
52 protected RetargetTextEditorAction fContentAssist;
53 private RetargetTextEditorAction fGotoMatchingBracket;
54 private List fRetargetToolbarActions = new ArrayList();
56 protected PHPParserAction fParserAction;
57 protected ShowExternalPreviewAction fShowExternalPreviewAction;
60 * Default constructor.
62 public PHPActionContributor() {
65 ResourceBundle b = PHPEditorMessages.getResourceBundle();
67 fRetargetContentAssist = new RetargetAction(PHPdtActionConstants.CONTENT_ASSIST, PHPEditorMessages.getString("ContentAssistProposal.label")); //$NON-NLS-1$
68 fRetargetContentAssist.setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
70 fContentAssist = new RetargetTextEditorAction(b, "ContentAssistProposal."); //$NON-NLS-1$
71 fContentAssist.setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
73 fGotoMatchingBracket = new RetargetTextEditorAction(b, "GotoMatchingBracket."); //$NON-NLS-1$
74 fGotoMatchingBracket.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_MATCHING_BRACKET);
76 // fContentAssist.setImageDescriptor(JavaPluginImages.DESC_CLCL_CODE_ASSIST);
77 // fContentAssist.setDisabledImageDescriptor(JavaPluginImages.DESC_DLCL_CODE_ASSIST);
79 // fContentAssist = new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "ContentAssistProposal."); //$NON-NLS-1$
80 // fContentAssistTip = new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "ContentAssistTip."); //$NON-NLS-1$
81 // fTogglePresentation = new PresentationAction();
83 fParserAction = PHPParserAction.getInstance();
85 if (SWT.getPlatform().equals("win32")) {
86 fShowExternalPreviewAction = ShowExternalPreviewAction.getInstance();
91 * @see EditorActionBarContributor#contributeToMenu(IMenuManager)
93 // public void contributeToMenu(IMenuManager menu) {
94 // super.contributeToMenu(menu);
95 // IMenuManager editMenu= menu.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
96 // if (editMenu != null) {
97 // MenuManager structureSelection= new MenuManager(JavaEditorMessages.getString("ExpandSelectionMenu.label")); //$NON-NLS-1$
98 // structureSelection.add(fStructureSelectEnclosingAction);
99 // structureSelection.add(fStructureSelectNextAction);
100 // structureSelection.add(fStructureSelectPreviousAction);
101 // structureSelection.add(fStructureSelectHistoryAction);
102 // editMenu.appendToGroup(IContextMenuConstants.GROUP_OPEN, structureSelection);
103 // editMenu.appendToGroup(IContextMenuConstants.GROUP_OPEN, fGotoPreviousMemberAction);
104 // editMenu.appendToGroup(IContextMenuConstants.GROUP_OPEN, fGotoNextMemberAction);
105 // editMenu.appendToGroup(IContextMenuConstants.GROUP_OPEN, fGotoMatchingBracket);
107 // editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE, fShowOutline);
111 * @see EditorActionBarContributor#contributeToMenu(IMenuManager)
113 // public void contributeToMenu(IMenuManager menu) {
115 // super.contributeToMenu(menu);
117 // IMenuManager editMenu= menu.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
118 // if (editMenu != null) {
119 // editMenu.add(new Separator(IContextMenuConstants.GROUP_OPEN));
120 // editMenu.add(new Separator(IContextMenuConstants.GROUP_GENERATE));
122 // editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE, fRetargetContentAssist);
127 * @see EditorActionBarContributor#contributeToToolBar(IToolBarManager)
129 public void contributeToToolBar(IToolBarManager tbm) {
130 tbm.add(new Separator());
131 Iterator e = fRetargetToolbarActions.iterator();
133 tbm.add((IAction) e.next());
137 * @see IEditorActionBarContributor#init(IActionBars)
139 public void init(IActionBars bars) {
142 IMenuManager menuManager = bars.getMenuManager();
143 IMenuManager editMenu = menuManager.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
144 if (editMenu != null) {
145 editMenu.add(new Separator());
146 editMenu.add(fContentAssist);
147 editMenu.add(fGotoMatchingBracket);
149 // editMenu.add(fContentAssistTip);
152 bars.setGlobalActionHandler(PHPdtActionConstants.CONTENT_ASSIST, fContentAssist);
153 // IToolBarManager toolBarManager = bars.getToolBarManager();
154 // if (toolBarManager != null) {
155 // toolBarManager.add(new Separator());
156 // toolBarManager.add(fTogglePresentation);
160 private void doSetActiveEditor(IEditorPart part) {
161 super.setActiveEditor(part);
163 ITextEditor textEditor = null;
164 if (part instanceof ITextEditor)
165 textEditor = (ITextEditor) part;
167 fContentAssist.setAction(getAction(textEditor, "ContentAssistProposal")); //$NON-NLS-1$
168 // fContentAssistTip.setAction(getAction(editor, "ContentAssistTip")); //$NON-NLS-1$
169 fGotoMatchingBracket.setAction(getAction(textEditor, GotoMatchingBracketAction.GOTO_MATCHING_BRACKET));
171 IActionBars bars = getActionBars();
172 bars.setGlobalActionHandler(PHPdtActionConstants.COMMENT, getAction(textEditor, "Comment"));
173 bars.setGlobalActionHandler(PHPdtActionConstants.UNCOMMENT, getAction(textEditor, "Uncomment"));
174 bars.setGlobalActionHandler(PHPdtActionConstants.FORMAT, getAction(textEditor, "Format"));
176 if (part instanceof PHPEditor) {
177 PHPEditor cuEditor = (PHPEditor) part;
178 ActionGroup group = cuEditor.getActionGroup();
180 group.fillActionBars(bars);
182 // fTogglePresentation.setEditor(editor);
183 // fTogglePresentation.update();
186 IEditorInput editorInput = textEditor.getEditorInput();
188 if (editorInput instanceof IFileEditorInput) {
189 file = ((IFileEditorInput) editorInput).getFile();
192 PHPeclipsePlugin.getDefault().setLastEditorFile(file);
193 fParserAction.setEditor(textEditor);
194 fParserAction.update();
195 if (SWT.getPlatform().equals("win32") && textEditor instanceof AbstractTextEditor) {
196 fShowExternalPreviewAction.setEditor(textEditor);
197 fShowExternalPreviewAction.update();
198 IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
199 if (store.getBoolean(PHPeclipsePlugin.SHOW_EXTERNAL_PREVIEW_PREF)) {
200 IAction a = ShowExternalPreviewAction.getInstance();
208 * @see IEditorActionBarContributor#setActiveEditor(IEditorPart)
210 public void setActiveEditor(IEditorPart part) {
211 doSetActiveEditor(part);
215 * @see IEditorActionBarContributor#dispose()
217 public void dispose() {
218 doSetActiveEditor(null);