587bc9da17b736fecf3dafc3d5f1fa1e805e719c
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / PHPActionContributor.java
1 package net.sourceforge.phpeclipse.phpeditor;
2
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
9
10 Contributors:
11     IBM Corporation - Initial implementation
12     Klaus Hartlage - www.eclipseproject.de
13 **********************************************************************/
14
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.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;
28
29 /**
30  * Contributes interesting PHP actions to the desktop's Edit menu and the toolbar.
31  */
32 public class PHPActionContributor extends BasicTextEditorActionContributor   {
33
34   // protected RetargetTextEditorAction fContentAssistTip;
35   // protected TextEditorAction fTogglePresentation;
36   protected RetargetAction fRetargetContentAssist;
37         
38   protected RetargetTextEditorAction fContentAssist;
39   
40   protected PHPParserAction parserAction;
41
42   /**
43    * Default constructor.
44    */
45   public PHPActionContributor() {
46     super();
47     
48         fRetargetContentAssist= new RetargetAction(PHPdtActionConstants.CONTENT_ASSIST,  PHPEditorMessages.getString("ContentAssistProposal.label")); //$NON-NLS-1$
49         fRetargetContentAssist.setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
50                 
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);
55
56     
57     // fContentAssist = new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "ContentAssistProposal."); //$NON-NLS-1$
58     //  fContentAssistTip = new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "ContentAssistTip."); //$NON-NLS-1$
59     //  fTogglePresentation = new PresentationAction();
60     
61         
62     parserAction = PHPParserAction.getInstance();
63   }
64
65   /*
66    * @see EditorActionBarContributor#contributeToMenu(IMenuManager)
67    */
68 //  public void contributeToMenu(IMenuManager menu) {
69 //              
70 //        super.contributeToMenu(menu);
71 //              
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));
76 //                      
77 //                editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE, fRetargetContentAssist);
78 //        }             
79 //  }
80   
81   /*
82    * @see IEditorActionBarContributor#init(IActionBars)
83    */
84   public void init(IActionBars bars) {
85     super.init(bars);
86
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);
93     }
94
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);
100     //    }
101   }
102
103   private void doSetActiveEditor(IEditorPart part) {
104     super.setActiveEditor(part);
105
106     ITextEditor textEditor = null;
107     if (part instanceof ITextEditor)
108       textEditor = (ITextEditor) part;
109
110     fContentAssist.setAction(getAction(textEditor, "ContentAssistProposal")); //$NON-NLS-1$
111     //  fContentAssistTip.setAction(getAction(editor, "ContentAssistTip")); //$NON-NLS-1$
112     
113     IActionBars bars = getActionBars();
114     bars.setGlobalActionHandler(PHPdtActionConstants.COMMENT, getAction(textEditor, "Comment"));
115     bars.setGlobalActionHandler(PHPdtActionConstants.UNCOMMENT, getAction(textEditor, "Uncomment"));
116     bars.setGlobalActionHandler(PHPdtActionConstants.FORMAT, getAction(textEditor, "Format"));
117     
118     if (part instanceof PHPEditor) {
119       PHPEditor cuEditor= (PHPEditor)part;
120       ActionGroup group= cuEditor.getActionGroup();
121       if (group != null)
122         group.fillActionBars(bars);
123     }
124     //    fTogglePresentation.setEditor(editor);
125     //    fTogglePresentation.update();
126
127     parserAction.setEditor(textEditor);
128     parserAction.update();
129   }
130
131   /*
132    * @see IEditorActionBarContributor#setActiveEditor(IEditorPart)
133    */
134   public void setActiveEditor(IEditorPart part) {
135     doSetActiveEditor(part);   
136   }
137
138   /*
139    * @see IEditorActionBarContributor#dispose()
140    */
141   public void dispose() {
142     doSetActiveEditor(null);
143     super.dispose();
144   }
145 }