Fixed: 1736622 - "php marker occurrences" color - did`t have an effect
[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 net.sourceforge.phpeclipse.phpeditor.PHPEditor;
14
15 import org.eclipse.jface.action.IAction;
16 import org.eclipse.jface.action.IMenuManager;
17 import org.eclipse.jface.text.source.ISourceViewer;
18 import org.eclipse.jface.text.source.IVerticalRulerInfo;
19 import org.eclipse.jface.text.source.projection.ProjectionViewer;
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 /**
27  * Groups the JDT folding actions.
28  * 
29  * @since 3.0
30  */
31 public class FoldingToggleRulerAction extends AbstractRulerActionDelegate {
32
33         private IAction fUIAction;
34
35         private TextOperationAction fAction;
36
37         private ITextEditor fTextEditor;
38
39         /*
40          * @see org.eclipse.ui.texteditor.AbstractRulerActionDelegate#createAction(org.eclipse.ui.texteditor.ITextEditor,
41          *      org.eclipse.jface.text.source.IVerticalRulerInfo)
42          */
43         protected IAction createAction(ITextEditor editor,
44                         IVerticalRulerInfo rulerInfo) {
45                 fTextEditor = editor;
46                 fAction = new TextOperationAction(ActionMessages.getResourceBundle(),
47                                 "Projection.Toggle.", editor, ProjectionViewer.TOGGLE, true); //$NON-NLS-1$
48                 fAction.setActionDefinitionId(IFoldingCommandIds.FOLDING_TOGGLE);
49
50                 return fAction;
51         }
52
53         /*
54          * @see org.eclipse.ui.texteditor.AbstractRulerActionDelegate#setActiveEditor(org.eclipse.jface.action.IAction,
55          *      org.eclipse.ui.IEditorPart)
56          */
57         public void setActiveEditor(IAction callerAction, IEditorPart targetEditor) {
58                 fUIAction = callerAction;
59                 super.setActiveEditor(callerAction, targetEditor);
60         }
61
62         /*
63          * @see org.eclipse.ui.texteditor.AbstractRulerActionDelegate#menuAboutToShow(org.eclipse.jface.action.IMenuManager)
64          */
65         public void menuAboutToShow(IMenuManager manager) {
66                 update();
67                 super.menuAboutToShow(manager);
68         }
69
70         private void update() {
71                 if (fTextEditor instanceof PHPEditor) {
72                         ISourceViewer viewer = ((PHPEditor) fTextEditor).getViewer();
73                         if (viewer instanceof ProjectionViewer) {
74                                 boolean enabled = ((ProjectionViewer) viewer)
75                                                 .getProjectionAnnotationModel() != null;
76                                 fUIAction.setChecked(enabled);
77                         }
78                 }
79         }
80 }