1f542a705529ed4148ee20dc09263cbd8bc0dc27
[phpeclipse.git] / net.sourceforge.phpeclipse.ui / src / net / sourceforge / phpeclipse / phpeditor / BasicEditorActionContributor.java
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
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpeclipse.phpeditor;
12
13 import net.sourceforge.phpdt.internal.ui.PHPUiImages;
14 import net.sourceforge.phpdt.ui.IContextMenuConstants;
15 import net.sourceforge.phpdt.ui.actions.PHPdtActionConstants;
16
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;
27
28 public class BasicEditorActionContributor extends
29                 BasicJavaEditorActionContributor {
30
31         protected RetargetAction fRetargetContentAssist;
32
33         protected RetargetTextEditorAction fContentAssist;
34
35         // protected RetargetTextEditorAction fContextInformation;
36         // protected RetargetTextEditorAction fCorrectionAssist;
37         private EncodingActionGroup fEncodingActionGroup;
38
39         public BasicEditorActionContributor() {
40
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);
47
48                 fContentAssist = new RetargetTextEditorAction(PHPEditorMessages
49                                 .getResourceBundle(), "ContentAssistProposal."); //$NON-NLS-1$
50                 fContentAssist
51                                 .setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
52                 fContentAssist.setImageDescriptor(PHPUiImages.DESC_CLCL_CODE_ASSIST);
53                 fContentAssist
54                                 .setDisabledImageDescriptor(PHPUiImages.DESC_DLCL_CODE_ASSIST);
55
56                 // fContextInformation= new
57                 // RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(),
58                 // "ContentAssistContextInformation."); //$NON-NLS-1$
59                 // fContextInformation.setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_CONTEXT_INFORMATION);
60
61                 // fCorrectionAssist= new
62                 // RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(),
63                 // "CorrectionAssistProposal."); //$NON-NLS-1$
64                 // fCorrectionAssist.setActionDefinitionId(PHPEditorActionDefinitionIds.CORRECTION_ASSIST_PROPOSALS);
65
66                 // character encoding
67                 fEncodingActionGroup = new EncodingActionGroup();
68         }
69
70         /*
71          * @see EditorActionBarContributor#contributeToMenu(IMenuManager)
72          */
73         public void contributeToMenu(IMenuManager menu) {
74
75                 super.contributeToMenu(menu);
76
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);
86                 }
87         }
88
89         /*
90          * @see IEditorActionBarContributor#setActiveEditor(IEditorPart)
91          */
92         public void setActiveEditor(IEditorPart part) {
93                 super.setActiveEditor(part);
94
95                 ITextEditor textEditor = null;
96                 if (part instanceof ITextEditor)
97                         textEditor = (ITextEditor) part;
98
99                 fContentAssist
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$
105
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$
111
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$
116
117                 // character encoding
118                 fEncodingActionGroup.retarget(textEditor);
119         }
120
121         /*
122          * @see IEditorActionBarContributor#init(IActionBars, IWorkbenchPage)
123          */
124         public void init(IActionBars bars, IWorkbenchPage page) {
125                 super.init(bars, page);
126
127                 // register actions that have a dynamic editor.
128                 bars.setGlobalActionHandler(PHPdtActionConstants.CONTENT_ASSIST,
129                                 fContentAssist);
130                 // character encoding
131                 fEncodingActionGroup.fillActionBars(bars);
132         }
133 }