1 11 package org.eclipse.ant.internal.ui.editor.actions; 12 13 import org.eclipse.jface.text.ITextViewer; 14 import org.eclipse.jface.text.source.projection.IProjectionListener; 15 import org.eclipse.jface.text.source.projection.ProjectionViewer; 16 import org.eclipse.ui.actions.ActionGroup; 17 import org.eclipse.ui.editors.text.IFoldingCommandIds; 18 import org.eclipse.ui.texteditor.ITextEditor; 19 import org.eclipse.ui.texteditor.TextOperationAction; 20 21 22 27 public class FoldingActionGroup extends ActionGroup { 28 private ProjectionViewer fViewer; 29 30 private TextOperationAction fToggle; 31 private TextOperationAction fExpand; 32 private TextOperationAction fCollapse; 33 private TextOperationAction fExpandAll; 34 35 private IProjectionListener fProjectionListener; 36 37 45 public FoldingActionGroup(ITextEditor editor, ITextViewer viewer) { 46 if (viewer instanceof ProjectionViewer) { 47 fViewer= (ProjectionViewer) viewer; 48 49 fProjectionListener= new IProjectionListener() { 50 51 public void projectionEnabled() { 52 update(); 53 } 54 55 public void projectionDisabled() { 56 update(); 57 } 58 }; 59 60 fViewer.addProjectionListener(fProjectionListener); 61 62 fToggle= new TextOperationAction(AntEditorActionMessages.getResourceBundle(), "Projection.Toggle.", editor, ProjectionViewer.TOGGLE, true); fToggle.setChecked(true); 64 fToggle.setActionDefinitionId(IFoldingCommandIds.FOLDING_TOGGLE); 65 editor.setAction("FoldingToggle", fToggle); 67 fExpandAll= new TextOperationAction(AntEditorActionMessages.getResourceBundle(), "Projection.ExpandAll.", editor, ProjectionViewer.EXPAND_ALL, true); fExpandAll.setActionDefinitionId(IFoldingCommandIds.FOLDING_EXPAND_ALL); 69 editor.setAction("FoldingExpandAll", fExpandAll); 71 fExpand= new TextOperationAction(AntEditorActionMessages.getResourceBundle(), "Projection.Expand.", editor, ProjectionViewer.EXPAND, true); fExpand.setActionDefinitionId(IFoldingCommandIds.FOLDING_EXPAND); 73 editor.setAction("FoldingExpand", fExpand); 75 fCollapse= new TextOperationAction(AntEditorActionMessages.getResourceBundle(), "Projection.Collapse.", editor, ProjectionViewer.COLLAPSE, true); fCollapse.setActionDefinitionId(IFoldingCommandIds.FOLDING_COLLAPSE); 77 editor.setAction("FoldingCollapse", fCollapse); } 79 } 80 81 89 private boolean isEnabled() { 90 return fViewer != null; 91 } 92 93 96 public void dispose() { 97 if (isEnabled()) { 98 fViewer.removeProjectionListener(fProjectionListener); 99 fViewer= null; 100 } 101 super.dispose(); 102 } 103 104 107 protected void update() { 108 if (isEnabled()) { 109 fToggle.update(); 110 fToggle.setChecked(fViewer.getProjectionAnnotationModel() != null); 111 fExpand.update(); 112 fExpandAll.update(); 113 fCollapse.update(); 114 } 115 } 116 117 120 public void updateActionBars() { 121 update(); 122 } 123 } 124 | Popular Tags |