updated build.xml
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / ui / actions / FoldingToggleRulerAction.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation 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  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.internal.ui.actions;
12
13 import org.eclipse.jface.action.IAction;
14 import org.eclipse.jface.action.IMenuManager;
15
16 import org.eclipse.jface.text.source.ISourceViewer;
17 import org.eclipse.jface.text.source.IVerticalRulerInfo;
18 import org.eclipse.jface.text.source.projection.ProjectionViewer;
19
20 import org.eclipse.ui.IEditorPart;
21 import org.eclipse.ui.editors.text.IFoldingCommandIds;
22 import org.eclipse.ui.texteditor.AbstractRulerActionDelegate;
23 import org.eclipse.ui.texteditor.ITextEditor;
24 import org.eclipse.ui.texteditor.TextOperationAction;
25
26 import net.sourceforge.phpeclipse.phpeditor.PHPEditor;
27
28
29 /**
30  * Groups the JDT folding actions.
31  *  
32  * @since 3.0
33  */
34 public class FoldingToggleRulerAction extends AbstractRulerActionDelegate {
35
36         private IAction fUIAction;
37         private TextOperationAction fAction;
38         private ITextEditor fTextEditor;
39
40         /*
41          * @see org.eclipse.ui.texteditor.AbstractRulerActionDelegate#createAction(org.eclipse.ui.texteditor.ITextEditor, org.eclipse.jface.text.source.IVerticalRulerInfo)
42          */
43         protected IAction createAction(ITextEditor editor, IVerticalRulerInfo rulerInfo) {
44                 fTextEditor= editor;
45                 fAction= new TextOperationAction(ActionMessages.getResourceBundle(), "Projection.Toggle.", editor, ProjectionViewer.TOGGLE, true); //$NON-NLS-1$
46                 fAction.setActionDefinitionId(IFoldingCommandIds.FOLDING_TOGGLE);
47
48                 return fAction;
49         }
50         
51         /*
52          * @see org.eclipse.ui.texteditor.AbstractRulerActionDelegate#setActiveEditor(org.eclipse.jface.action.IAction, org.eclipse.ui.IEditorPart)
53          */
54         public void setActiveEditor(IAction callerAction, IEditorPart targetEditor) {
55                 fUIAction= callerAction;
56                 super.setActiveEditor(callerAction, targetEditor);
57         }
58         
59         /*
60          * @see org.eclipse.ui.texteditor.AbstractRulerActionDelegate#menuAboutToShow(org.eclipse.jface.action.IMenuManager)
61          */
62         public void menuAboutToShow(IMenuManager manager) {
63                 update();
64                 super.menuAboutToShow(manager);
65         }
66         
67         private void update() {
68                 if (fTextEditor instanceof PHPEditor) {
69                         ISourceViewer viewer= ((PHPEditor) fTextEditor).getViewer();
70                         if (viewer instanceof ProjectionViewer) {
71                                 boolean enabled= ((ProjectionViewer) viewer).getProjectionAnnotationModel() != null;
72                                 fUIAction.setChecked(enabled);
73                         }
74                 }
75         }
76 }