1fbefe51745a71c9ddce3b6967e1a3492d228955
[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 java.util.ResourceBundle;
16 import org.eclipse.jface.action.IMenuManager;
17 import org.eclipse.jface.action.IToolBarManager;
18 import org.eclipse.jface.action.Separator;
19 import org.eclipse.ui.IActionBars;
20 import org.eclipse.ui.IEditorPart;
21 import org.eclipse.ui.IWorkbenchActionConstants;
22 import org.eclipse.ui.editors.text.TextEditorActionContributor;
23 import org.eclipse.ui.texteditor.BasicTextEditorActionContributor;
24 import org.eclipse.ui.texteditor.ITextEditor;
25 import org.eclipse.ui.texteditor.RetargetTextEditorAction;
26 import org.eclipse.ui.texteditor.TextEditorAction;
27
28 /**
29  * Contributes interesting Java actions to the desktop's Edit menu and the toolbar.
30  */
31 public class PHPActionContributor extends TextEditorActionContributor {
32
33         protected RetargetTextEditorAction fContentAssistProposal;
34         protected RetargetTextEditorAction fContentAssistTip;
35         protected TextEditorAction fTogglePresentation;
36
37         /**
38          * Default constructor.
39          */
40         public PHPActionContributor() {
41                 super();
42                 fContentAssistProposal= new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "ContentAssistProposal."); //$NON-NLS-1$
43                 fContentAssistTip= new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "ContentAssistTip."); //$NON-NLS-1$
44                 fTogglePresentation= new PresentationAction();
45         }
46         
47         /*
48          * @see IEditorActionBarContributor#init(IActionBars)
49          */
50         public void init(IActionBars bars) {
51                 super.init(bars);
52                 
53                 IMenuManager menuManager= bars.getMenuManager();
54                 IMenuManager editMenu= menuManager.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
55                 if (editMenu != null) {
56                         editMenu.add(new Separator());
57                         editMenu.add(fContentAssistProposal);
58                         editMenu.add(fContentAssistTip);
59                 }       
60                 
61                 IToolBarManager toolBarManager= bars.getToolBarManager();
62                 if (toolBarManager != null) {
63                         toolBarManager.add(new Separator());
64                         toolBarManager.add(fTogglePresentation);
65                 }
66         }
67         
68         private void doSetActiveEditor(IEditorPart part) {
69                 super.setActiveEditor(part);
70
71                 ITextEditor editor= null;
72                 if (part instanceof ITextEditor)
73                         editor= (ITextEditor) part;
74
75                 fContentAssistProposal.setAction(getAction(editor, "ContentAssistProposal")); //$NON-NLS-1$
76                 fContentAssistTip.setAction(getAction(editor, "ContentAssistTip")); //$NON-NLS-1$
77
78                 fTogglePresentation.setEditor(editor);
79                 fTogglePresentation.update();
80         }
81         
82         /*
83          * @see IEditorActionBarContributor#setActiveEditor(IEditorPart)
84          */
85         public void setActiveEditor(IEditorPart part) {
86                 super.setActiveEditor(part);
87                 doSetActiveEditor(part);
88         }
89         
90         /*
91          * @see IEditorActionBarContributor#dispose()
92          */
93         public void dispose() {
94                 doSetActiveEditor(null);
95                 super.dispose();
96         }
97 }