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
9 * Christopher Lenz - initial API and implementation
11 * $Id: CssEditorActionContributor.java,v 1.1 2004-09-02 18:11:50 jsurfer Exp $
14 package net.sourceforge.phpeclipse.css.ui.internal.editor;
16 import net.sourceforge.phpeclipse.css.ui.internal.CssUIMessages;
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;
33 public class CssEditorActionContributor
34 extends BasicTextEditorActionContributor {
36 // Instance Variables ------------------------------------------------------
38 private RetargetTextEditorAction contentAssistAction =
39 new RetargetTextEditorAction(CssUIMessages.getResourceBundle(),
40 "CssEditor.contentAssistProposal."); //$NON-NLS-1$
42 private ShowSelectedElementOnlyAction showSelectedElementOnlyAction =
43 new ShowSelectedElementOnlyAction(); //$NON-NLS-1$
45 // IEditorActionBarContributor Implementation ------------------------------
48 * @see org.eclipse.ui.part.EditorActionBarContributor#contributeToMenu(IMenuManager)
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);
61 * @see org.eclipse.ui.part.EditorActionBarContributor#contributeToToolBar(IToolBarManager)
63 public void contributeToToolBar(IToolBarManager toolBarManager) {
64 super.contributeToToolBar(toolBarManager);
65 if (toolBarManager != null) {
66 toolBarManager.add(new Separator());
71 * @see org.eclipse.ui.IEditorActionBarContributor#dispose()
73 public void dispose() {
74 doSetActiveEditor(null);
79 * @see org.eclipse.ui.IEditorActionBarContributor#setActiveEditor(IEditorPart)
81 public void setActiveEditor(IEditorPart part) {
82 super.setActiveEditor(part);
83 doSetActiveEditor(part);
86 // Private Methods ---------------------------------------------------------
88 private void doSetActiveEditor(IEditorPart part) {
89 ITextEditor editor = null;
90 if (part instanceof ITextEditor) {
91 editor = (ITextEditor) part;
94 contentAssistAction.setAction(
95 getAction(editor, ICssEditorActionConstants.CONTENT_ASSIST));
97 showSelectedElementOnlyAction.setEditor(editor);
98 showSelectedElementOnlyAction.update();
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));