1 package net.sourceforge.phpeclipse.phpeditor;
2 /*******************************************************************************
3 * Copyright (c) 2000, 2002 IBM Corp. and others. All rights reserved. This
4 * program and the accompanying materials are made available under the terms of
5 * the Common Public License v1.0 which accompanies this distribution, and is
6 * available at http://www.eclipse.org/legal/cpl-v10.html
8 * Contributors: IBM Corporation - Initial implementation Klaus Hartlage -
9 * www.eclipseproject.de
10 ******************************************************************************/
11 import java.util.ArrayList;
12 import java.util.Iterator;
13 import java.util.List;
14 import java.util.ResourceBundle;
16 import net.sourceforge.phpdt.internal.ui.PHPUiImages;
17 import net.sourceforge.phpdt.ui.IContextMenuConstants;
18 import net.sourceforge.phpdt.ui.actions.PHPdtActionConstants;
19 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
21 import org.eclipse.core.resources.IFile;
22 import org.eclipse.jface.action.IAction;
23 import org.eclipse.jface.action.IMenuManager;
24 import org.eclipse.jface.action.IStatusLineManager;
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.IEditorInput;
29 import org.eclipse.ui.IEditorPart;
30 import org.eclipse.ui.IFileEditorInput;
31 import org.eclipse.ui.IWorkbenchActionConstants;
32 import org.eclipse.ui.IWorkbenchPage;
33 import org.eclipse.ui.actions.RetargetAction;
34 import org.eclipse.ui.editors.text.EncodingActionGroup;
35 import org.eclipse.ui.ide.IDEActionFactory;
36 import org.eclipse.ui.texteditor.AbstractTextEditor;
37 import org.eclipse.ui.texteditor.BasicTextEditorActionContributor;
38 import org.eclipse.ui.texteditor.ITextEditor;
39 import org.eclipse.ui.texteditor.RetargetTextEditorAction;
41 * Contributes interesting PHP actions to the desktop's Edit menu and the
44 public class PHPActionContributor extends BasicJavaEditorActionContributor {
45 // protected RetargetTextEditorAction fContentAssistTip;
46 // protected TextEditorAction fTogglePresentation;
47 protected RetargetAction fRetargetContentAssist;
48 protected RetargetTextEditorAction fContentAssist;
49 protected RetargetTextEditorAction fContextInformation;
50 private RetargetTextEditorAction fGotoMatchingBracket;
51 private List fRetargetToolbarActions = new ArrayList();
52 // private List fPartListeners = new ArrayList();
53 protected PHPParserAction fParserAction;
54 protected ShowExternalPreviewAction fShowExternalPreviewAction;
55 private EncodingActionGroup fEncodingActionGroup;
57 * Default constructor.
59 public PHPActionContributor() {
61 ResourceBundle b = PHPEditorMessages.getResourceBundle();
63 // fRetargetContentAssist = new RetargetAction(
64 // PHPdtActionConstants.CONTENT_ASSIST, PHPEditorMessages
65 // .getString("ContentAssistProposal.label")); //$NON-NLS-1$
66 // fRetargetContentAssist
67 // .setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
68 // markAsPartListener(fRetargetContentAssist);
70 // fContentAssist = new RetargetTextEditorAction(b, "ContentAssistProposal."); //$NON-NLS-1$
72 // .setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
74 fRetargetContentAssist= new RetargetAction(PHPdtActionConstants.CONTENT_ASSIST, PHPEditorMessages.getString("ContentAssistProposal.label")); //$NON-NLS-1$
75 fRetargetContentAssist.setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
76 markAsPartListener(fRetargetContentAssist);
78 fContentAssist= new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "ContentAssistProposal."); //$NON-NLS-1$
79 fContentAssist.setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
80 fContentAssist.setImageDescriptor(PHPUiImages.DESC_CLCL_CODE_ASSIST);
81 fContentAssist.setDisabledImageDescriptor(PHPUiImages.DESC_DLCL_CODE_ASSIST);
83 fContextInformation= new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "ContentAssistContextInformation."); //$NON-NLS-1$
84 fContextInformation.setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_CONTEXT_INFORMATION);
86 // fCorrectionAssist= new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "CorrectionAssistProposal."); //$NON-NLS-1$
87 // fCorrectionAssist.setActionDefinitionId(PHPEditorActionDefinitionIds.CORRECTION_ASSIST_PROPOSALS);
90 fEncodingActionGroup= new EncodingActionGroup();
92 fParserAction = PHPParserAction.getInstance();
93 fShowExternalPreviewAction = ShowExternalPreviewAction.getInstance();
97 * @see EditorActionBarContributor#contributeToMenu(IMenuManager)
99 // public void contributeToMenu(IMenuManager menu) {
100 // super.contributeToMenu(menu);
101 // IMenuManager editMenu=
102 // menu.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
103 // if (editMenu != null) {
104 // MenuManager structureSelection= new
105 // MenuManager(JavaEditorMessages.getString("ExpandSelectionMenu.label"));
107 // structureSelection.add(fStructureSelectEnclosingAction);
108 // structureSelection.add(fStructureSelectNextAction);
109 // structureSelection.add(fStructureSelectPreviousAction);
110 // structureSelection.add(fStructureSelectHistoryAction);
111 // editMenu.appendToGroup(IContextMenuConstants.GROUP_OPEN,
112 // structureSelection);
113 // editMenu.appendToGroup(IContextMenuConstants.GROUP_OPEN,
114 // fGotoPreviousMemberAction);
115 // editMenu.appendToGroup(IContextMenuConstants.GROUP_OPEN,
116 // fGotoNextMemberAction);
117 // editMenu.appendToGroup(IContextMenuConstants.GROUP_OPEN,
118 // fGotoMatchingBracket);
119 // editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE,
124 * @see EditorActionBarContributor#contributeToMenu(IMenuManager)
126 // public void contributeToMenu(IMenuManager menu) {
128 // super.contributeToMenu(menu);
130 // IMenuManager editMenu=
131 // menu.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
132 // if (editMenu != null) {
133 // editMenu.add(new Separator(IContextMenuConstants.GROUP_OPEN));
134 // editMenu.add(new Separator(IContextMenuConstants.GROUP_GENERATE));
136 // editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE,
137 // fRetargetContentAssist);
141 * @see org.eclipse.ui.part.EditorActionBarContributor#contributeToMenu(org.eclipse.jface.action.IMenuManager)
143 public void contributeToMenu(IMenuManager menu) {
144 super.contributeToMenu(menu);
146 IMenuManager editMenu= menu.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
147 if (editMenu != null) {
148 editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE, fRetargetContentAssist);
149 // editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE, fCorrectionAssist);
150 editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE, fContextInformation);
154 // * @see EditorActionBarContributor#contributeToToolBar(IToolBarManager)
156 // public void contributeToToolBar(IToolBarManager tbm) {
157 // tbm.add(new Separator());
158 // Iterator e = fRetargetToolbarActions.iterator();
159 // while (e.hasNext())
160 // tbm.add((IAction) e.next());
163 * @see IEditorActionBarContributor#init(IActionBars, IWorkbenchPage)
165 // public void init(IActionBars bars, IWorkbenchPage page) {
166 // Iterator e = fPartListeners.iterator();
167 // while (e.hasNext())
168 // page.addPartListener((RetargetAction) e.next());
169 // // character encoding
170 // fEncodingActionGroup.fillActionBars(bars);
171 // super.init(bars, page);
175 * @see IEditorActionBarContributor#init(IActionBars, IWorkbenchPage)
177 public void init(IActionBars bars, IWorkbenchPage page) {
178 super.init(bars, page);
180 // register actions that have a dynamic editor.
181 bars.setGlobalActionHandler(PHPdtActionConstants.CONTENT_ASSIST, fContentAssist);
182 // character encoding
183 fEncodingActionGroup.fillActionBars(bars);
186 // * @see IEditorActionBarContributor#init(IActionBars)
188 // public void init(IActionBars bars) {
190 // IMenuManager menuManager = bars.getMenuManager();
191 // IMenuManager editMenu = menuManager
192 // .findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
193 // if (editMenu != null) {
194 // editMenu.add(new Separator());
195 // editMenu.add(fContentAssist);
196 // // editMenu.add(fGotoMatchingBracket);
197 // // editMenu.add(fContentAssistTip);
199 // bars.setGlobalActionHandler(PHPdtActionConstants.CONTENT_ASSIST,
201 // // IToolBarManager toolBarManager = bars.getToolBarManager();
202 // // if (toolBarManager != null) {
203 // // toolBarManager.add(new Separator());
204 // // toolBarManager.add(fTogglePresentation);
210 * @see IEditorActionBarContributor#setActiveEditor(IEditorPart)
212 public void setActiveEditor(IEditorPart part) {
213 super.setActiveEditor(part);
214 IActionBars bars = getActionBars();
215 IStatusLineManager manager = bars.getStatusLineManager();
216 manager.setMessage(null);
217 manager.setErrorMessage(null);
219 ITextEditor textEditor = null;
220 if (part instanceof ITextEditor)
221 textEditor = (ITextEditor) part;
223 fContentAssist.setAction(getAction(textEditor, "ContentAssistProposal")); //$NON-NLS-1$
224 fContextInformation.setAction(getAction(textEditor, "ContentAssistContextInformation")); //$NON-NLS-1$
225 // fCorrectionAssist.setAction(getAction(textEditor, "CorrectionAssistProposal")); //$NON-NLS-1$
227 IActionBars actionBars= getActionBars();
228 actionBars.setGlobalActionHandler(PHPdtActionConstants.SHIFT_RIGHT, getAction(textEditor, "ShiftRight")); //$NON-NLS-1$
229 actionBars.setGlobalActionHandler(PHPdtActionConstants.SHIFT_LEFT, getAction(textEditor, "ShiftLeft")); //$NON-NLS-1$
231 actionBars.setGlobalActionHandler(IDEActionFactory.ADD_TASK.getId(), getAction(textEditor, IDEActionFactory.ADD_TASK.getId())); //$NON-NLS-1$
232 actionBars.setGlobalActionHandler(IDEActionFactory.BOOKMARK.getId(), getAction(textEditor, IDEActionFactory.BOOKMARK.getId())); //$NON-NLS-1$
234 // character encoding
235 fEncodingActionGroup.retarget(textEditor);
237 if (textEditor != null) {
239 IEditorInput editorInput = textEditor.getEditorInput();
240 if (editorInput instanceof IFileEditorInput) {
241 file = ((IFileEditorInput) editorInput).getFile();
243 PHPeclipsePlugin.getDefault().setLastEditorFile(file);
244 fParserAction.setEditor(textEditor);
245 fParserAction.update();
246 if (textEditor instanceof AbstractTextEditor) {
247 fShowExternalPreviewAction.setEditor(textEditor);
248 fShowExternalPreviewAction.update();
249 IAction a = ShowExternalPreviewAction.getInstance();