Improved auto completion
[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   public static final String COMMENT = "net.sourceforge.phpeclipse.phpeditor.comment";
34   public static final String UNCOMMENT = "net.sourceforge.phpeclipse.phpeditor.uncomment";
35   
36   protected RetargetTextEditorAction fContentAssistProposal;
37   protected RetargetTextEditorAction fContentAssistTip;
38   protected TextEditorAction fTogglePresentation;
39   protected PHPParserAction parserAction;
40
41   /**
42    * Default constructor.
43    */
44   public PHPActionContributor() {
45     super();
46     fContentAssistProposal = new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "ContentAssistProposal."); //$NON-NLS-1$
47     fContentAssistTip = new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "ContentAssistTip."); //$NON-NLS-1$
48     fTogglePresentation = new PresentationAction();
49     parserAction = PHPParserAction.getInstance();
50   }
51
52   /*
53    * @see IEditorActionBarContributor#init(IActionBars)
54    */
55   public void init(IActionBars bars) {
56     super.init(bars);
57
58     IMenuManager menuManager = bars.getMenuManager();
59     IMenuManager editMenu = menuManager.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
60     if (editMenu != null) {
61       editMenu.add(new Separator());
62       editMenu.add(fContentAssistProposal);
63       editMenu.add(fContentAssistTip);
64     }
65
66     IToolBarManager toolBarManager = bars.getToolBarManager();
67     if (toolBarManager != null) {
68       toolBarManager.add(new Separator());
69       toolBarManager.add(fTogglePresentation);
70     }
71   }
72
73   private void doSetActiveEditor(IEditorPart part) {
74     super.setActiveEditor(part);
75
76     ITextEditor editor = null;
77     if (part instanceof ITextEditor)
78       editor = (ITextEditor) part;
79
80     fContentAssistProposal.setAction(getAction(editor, "ContentAssistProposal")); //$NON-NLS-1$
81     fContentAssistTip.setAction(getAction(editor, "ContentAssistTip")); //$NON-NLS-1$
82
83     IActionBars bars= getActionBars();    
84     bars.setGlobalActionHandler(COMMENT, getAction(editor, "Comment"));
85     bars.setGlobalActionHandler(UNCOMMENT, getAction(editor, "Uncomment"));
86     
87     fTogglePresentation.setEditor(editor);
88     fTogglePresentation.update();
89
90     parserAction.setEditor(editor);
91     parserAction.update();
92   }
93
94   /*
95    * @see IEditorActionBarContributor#setActiveEditor(IEditorPart)
96    */
97   public void setActiveEditor(IEditorPart part) {
98     super.setActiveEditor(part);
99     doSetActiveEditor(part);
100
101   }
102
103   /*
104    * @see IEditorActionBarContributor#dispose()
105    */
106   public void dispose() {
107     doSetActiveEditor(null);
108     super.dispose();
109   }
110 }