b106a93e4a5aea39a734a892943cb8423cdbcdf4
[phpeclipse.git] / net.sourceforge.phpeclipse / 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
14 import net.sourceforge.phpdt.internal.ui.PHPUiImages;
15 import net.sourceforge.phpdt.ui.IContextMenuConstants;
16 import net.sourceforge.phpdt.ui.actions.PHPdtActionConstants;
17
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;
28
29
30 public class BasicEditorActionContributor extends BasicJavaEditorActionContributor {
31         
32         protected RetargetAction fRetargetContentAssist;
33         protected RetargetTextEditorAction fContentAssist;
34         protected RetargetTextEditorAction fContextInformation;
35 //      protected RetargetTextEditorAction fCorrectionAssist;
36         private EncodingActionGroup fEncodingActionGroup;
37         
38         
39         public BasicEditorActionContributor() {
40                 
41                 fRetargetContentAssist= new RetargetAction(PHPdtActionConstants.CONTENT_ASSIST,  PHPEditorMessages.getString("ContentAssistProposal.label")); //$NON-NLS-1$
42                 fRetargetContentAssist.setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
43                 markAsPartListener(fRetargetContentAssist);
44                 
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);
49                 
50                 fContextInformation= new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "ContentAssistContextInformation."); //$NON-NLS-1$
51                 fContextInformation.setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_CONTEXT_INFORMATION);
52                 
53 //              fCorrectionAssist= new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "CorrectionAssistProposal."); //$NON-NLS-1$
54 //              fCorrectionAssist.setActionDefinitionId(PHPEditorActionDefinitionIds.CORRECTION_ASSIST_PROPOSALS);
55                 
56                 // character encoding
57                 fEncodingActionGroup= new EncodingActionGroup();
58         }
59         
60         /*
61          * @see EditorActionBarContributor#contributeToMenu(IMenuManager)
62          */
63         public void contributeToMenu(IMenuManager menu) {
64                 
65                 super.contributeToMenu(menu);
66                 
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);
72                 }               
73         }
74         
75         /*
76          * @see IEditorActionBarContributor#setActiveEditor(IEditorPart)
77          */
78         public void setActiveEditor(IEditorPart part) {
79                 super.setActiveEditor(part);
80                                 
81                 ITextEditor textEditor= null;
82                 if (part instanceof ITextEditor)
83                         textEditor= (ITextEditor) part;
84                         
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$
88                 
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$
92
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$
95                 
96                 // character encoding
97                 fEncodingActionGroup.retarget(textEditor);
98         }
99         
100         /*
101          * @see IEditorActionBarContributor#init(IActionBars, IWorkbenchPage)
102          */
103         public void init(IActionBars bars, IWorkbenchPage page) {
104                 super.init(bars, page);
105                 
106                 // register actions that have a dynamic editor. 
107                 bars.setGlobalActionHandler(PHPdtActionConstants.CONTENT_ASSIST, fContentAssist);
108                 // character encoding
109                 fEncodingActionGroup.fillActionBars(bars);
110         }       
111 }