Added default preferences for outline options
[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.*;
16 import org.eclipse.jface.action.IMenuManager;
17 import org.eclipse.jface.action.Separator;
18 import org.eclipse.ui.IActionBars;
19 import org.eclipse.ui.IEditorPart;
20 import org.eclipse.ui.IWorkbenchActionConstants;
21 import org.eclipse.ui.actions.ActionGroup;
22 import org.eclipse.ui.texteditor.BasicTextEditorActionContributor;
23 import org.eclipse.ui.texteditor.ITextEditor;
24 import org.eclipse.ui.texteditor.RetargetTextEditorAction;
25
26 /**
27  * Contributes interesting PHP actions to the desktop's Edit menu and the toolbar.
28  */
29 public class PHPActionContributor extends BasicTextEditorActionContributor   {
30
31   protected RetargetTextEditorAction fContentAssistProposal;
32   // protected RetargetTextEditorAction fContentAssistTip;
33   // protected TextEditorAction fTogglePresentation;
34   protected PHPParserAction parserAction;
35
36   /**
37    * Default constructor.
38    */
39   public PHPActionContributor() {
40     super();
41     fContentAssistProposal = new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "ContentAssistProposal."); //$NON-NLS-1$
42     //  fContentAssistTip = new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "ContentAssistTip."); //$NON-NLS-1$
43     //  fTogglePresentation = new PresentationAction();
44     parserAction = PHPParserAction.getInstance();
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 textEditor = null;
72     if (part instanceof ITextEditor)
73       textEditor = (ITextEditor) part;
74
75     fContentAssistProposal.setAction(getAction(textEditor, "ContentAssistProposal")); //$NON-NLS-1$
76     //  fContentAssistTip.setAction(getAction(editor, "ContentAssistTip")); //$NON-NLS-1$
77
78     IActionBars bars = getActionBars();
79     bars.setGlobalActionHandler(PHPdtActionConstants.COMMENT, getAction(textEditor, "Comment"));
80     bars.setGlobalActionHandler(PHPdtActionConstants.UNCOMMENT, getAction(textEditor, "Uncomment"));
81
82     if (part instanceof PHPEditor) {
83       PHPEditor cuEditor= (PHPEditor)part;
84       ActionGroup group= cuEditor.getActionGroup();
85       if (group != null)
86         group.fillActionBars(bars);
87     }
88     //    fTogglePresentation.setEditor(editor);
89     //    fTogglePresentation.update();
90
91     parserAction.setEditor(textEditor);
92     parserAction.update();
93   }
94
95   /*
96    * @see IEditorActionBarContributor#setActiveEditor(IEditorPart)
97    */
98   public void setActiveEditor(IEditorPart part) {
99     doSetActiveEditor(part);   
100   }
101
102   /*
103    * @see IEditorActionBarContributor#dispose()
104    */
105   public void dispose() {
106     doSetActiveEditor(null);
107     super.dispose();
108   }
109 }