1 15 16 package org.eclipse.ant.internal.ui.editor; 17 18 import java.util.ResourceBundle ; 19 20 import org.eclipse.ant.internal.ui.editor.actions.FoldingActionGroup; 21 import org.eclipse.ant.internal.ui.editor.actions.OpenDeclarationAction; 22 import org.eclipse.ant.internal.ui.editor.actions.OpenExternalDocAction; 23 import org.eclipse.ant.internal.ui.editor.actions.ToggleAutoReconcileAction; 24 import org.eclipse.ant.internal.ui.editor.actions.ToggleMarkOccurrencesAction; 25 import org.eclipse.ant.internal.ui.editor.actions.TogglePresentationAction; 26 import org.eclipse.jface.action.IMenuManager; 27 import org.eclipse.jface.action.Separator; 28 import org.eclipse.ui.IActionBars; 29 import org.eclipse.ui.IEditorPart; 30 import org.eclipse.ui.IWorkbenchActionConstants; 31 import org.eclipse.ui.IWorkbenchPage; 32 import org.eclipse.ui.editors.text.TextEditorActionContributor; 33 import org.eclipse.ui.texteditor.ITextEditor; 34 import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; 35 import org.eclipse.ui.texteditor.RetargetTextEditorAction; 36 37 41 public class AntEditorActionContributor extends TextEditorActionContributor { 42 43 private final static String TOGGLE_MARK_OCCURRENCES_ID= "org.eclipse.ant.ui.toggleMarkOccurrences"; protected RetargetTextEditorAction fContentAssistProposal; 45 protected RetargetTextEditorAction fContentFormat; 46 private OpenDeclarationAction fOpenDeclarationAction; 47 private TogglePresentationAction fTogglePresentation; 48 private OpenExternalDocAction fOpenExternalDocAction; 49 private ToggleMarkOccurrencesAction fToggleMarkOccurrencesAction; 50 private ToggleAutoReconcileAction fToggleAutoReconcileAction; 51 52 public AntEditorActionContributor() { 53 super(); 54 ResourceBundle bundle = AntEditorMessages.getResourceBundle(); 55 fContentAssistProposal = new RetargetTextEditorAction(bundle, "ContentAssistProposal."); fContentFormat = new RetargetTextEditorAction(bundle, "ContentFormat."); fTogglePresentation= new TogglePresentationAction(); 58 fToggleMarkOccurrencesAction= new ToggleMarkOccurrencesAction(); 59 fToggleAutoReconcileAction= new ToggleAutoReconcileAction(); 60 61 } 62 63 protected void initializeActions(AntEditor editor) { 64 fOpenDeclarationAction= new OpenDeclarationAction(editor); 65 fOpenExternalDocAction= new OpenExternalDocAction(editor); 66 } 67 68 private void doSetActiveEditor(IEditorPart part) { 69 super.setActiveEditor(part); 70 71 ITextEditor editor= null; 72 if (part instanceof ITextEditor) { 73 editor= (ITextEditor) part; 74 } 75 76 fContentAssistProposal.setAction(getAction(editor, "ContentAssistProposal")); fContentFormat.setAction(getAction(editor, "ContentFormat")); 79 if (editor instanceof AntEditor) { 80 AntEditor antEditor= (AntEditor) part; 81 if (fOpenDeclarationAction == null) { 82 initializeActions(antEditor); 83 contributeToMenu(getActionBars().getMenuManager()); 84 } 85 86 FoldingActionGroup foldingActions= antEditor.getFoldingActionGroup(); 87 if (foldingActions != null) { 88 foldingActions.updateActionBars(); 89 } 90 if (fOpenDeclarationAction != null) { 91 fOpenDeclarationAction.setEditor(antEditor); 92 } 93 if (fOpenExternalDocAction != null) { 94 fOpenExternalDocAction.setActiveEditor(null, antEditor); 95 } 96 } 97 98 if (fTogglePresentation != null) { 99 fTogglePresentation.setEditor(editor); 100 } 101 if (fToggleMarkOccurrencesAction != null) { 102 fToggleMarkOccurrencesAction.setEditor(editor); 103 } 104 if (fToggleAutoReconcileAction != null) { 105 fToggleAutoReconcileAction.setEditor(editor); 106 } 107 } 108 109 112 public void contributeToMenu(IMenuManager menu) { 113 if (fOpenDeclarationAction == null) { 114 return; 115 } 116 super.contributeToMenu(menu); 117 118 IMenuManager navigateMenu= menu.findMenuUsingPath(IWorkbenchActionConstants.M_NAVIGATE); 119 if (navigateMenu != null) { 120 navigateMenu.appendToGroup(IWorkbenchActionConstants.OPEN_EXT, fOpenDeclarationAction); 121 navigateMenu.appendToGroup(IWorkbenchActionConstants.OPEN_EXT, fOpenExternalDocAction); 122 navigateMenu.setVisible(true); 123 } 124 } 125 126 129 public void init(IActionBars bars) { 130 super.init(bars); 131 132 IMenuManager menuManager= bars.getMenuManager(); 133 IMenuManager editMenu= menuManager.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT); 134 if (editMenu != null) { 135 editMenu.add(new Separator()); 136 editMenu.add(fContentAssistProposal); 137 editMenu.add(fContentFormat); 138 } 139 } 140 141 144 public void setActiveEditor(IEditorPart part) { 145 doSetActiveEditor(part); 146 } 147 148 151 public void dispose() { 152 doSetActiveEditor(null); 153 super.dispose(); 154 } 155 156 159 public void init(IActionBars bars, IWorkbenchPage page) { 160 super.init(bars, page); 161 bars.setGlobalActionHandler(ITextEditorActionDefinitionIds.TOGGLE_SHOW_SELECTED_ELEMENT_ONLY, fTogglePresentation); 162 bars.setGlobalActionHandler(TOGGLE_MARK_OCCURRENCES_ID, fToggleMarkOccurrencesAction); 163 bars.setGlobalActionHandler("org.eclipse.ant.ui.toggleAutoReconcile", fToggleAutoReconcileAction); } 165 } 166 | Popular Tags |