/*******************************************************************************
* Copyright (c) 2009, 2010 Innovation Gate GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Innovation Gate GmbH - initial API and implementation
******************************************************************************/
package de.innovationgate.eclipse.editors.tml;
import java.util.ResourceBundle;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.part.EditorActionBarContributor;
import org.eclipse.ui.texteditor.BasicTextEditorActionContributor;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.ui.texteditor.RetargetTextEditorAction;
import de.innovationgate.eclipse.editors.Plugin;
/**
* Manages the installation and deinstallation of actions for the tml editor.
*/
public class TMLEditorContributor extends BasicTextEditorActionContributor
{
protected RetargetTextEditorAction formatProposal;
/**
* Constructor for TMLEditorContributor. Creates a new contributor in the
* form of adding Content Format to the menu
*/
public TMLEditorContributor() {
super();
ResourceBundle bundle = Plugin.getDefault().getResourceBundle();
formatProposal = new RetargetTextEditorAction(bundle, "ContentFormatProposal.");
}
public void contributeToMenu(IMenuManager mm) {
super.contributeToMenu(mm);
IMenuManager editMenu = mm.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
if (editMenu != null) {
editMenu.add(new Separator());
editMenu.add(formatProposal);
}
}
/**
* Sets the active editor to this contributor. This updates the actions to
* reflect the editor.
*
* @see EditorActionBarContributor#editorChanged
*/
public void setActiveEditor(IEditorPart part) {
super.setActiveEditor(part);
ITextEditor editor = null;
if (part instanceof ITextEditor)
editor = (ITextEditor) part;
formatProposal.setAction(getAction(editor, "ContentFormatProposal"));
}
}