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;
13 import net.sourceforge.phpdt.internal.ui.PHPUiImages;
14 import net.sourceforge.phpdt.ui.IContextMenuConstants;
15 import net.sourceforge.phpdt.ui.actions.PHPdtActionConstants;
17 import org.eclipse.jface.action.IMenuManager;
18 import org.eclipse.ui.IActionBars;
19 import org.eclipse.ui.IEditorPart;
20 import org.eclipse.ui.IWorkbenchActionConstants;
21 import org.eclipse.ui.IWorkbenchPage;
22 import org.eclipse.ui.actions.RetargetAction;
23 import org.eclipse.ui.editors.text.EncodingActionGroup;
24 import org.eclipse.ui.ide.IDEActionFactory;
25 import org.eclipse.ui.texteditor.ITextEditor;
26 import org.eclipse.ui.texteditor.RetargetTextEditorAction;
28 public class BasicEditorActionContributor extends
29 BasicJavaEditorActionContributor {
31 protected RetargetAction fRetargetContentAssist;
33 protected RetargetTextEditorAction fContentAssist;
35 // protected RetargetTextEditorAction fContextInformation;
36 // protected RetargetTextEditorAction fCorrectionAssist;
37 private EncodingActionGroup fEncodingActionGroup;
39 public BasicEditorActionContributor() {
41 fRetargetContentAssist = new RetargetAction(
42 PHPdtActionConstants.CONTENT_ASSIST, PHPEditorMessages
43 .getString("ContentAssistProposal.label")); //$NON-NLS-1$
44 fRetargetContentAssist
45 .setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
46 markAsPartListener(fRetargetContentAssist);
48 fContentAssist = new RetargetTextEditorAction(PHPEditorMessages
49 .getResourceBundle(), "ContentAssistProposal."); //$NON-NLS-1$
51 .setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
52 fContentAssist.setImageDescriptor(PHPUiImages.DESC_CLCL_CODE_ASSIST);
54 .setDisabledImageDescriptor(PHPUiImages.DESC_DLCL_CODE_ASSIST);
56 // fContextInformation= new
57 // RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(),
58 // "ContentAssistContextInformation."); //$NON-NLS-1$
59 // fContextInformation.setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_CONTEXT_INFORMATION);
61 // fCorrectionAssist= new
62 // RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(),
63 // "CorrectionAssistProposal."); //$NON-NLS-1$
64 // fCorrectionAssist.setActionDefinitionId(PHPEditorActionDefinitionIds.CORRECTION_ASSIST_PROPOSALS);
67 fEncodingActionGroup = new EncodingActionGroup();
71 * @see EditorActionBarContributor#contributeToMenu(IMenuManager)
73 public void contributeToMenu(IMenuManager menu) {
75 super.contributeToMenu(menu);
77 IMenuManager editMenu = menu
78 .findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
79 if (editMenu != null) {
80 editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE,
81 fRetargetContentAssist);
82 // editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE,
83 // fCorrectionAssist);
84 // editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE,
85 // fContextInformation);
90 * @see IEditorActionBarContributor#setActiveEditor(IEditorPart)
92 public void setActiveEditor(IEditorPart part) {
93 super.setActiveEditor(part);
95 ITextEditor textEditor = null;
96 if (part instanceof ITextEditor)
97 textEditor = (ITextEditor) part;
100 .setAction(getAction(textEditor, "ContentAssistProposal")); //$NON-NLS-1$
101 // fContextInformation.setAction(getAction(textEditor,
102 // "ContentAssistContextInformation")); //$NON-NLS-1$
103 // fCorrectionAssist.setAction(getAction(textEditor,
104 // "CorrectionAssistProposal")); //$NON-NLS-1$
106 IActionBars actionBars = getActionBars();
107 actionBars.setGlobalActionHandler(PHPdtActionConstants.SHIFT_RIGHT,
108 getAction(textEditor, "ShiftRight")); //$NON-NLS-1$
109 actionBars.setGlobalActionHandler(PHPdtActionConstants.SHIFT_LEFT,
110 getAction(textEditor, "ShiftLeft")); //$NON-NLS-1$
112 actionBars.setGlobalActionHandler(IDEActionFactory.ADD_TASK.getId(),
113 getAction(textEditor, IDEActionFactory.ADD_TASK.getId())); //$NON-NLS-1$
114 actionBars.setGlobalActionHandler(IDEActionFactory.BOOKMARK.getId(),
115 getAction(textEditor, IDEActionFactory.BOOKMARK.getId())); //$NON-NLS-1$
117 // character encoding
118 fEncodingActionGroup.retarget(textEditor);
122 * @see IEditorActionBarContributor#init(IActionBars, IWorkbenchPage)
124 public void init(IActionBars bars, IWorkbenchPage page) {
125 super.init(bars, page);
127 // register actions that have a dynamic editor.
128 bars.setGlobalActionHandler(PHPdtActionConstants.CONTENT_ASSIST,
130 // character encoding
131 fEncodingActionGroup.fillActionBars(bars);