1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpeclipse.phpeditor;
14 import net.sourceforge.phpdt.internal.ui.PHPUiImages;
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.ui.IActionBars;
20 import org.eclipse.ui.IEditorPart;
21 import org.eclipse.ui.IWorkbenchActionConstants;
22 import org.eclipse.ui.IWorkbenchPage;
23 import org.eclipse.ui.actions.RetargetAction;
24 import org.eclipse.ui.editors.text.EncodingActionGroup;
25 import org.eclipse.ui.ide.IDEActionFactory;
26 import org.eclipse.ui.texteditor.ITextEditor;
27 import org.eclipse.ui.texteditor.RetargetTextEditorAction;
30 public class BasicEditorActionContributor extends BasicJavaEditorActionContributor {
32 protected RetargetAction fRetargetContentAssist;
33 protected RetargetTextEditorAction fContentAssist;
34 protected RetargetTextEditorAction fContextInformation;
35 // protected RetargetTextEditorAction fCorrectionAssist;
36 private EncodingActionGroup fEncodingActionGroup;
39 public BasicEditorActionContributor() {
41 fRetargetContentAssist= new RetargetAction(PHPdtActionConstants.CONTENT_ASSIST, PHPEditorMessages.getString("ContentAssistProposal.label")); //$NON-NLS-1$
42 fRetargetContentAssist.setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
43 markAsPartListener(fRetargetContentAssist);
45 fContentAssist= new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "ContentAssistProposal."); //$NON-NLS-1$
46 fContentAssist.setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
47 fContentAssist.setImageDescriptor(PHPUiImages.DESC_CLCL_CODE_ASSIST);
48 fContentAssist.setDisabledImageDescriptor(PHPUiImages.DESC_DLCL_CODE_ASSIST);
50 fContextInformation= new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "ContentAssistContextInformation."); //$NON-NLS-1$
51 fContextInformation.setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_CONTEXT_INFORMATION);
53 // fCorrectionAssist= new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "CorrectionAssistProposal."); //$NON-NLS-1$
54 // fCorrectionAssist.setActionDefinitionId(PHPEditorActionDefinitionIds.CORRECTION_ASSIST_PROPOSALS);
57 fEncodingActionGroup= new EncodingActionGroup();
61 * @see EditorActionBarContributor#contributeToMenu(IMenuManager)
63 public void contributeToMenu(IMenuManager menu) {
65 super.contributeToMenu(menu);
67 IMenuManager editMenu= menu.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
68 if (editMenu != null) {
69 editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE, fRetargetContentAssist);
70 // editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE, fCorrectionAssist);
71 editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE, fContextInformation);
76 * @see IEditorActionBarContributor#setActiveEditor(IEditorPart)
78 public void setActiveEditor(IEditorPart part) {
79 super.setActiveEditor(part);
81 ITextEditor textEditor= null;
82 if (part instanceof ITextEditor)
83 textEditor= (ITextEditor) part;
85 fContentAssist.setAction(getAction(textEditor, "ContentAssistProposal")); //$NON-NLS-1$
86 fContextInformation.setAction(getAction(textEditor, "ContentAssistContextInformation")); //$NON-NLS-1$
87 // fCorrectionAssist.setAction(getAction(textEditor, "CorrectionAssistProposal")); //$NON-NLS-1$
89 IActionBars actionBars= getActionBars();
90 actionBars.setGlobalActionHandler(PHPdtActionConstants.SHIFT_RIGHT, getAction(textEditor, "ShiftRight")); //$NON-NLS-1$
91 actionBars.setGlobalActionHandler(PHPdtActionConstants.SHIFT_LEFT, getAction(textEditor, "ShiftLeft")); //$NON-NLS-1$
93 actionBars.setGlobalActionHandler(IDEActionFactory.ADD_TASK.getId(), getAction(textEditor, IDEActionFactory.ADD_TASK.getId())); //$NON-NLS-1$
94 actionBars.setGlobalActionHandler(IDEActionFactory.BOOKMARK.getId(), getAction(textEditor, IDEActionFactory.BOOKMARK.getId())); //$NON-NLS-1$
97 fEncodingActionGroup.retarget(textEditor);
101 * @see IEditorActionBarContributor#init(IActionBars, IWorkbenchPage)
103 public void init(IActionBars bars, IWorkbenchPage page) {
104 super.init(bars, page);
106 // register actions that have a dynamic editor.
107 bars.setGlobalActionHandler(PHPdtActionConstants.CONTENT_ASSIST, fContentAssist);
108 // character encoding
109 fEncodingActionGroup.fillActionBars(bars);