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.IContextMenuConstants;
16 import net.sourceforge.phpdt.ui.actions.PHPdtActionConstants;
18 import org.eclipse.jface.action.IMenuManager;
19 import org.eclipse.jface.action.Separator;
20 import org.eclipse.ui.IActionBars;
21 import org.eclipse.ui.IEditorPart;
22 import org.eclipse.ui.IWorkbenchActionConstants;
23 import org.eclipse.ui.actions.ActionGroup;
24 import org.eclipse.ui.actions.RetargetAction;
25 import org.eclipse.ui.texteditor.BasicTextEditorActionContributor;
26 import org.eclipse.ui.texteditor.ITextEditor;
27 import org.eclipse.ui.texteditor.RetargetTextEditorAction;
30 * Contributes interesting PHP actions to the desktop's Edit menu and the toolbar.
32 public class PHPActionContributor extends BasicTextEditorActionContributor {
34 // protected RetargetTextEditorAction fContentAssistTip;
35 // protected TextEditorAction fTogglePresentation;
36 protected RetargetAction fRetargetContentAssist;
38 protected RetargetTextEditorAction fContentAssist;
40 protected PHPParserAction parserAction;
43 * Default constructor.
45 public PHPActionContributor() {
48 fRetargetContentAssist= new RetargetAction(PHPdtActionConstants.CONTENT_ASSIST, PHPEditorMessages.getString("ContentAssistProposal.label")); //$NON-NLS-1$
49 fRetargetContentAssist.setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
51 fContentAssist= new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "ContentAssistProposal."); //$NON-NLS-1$
52 fContentAssist.setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
53 // fContentAssist.setImageDescriptor(JavaPluginImages.DESC_CLCL_CODE_ASSIST);
54 // fContentAssist.setDisabledImageDescriptor(JavaPluginImages.DESC_DLCL_CODE_ASSIST);
57 // fContentAssist = new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "ContentAssistProposal."); //$NON-NLS-1$
58 // fContentAssistTip = new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "ContentAssistTip."); //$NON-NLS-1$
59 // fTogglePresentation = new PresentationAction();
62 parserAction = PHPParserAction.getInstance();
66 * @see EditorActionBarContributor#contributeToMenu(IMenuManager)
68 // public void contributeToMenu(IMenuManager menu) {
70 // super.contributeToMenu(menu);
72 // IMenuManager editMenu= menu.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
73 // if (editMenu != null) {
74 // editMenu.add(new Separator(IContextMenuConstants.GROUP_OPEN));
75 // editMenu.add(new Separator(IContextMenuConstants.GROUP_GENERATE));
77 // editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE, fRetargetContentAssist);
82 * @see IEditorActionBarContributor#init(IActionBars)
84 public void init(IActionBars bars) {
87 IMenuManager menuManager = bars.getMenuManager();
88 IMenuManager editMenu = menuManager.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
89 if (editMenu != null) {
90 editMenu.add(new Separator());
91 editMenu.add(fContentAssist);
92 // editMenu.add(fContentAssistTip);
95 bars.setGlobalActionHandler(PHPdtActionConstants.CONTENT_ASSIST, fContentAssist);
96 // IToolBarManager toolBarManager = bars.getToolBarManager();
97 // if (toolBarManager != null) {
98 // toolBarManager.add(new Separator());
99 // toolBarManager.add(fTogglePresentation);
103 private void doSetActiveEditor(IEditorPart part) {
104 super.setActiveEditor(part);
106 ITextEditor textEditor = null;
107 if (part instanceof ITextEditor)
108 textEditor = (ITextEditor) part;
110 fContentAssist.setAction(getAction(textEditor, "ContentAssistProposal")); //$NON-NLS-1$
111 // fContentAssistTip.setAction(getAction(editor, "ContentAssistTip")); //$NON-NLS-1$
113 IActionBars bars = getActionBars();
114 bars.setGlobalActionHandler(PHPdtActionConstants.COMMENT, getAction(textEditor, "Comment"));
115 bars.setGlobalActionHandler(PHPdtActionConstants.UNCOMMENT, getAction(textEditor, "Uncomment"));
117 if (part instanceof PHPEditor) {
118 PHPEditor cuEditor= (PHPEditor)part;
119 ActionGroup group= cuEditor.getActionGroup();
121 group.fillActionBars(bars);
123 // fTogglePresentation.setEditor(editor);
124 // fTogglePresentation.update();
126 parserAction.setEditor(textEditor);
127 parserAction.update();
131 * @see IEditorActionBarContributor#setActiveEditor(IEditorPart)
133 public void setActiveEditor(IEditorPart part) {
134 doSetActiveEditor(part);
138 * @see IEditorActionBarContributor#dispose()
140 public void dispose() {
141 doSetActiveEditor(null);