Temporarily replace new Project Wizard until errors in old one investigated..
[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.actions.PHPdtActionConstants;
16
17 import org.eclipse.jface.action.IMenuManager;
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.actions.ActionGroup;
23 import org.eclipse.ui.texteditor.BasicTextEditorActionContributor;
24 import org.eclipse.ui.texteditor.ITextEditor;
25 import org.eclipse.ui.texteditor.RetargetTextEditorAction;
26
27 /**
28  * Contributes interesting PHP actions to the desktop's Edit menu and the toolbar.
29  */
30 public class PHPActionContributor extends BasicTextEditorActionContributor   {
31
32   protected RetargetTextEditorAction fContentAssistProposal;
33   // protected RetargetTextEditorAction fContentAssistTip;
34   // protected TextEditorAction fTogglePresentation;
35   protected PHPParserAction parserAction;
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     parserAction = PHPParserAction.getInstance();
46   }
47
48   /*
49    * @see IEditorActionBarContributor#init(IActionBars)
50    */
51   public void init(IActionBars bars) {
52     super.init(bars);
53
54     IMenuManager menuManager = bars.getMenuManager();
55     IMenuManager editMenu = menuManager.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
56     if (editMenu != null) {
57       editMenu.add(new Separator());
58       editMenu.add(fContentAssistProposal);
59       //   editMenu.add(fContentAssistTip);
60     }
61
62     //    IToolBarManager toolBarManager = bars.getToolBarManager();
63     //    if (toolBarManager != null) {
64     //      toolBarManager.add(new Separator());
65     //      toolBarManager.add(fTogglePresentation);
66     //    }
67   }
68
69   private void doSetActiveEditor(IEditorPart part) {
70     super.setActiveEditor(part);
71
72     ITextEditor textEditor = null;
73     if (part instanceof ITextEditor)
74       textEditor = (ITextEditor) part;
75
76     fContentAssistProposal.setAction(getAction(textEditor, "ContentAssistProposal")); //$NON-NLS-1$
77     //  fContentAssistTip.setAction(getAction(editor, "ContentAssistTip")); //$NON-NLS-1$
78
79     IActionBars bars = getActionBars();
80     bars.setGlobalActionHandler(PHPdtActionConstants.COMMENT, getAction(textEditor, "Comment"));
81     bars.setGlobalActionHandler(PHPdtActionConstants.UNCOMMENT, getAction(textEditor, "Uncomment"));
82
83     if (part instanceof PHPEditor) {
84       PHPEditor cuEditor= (PHPEditor)part;
85       ActionGroup group= cuEditor.getActionGroup();
86       if (group != null)
87         group.fillActionBars(bars);
88     }
89     //    fTogglePresentation.setEditor(editor);
90     //    fTogglePresentation.update();
91
92     parserAction.setEditor(textEditor);
93     parserAction.update();
94   }
95
96   /*
97    * @see IEditorActionBarContributor#setActiveEditor(IEditorPart)
98    */
99   public void setActiveEditor(IEditorPart part) {
100     doSetActiveEditor(part);   
101   }
102
103   /*
104    * @see IEditorActionBarContributor#dispose()
105    */
106   public void dispose() {
107     doSetActiveEditor(null);
108     super.dispose();
109   }
110 }