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 net.sourceforge.phpdt.ui.actions.PHPdtActionConstants;
17 import org.eclipse.jface.action.IMenuManager;
18 import org.eclipse.jface.action.Separator;
19 import org.eclipse.ui.IActionBars;
20 import org.eclipse.ui.IEditorPart;
21 import org.eclipse.ui.IWorkbenchActionConstants;
22 import org.eclipse.ui.actions.ActionGroup;
23 import org.eclipse.ui.texteditor.BasicTextEditorActionContributor;
24 import org.eclipse.ui.texteditor.ITextEditor;
25 import org.eclipse.ui.texteditor.RetargetTextEditorAction;
28 * Contributes interesting PHP actions to the desktop's Edit menu and the toolbar.
30 public class PHPActionContributor extends BasicTextEditorActionContributor {
32 protected RetargetTextEditorAction fContentAssistProposal;
33 // protected RetargetTextEditorAction fContentAssistTip;
34 // protected TextEditorAction fTogglePresentation;
35 protected PHPParserAction parserAction;
38 * Default constructor.
40 public PHPActionContributor() {
42 fContentAssistProposal = new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "ContentAssistProposal."); //$NON-NLS-1$
43 // fContentAssistTip = new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "ContentAssistTip."); //$NON-NLS-1$
44 // fTogglePresentation = new PresentationAction();
45 parserAction = PHPParserAction.getInstance();
49 * @see IEditorActionBarContributor#init(IActionBars)
51 public void init(IActionBars bars) {
54 IMenuManager menuManager = bars.getMenuManager();
55 IMenuManager editMenu = menuManager.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
56 if (editMenu != null) {
57 editMenu.add(new Separator());
58 editMenu.add(fContentAssistProposal);
59 // editMenu.add(fContentAssistTip);
62 // IToolBarManager toolBarManager = bars.getToolBarManager();
63 // if (toolBarManager != null) {
64 // toolBarManager.add(new Separator());
65 // toolBarManager.add(fTogglePresentation);
69 private void doSetActiveEditor(IEditorPart part) {
70 super.setActiveEditor(part);
72 ITextEditor textEditor = null;
73 if (part instanceof ITextEditor)
74 textEditor = (ITextEditor) part;
76 fContentAssistProposal.setAction(getAction(textEditor, "ContentAssistProposal")); //$NON-NLS-1$
77 // fContentAssistTip.setAction(getAction(editor, "ContentAssistTip")); //$NON-NLS-1$
79 IActionBars bars = getActionBars();
80 bars.setGlobalActionHandler(PHPdtActionConstants.COMMENT, getAction(textEditor, "Comment"));
81 bars.setGlobalActionHandler(PHPdtActionConstants.UNCOMMENT, getAction(textEditor, "Uncomment"));
83 if (part instanceof PHPEditor) {
84 PHPEditor cuEditor= (PHPEditor)part;
85 ActionGroup group= cuEditor.getActionGroup();
87 group.fillActionBars(bars);
89 // fTogglePresentation.setEditor(editor);
90 // fTogglePresentation.update();
92 parserAction.setEditor(textEditor);
93 parserAction.update();
97 * @see IEditorActionBarContributor#setActiveEditor(IEditorPart)
99 public void setActiveEditor(IEditorPart part) {
100 doSetActiveEditor(part);
104 * @see IEditorActionBarContributor#dispose()
106 public void dispose() {
107 doSetActiveEditor(null);