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.ITextEditor;
38 import org.eclipse.ui.texteditor.RetargetTextEditorAction;
40 * Contributes interesting PHP actions to the desktop's Edit menu and the
43 public class PHPActionContributor_DeleteIt extends BasicJavaEditorActionContributor {
44 // protected RetargetTextEditorAction fContentAssistTip;
45 // protected TextEditorAction fTogglePresentation;
46 protected RetargetAction fRetargetContentAssist;
47 protected RetargetTextEditorAction fContentAssist;
48 protected RetargetTextEditorAction fContextInformation;
49 private RetargetTextEditorAction fGotoMatchingBracket;
50 private List fRetargetToolbarActions = new ArrayList();
51 // private List fPartListeners = new ArrayList();
52 protected PHPParserAction fParserAction;
53 protected ShowExternalPreviewAction fShowExternalPreviewAction;
54 private EncodingActionGroup fEncodingActionGroup;
56 * Default constructor.
58 public PHPActionContributor_DeleteIt() {
60 ResourceBundle b = PHPEditorMessages.getResourceBundle();
62 // fRetargetContentAssist = new RetargetAction(
63 // PHPdtActionConstants.CONTENT_ASSIST, PHPEditorMessages
64 // .getString("ContentAssistProposal.label")); //$NON-NLS-1$
65 // fRetargetContentAssist
66 // .setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
67 // markAsPartListener(fRetargetContentAssist);
69 // fContentAssist = new RetargetTextEditorAction(b, "ContentAssistProposal."); //$NON-NLS-1$
71 // .setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
73 fRetargetContentAssist= new RetargetAction(PHPdtActionConstants.CONTENT_ASSIST, PHPEditorMessages.getString("ContentAssistProposal.label")); //$NON-NLS-1$
74 fRetargetContentAssist.setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
75 markAsPartListener(fRetargetContentAssist);
77 fContentAssist= new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "ContentAssistProposal."); //$NON-NLS-1$
78 fContentAssist.setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
79 fContentAssist.setImageDescriptor(PHPUiImages.DESC_CLCL_CODE_ASSIST);
80 fContentAssist.setDisabledImageDescriptor(PHPUiImages.DESC_DLCL_CODE_ASSIST);
82 fContextInformation= new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "ContentAssistContextInformation."); //$NON-NLS-1$
83 fContextInformation.setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_CONTEXT_INFORMATION);
85 // fCorrectionAssist= new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "CorrectionAssistProposal."); //$NON-NLS-1$
86 // fCorrectionAssist.setActionDefinitionId(PHPEditorActionDefinitionIds.CORRECTION_ASSIST_PROPOSALS);
89 fEncodingActionGroup= new EncodingActionGroup();
91 fParserAction = PHPParserAction.getInstance();
92 fShowExternalPreviewAction = ShowExternalPreviewAction.getInstance();
96 * @see EditorActionBarContributor#contributeToMenu(IMenuManager)
98 // public void contributeToMenu(IMenuManager menu) {
99 // super.contributeToMenu(menu);
100 // IMenuManager editMenu=
101 // menu.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
102 // if (editMenu != null) {
103 // MenuManager structureSelection= new
104 // MenuManager(JavaEditorMessages.getString("ExpandSelectionMenu.label"));
106 // structureSelection.add(fStructureSelectEnclosingAction);
107 // structureSelection.add(fStructureSelectNextAction);
108 // structureSelection.add(fStructureSelectPreviousAction);
109 // structureSelection.add(fStructureSelectHistoryAction);
110 // editMenu.appendToGroup(IContextMenuConstants.GROUP_OPEN,
111 // structureSelection);
112 // editMenu.appendToGroup(IContextMenuConstants.GROUP_OPEN,
113 // fGotoPreviousMemberAction);
114 // editMenu.appendToGroup(IContextMenuConstants.GROUP_OPEN,
115 // fGotoNextMemberAction);
116 // editMenu.appendToGroup(IContextMenuConstants.GROUP_OPEN,
117 // fGotoMatchingBracket);
118 // editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE,
123 * @see EditorActionBarContributor#contributeToMenu(IMenuManager)
125 // public void contributeToMenu(IMenuManager menu) {
127 // super.contributeToMenu(menu);
129 // IMenuManager editMenu=
130 // menu.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
131 // if (editMenu != null) {
132 // editMenu.add(new Separator(IContextMenuConstants.GROUP_OPEN));
133 // editMenu.add(new Separator(IContextMenuConstants.GROUP_GENERATE));
135 // editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE,
136 // fRetargetContentAssist);
140 * @see org.eclipse.ui.part.EditorActionBarContributor#contributeToMenu(org.eclipse.jface.action.IMenuManager)
142 public void contributeToMenu(IMenuManager menu) {
143 super.contributeToMenu(menu);
145 IMenuManager editMenu= menu.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
146 if (editMenu != null) {
147 editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE, fRetargetContentAssist);
148 // editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE, fCorrectionAssist);
149 editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE, fContextInformation);
153 // * @see EditorActionBarContributor#contributeToToolBar(IToolBarManager)
155 // public void contributeToToolBar(IToolBarManager tbm) {
156 // tbm.add(new Separator());
157 // Iterator e = fRetargetToolbarActions.iterator();
158 // while (e.hasNext())
159 // tbm.add((IAction) e.next());
162 * @see IEditorActionBarContributor#init(IActionBars, IWorkbenchPage)
164 // public void init(IActionBars bars, IWorkbenchPage page) {
165 // Iterator e = fPartListeners.iterator();
166 // while (e.hasNext())
167 // page.addPartListener((RetargetAction) e.next());
168 // // character encoding
169 // fEncodingActionGroup.fillActionBars(bars);
170 // super.init(bars, page);
174 * @see IEditorActionBarContributor#init(IActionBars, IWorkbenchPage)
176 public void init(IActionBars bars, IWorkbenchPage page) {
177 super.init(bars, page);
179 // register actions that have a dynamic editor.
180 bars.setGlobalActionHandler(PHPdtActionConstants.CONTENT_ASSIST, fContentAssist);
181 // character encoding
182 fEncodingActionGroup.fillActionBars(bars);
185 // * @see IEditorActionBarContributor#init(IActionBars)
187 // public void init(IActionBars bars) {
189 // IMenuManager menuManager = bars.getMenuManager();
190 // IMenuManager editMenu = menuManager
191 // .findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
192 // if (editMenu != null) {
193 // editMenu.add(new Separator());
194 // editMenu.add(fContentAssist);
195 // // editMenu.add(fGotoMatchingBracket);
196 // // editMenu.add(fContentAssistTip);
198 // bars.setGlobalActionHandler(PHPdtActionConstants.CONTENT_ASSIST,
200 // // IToolBarManager toolBarManager = bars.getToolBarManager();
201 // // if (toolBarManager != null) {
202 // // toolBarManager.add(new Separator());
203 // // toolBarManager.add(fTogglePresentation);
209 * @see IEditorActionBarContributor#setActiveEditor(IEditorPart)
211 public void setActiveEditor(IEditorPart part) {
212 super.setActiveEditor(part);
213 IActionBars bars = getActionBars();
214 IStatusLineManager manager = bars.getStatusLineManager();
215 manager.setMessage(null);
216 manager.setErrorMessage(null);
218 ITextEditor textEditor = null;
219 if (part instanceof ITextEditor)
220 textEditor = (ITextEditor) part;
222 fContentAssist.setAction(getAction(textEditor, "ContentAssistProposal")); //$NON-NLS-1$
223 fContextInformation.setAction(getAction(textEditor, "ContentAssistContextInformation")); //$NON-NLS-1$
224 // fCorrectionAssist.setAction(getAction(textEditor, "CorrectionAssistProposal")); //$NON-NLS-1$
226 IActionBars actionBars= getActionBars();
227 actionBars.setGlobalActionHandler(PHPdtActionConstants.SHIFT_RIGHT, getAction(textEditor, "ShiftRight")); //$NON-NLS-1$
228 actionBars.setGlobalActionHandler(PHPdtActionConstants.SHIFT_LEFT, getAction(textEditor, "ShiftLeft")); //$NON-NLS-1$
230 actionBars.setGlobalActionHandler(IDEActionFactory.ADD_TASK.getId(), getAction(textEditor, IDEActionFactory.ADD_TASK.getId())); //$NON-NLS-1$
231 actionBars.setGlobalActionHandler(IDEActionFactory.BOOKMARK.getId(), getAction(textEditor, IDEActionFactory.BOOKMARK.getId())); //$NON-NLS-1$
233 // character encoding
234 fEncodingActionGroup.retarget(textEditor);
236 if (textEditor != null) {
238 IEditorInput editorInput = textEditor.getEditorInput();
239 if (editorInput instanceof IFileEditorInput) {
240 file = ((IFileEditorInput) editorInput).getFile();
242 PHPeclipsePlugin.getDefault().setLastEditorFile(file);
243 fParserAction.setEditor(textEditor);
244 fParserAction.update();
245 if (textEditor instanceof AbstractTextEditor) {
246 fShowExternalPreviewAction.setEditor(textEditor);
247 fShowExternalPreviewAction.update();
248 IAction a = ShowExternalPreviewAction.getInstance();