1 11 package org.eclipse.jdt.internal.ui.javaeditor; 12 13 import java.util.ResourceBundle ; 14 15 import org.eclipse.jface.action.IAction; 16 import org.eclipse.jface.action.IMenuManager; 17 18 import org.eclipse.ui.IActionBars; 19 import org.eclipse.ui.IEditorPart; 20 import org.eclipse.ui.IWorkbenchActionConstants; 21 import org.eclipse.ui.actions.ActionFactory; 22 import org.eclipse.ui.texteditor.ITextEditor; 23 import org.eclipse.ui.texteditor.ITextEditorActionConstants; 24 import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; 25 import org.eclipse.ui.texteditor.RetargetTextEditorAction; 26 27 import org.eclipse.jdt.ui.IContextMenuConstants; 28 import org.eclipse.jdt.ui.actions.JdtActionConstants; 29 30 public class CompilationUnitEditorActionContributor extends BasicCompilationUnitEditorActionContributor { 31 32 private RetargetTextEditorAction fToggleInsertModeAction; 33 34 public CompilationUnitEditorActionContributor() { 35 super(); 36 37 ResourceBundle b= JavaEditorMessages.getBundleForConstructedKeys(); 38 39 fToggleInsertModeAction= new RetargetTextEditorAction(b, "CompilationUnitEditorActionContributor.ToggleInsertMode.", IAction.AS_CHECK_BOX); fToggleInsertModeAction.setActionDefinitionId(ITextEditorActionDefinitionIds.TOGGLE_INSERT_MODE); 41 } 42 43 44 47 public void contributeToMenu(IMenuManager menu) { 48 super.contributeToMenu(menu); 49 50 IMenuManager editMenu= menu.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT); 51 if (editMenu != null) { 52 editMenu.appendToGroup(IContextMenuConstants.GROUP_ADDITIONS, fToggleInsertModeAction); 53 } 54 } 55 56 59 public void setActiveEditor(IEditorPart part) { 60 super.setActiveEditor(part); 61 62 ITextEditor textEditor= null; 63 if (part instanceof ITextEditor) 64 textEditor= (ITextEditor) part; 65 66 IActionBars bars= getActionBars(); 68 bars.setGlobalActionHandler(JdtActionConstants.COMMENT, getAction(textEditor, "Comment")); bars.setGlobalActionHandler(JdtActionConstants.UNCOMMENT, getAction(textEditor, "Uncomment")); bars.setGlobalActionHandler(JdtActionConstants.TOGGLE_COMMENT, getAction(textEditor, "ToggleComment")); bars.setGlobalActionHandler(JdtActionConstants.FORMAT, getAction(textEditor, "Format")); bars.setGlobalActionHandler(JdtActionConstants.FORMAT_ELEMENT, getAction(textEditor, "QuickFormat")); bars.setGlobalActionHandler(JdtActionConstants.ADD_BLOCK_COMMENT, getAction(textEditor, "AddBlockComment")); bars.setGlobalActionHandler(JdtActionConstants.REMOVE_BLOCK_COMMENT, getAction(textEditor, "RemoveBlockComment")); bars.setGlobalActionHandler(JdtActionConstants.INDENT, getAction(textEditor, "Indent")); 77 IAction action= getAction(textEditor, ActionFactory.REFRESH.getId()); 78 bars.setGlobalActionHandler(ActionFactory.REFRESH.getId(), action); 79 80 fToggleInsertModeAction.setAction(getAction(textEditor, ITextEditorActionConstants.TOGGLE_INSERT_MODE)); 81 } 82 } 83 | Popular Tags |