intial source from ttp://www.sf.net/projects/wdte
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.css.ui / src / net / sourceforge / phpeclipse / css / ui / internal / editor / CssEditorActionContributor.java
1 /*
2  * Copyright (c) 2003-2004 Christopher Lenz and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     Christopher Lenz - initial API and implementation
10  * 
11  * $Id: CssEditorActionContributor.java,v 1.1 2004-09-02 18:11:50 jsurfer Exp $
12  */
13
14 package net.sourceforge.phpeclipse.css.ui.internal.editor;
15
16 import net.sourceforge.phpeclipse.css.ui.internal.CssUIMessages;
17
18 import org.eclipse.jface.action.IMenuManager;
19 import org.eclipse.jface.action.IToolBarManager;
20 import org.eclipse.jface.action.Separator;
21 import org.eclipse.ui.IActionBars;
22 import org.eclipse.ui.IEditorPart;
23 import org.eclipse.ui.IWorkbenchActionConstants;
24 import org.eclipse.ui.texteditor.BasicTextEditorActionContributor;
25 import org.eclipse.ui.texteditor.ITextEditor;
26 import org.eclipse.ui.texteditor.ITextEditorActionConstants;
27 import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
28 import org.eclipse.ui.texteditor.RetargetTextEditorAction;
29
30 /**
31  * 
32  */
33 public class CssEditorActionContributor
34         extends BasicTextEditorActionContributor {
35
36         // Instance Variables ------------------------------------------------------
37
38         private RetargetTextEditorAction contentAssistAction =
39                 new RetargetTextEditorAction(CssUIMessages.getResourceBundle(),
40                         "CssEditor.contentAssistProposal."); //$NON-NLS-1$
41
42         private ShowSelectedElementOnlyAction showSelectedElementOnlyAction = 
43                 new ShowSelectedElementOnlyAction(); //$NON-NLS-1$
44
45         // IEditorActionBarContributor Implementation ------------------------------
46
47         /**
48          * @see org.eclipse.ui.part.EditorActionBarContributor#contributeToMenu(IMenuManager)
49          */
50         public void contributeToMenu(IMenuManager menu) {
51                 super.contributeToMenu(menu);
52                 IMenuManager editMenu = menu.findMenuUsingPath(
53                         IWorkbenchActionConstants.M_EDIT);
54                 if (editMenu != null) {
55                         editMenu.add(new Separator());
56                         editMenu.add(this.contentAssistAction);
57                 }
58         }
59
60         /**
61          * @see org.eclipse.ui.part.EditorActionBarContributor#contributeToToolBar(IToolBarManager)
62          */
63         public void contributeToToolBar(IToolBarManager toolBarManager) {
64                 super.contributeToToolBar(toolBarManager);
65                 if (toolBarManager != null) {
66                         toolBarManager.add(new Separator());
67                 }
68         }
69
70         /**
71          * @see org.eclipse.ui.IEditorActionBarContributor#dispose()
72          */
73         public void dispose() {
74                 doSetActiveEditor(null);
75                 super.dispose();
76         }
77
78         /**
79          * @see org.eclipse.ui.IEditorActionBarContributor#setActiveEditor(IEditorPart)
80          */
81         public void setActiveEditor(IEditorPart part) {
82                 super.setActiveEditor(part);
83                 doSetActiveEditor(part);
84         }
85
86         // Private Methods ---------------------------------------------------------
87
88         private void doSetActiveEditor(IEditorPart part) {
89                 ITextEditor editor = null;
90                 if (part instanceof ITextEditor) {
91                         editor = (ITextEditor) part;
92                 }
93
94                 contentAssistAction.setAction(
95                         getAction(editor, ICssEditorActionConstants.CONTENT_ASSIST));
96
97                 showSelectedElementOnlyAction.setEditor(editor);
98                 showSelectedElementOnlyAction.update();
99
100                 IActionBars bars = getActionBars();      
101                 bars.setGlobalActionHandler(
102                         ITextEditorActionDefinitionIds.TOGGLE_SHOW_SELECTED_ELEMENT_ONLY,
103                         showSelectedElementOnlyAction);
104                 bars.setGlobalActionHandler(
105                         ICssEditorActionDefinitionIds.COMMENT,
106                         getAction(editor, ICssEditorActionConstants.COMMENT));
107                 bars.setGlobalActionHandler(
108                         ICssEditorActionDefinitionIds.UNCOMMENT,
109                         getAction(editor, ICssEditorActionConstants.UNCOMMENT));
110                 bars.setGlobalActionHandler(
111                         ITextEditorActionDefinitionIds.SHIFT_LEFT,
112                         getAction(editor, ITextEditorActionConstants.SHIFT_LEFT));
113                 bars.setGlobalActionHandler(
114                         ITextEditorActionDefinitionIds.SHIFT_RIGHT,
115                         getAction(editor, ITextEditorActionConstants.SHIFT_RIGHT));
116         }
117
118 }