blob: f4386718cb506da8a748fd617eb579170a81a1a9 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2000, 2008 IBM Corporation and others.
* 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:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.ant.internal.ui.editor.actions;
import org.eclipse.ant.internal.ui.editor.AntEditor;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.IVerticalRulerInfo;
import org.eclipse.jface.text.source.projection.ProjectionViewer;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.editors.text.IFoldingCommandIds;
import org.eclipse.ui.texteditor.AbstractRulerActionDelegate;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.ui.texteditor.TextOperationAction;
public class FoldingToggleRulerAction extends AbstractRulerActionDelegate {
private IAction fUIAction;
private TextOperationAction fAction;
private ITextEditor fTextEditor;
/* (non-Javadoc)
* @see org.eclipse.ui.texteditor.AbstractRulerActionDelegate#createAction(org.eclipse.ui.texteditor.ITextEditor, org.eclipse.jface.text.source.IVerticalRulerInfo)
*/
protected IAction createAction(ITextEditor editor, IVerticalRulerInfo rulerInfo) {
fTextEditor= editor;
fAction= new TextOperationAction(AntEditorActionMessages.getResourceBundle(), "Projection.Toggle.", editor, ProjectionViewer.TOGGLE, true); //$NON-NLS-1$
fAction.setActionDefinitionId(IFoldingCommandIds.FOLDING_TOGGLE);
return fAction;
}
/* (non-Javadoc)
* @see org.eclipse.ui.IEditorActionDelegate#setActiveEditor(org.eclipse.jface.action.IAction, org.eclipse.ui.IEditorPart)
*/
public void setActiveEditor(IAction callerAction, IEditorPart targetEditor) {
fUIAction= callerAction;
super.setActiveEditor(callerAction, targetEditor);
}
/* (non-Javadoc)
* @see org.eclipse.jface.action.IMenuListener#menuAboutToShow(org.eclipse.jface.action.IMenuManager)
*/
public void menuAboutToShow(IMenuManager manager) {
update();
super.menuAboutToShow(manager);
}
private void update() {
if (fTextEditor instanceof AntEditor) {
ISourceViewer viewer= ((AntEditor) fTextEditor).getViewer();
if (viewer instanceof ProjectionViewer) {
boolean enabled= ((ProjectionViewer) viewer).getProjectionAnnotationModel() != null;
fUIAction.setChecked(enabled);
}
}
}
}