1 11 package org.eclipse.jdt.internal.ui.javaeditor; 12 13 14 import org.eclipse.jface.action.IMenuManager; 15 16 import org.eclipse.ui.IActionBars; 17 import org.eclipse.ui.IEditorPart; 18 import org.eclipse.ui.IWorkbenchActionConstants; 19 import org.eclipse.ui.IWorkbenchPage; 20 import org.eclipse.ui.actions.RetargetAction; 21 import org.eclipse.ui.ide.IDEActionFactory; 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.IJavaEditorActionDefinitionIds; 29 import org.eclipse.jdt.ui.actions.JdtActionConstants; 30 31 import org.eclipse.jdt.internal.ui.JavaPluginImages; 32 33 34 public class BasicEditorActionContributor extends BasicJavaEditorActionContributor { 35 36 37 protected RetargetAction fRetargetContentAssist; 38 protected RetargetTextEditorAction fContentAssist; 39 protected RetargetTextEditorAction fContextInformation; 40 protected RetargetTextEditorAction fCorrectionAssist; 41 protected RetargetTextEditorAction fChangeEncodingAction; 42 43 44 public BasicEditorActionContributor() { 45 46 fRetargetContentAssist= new RetargetAction(JdtActionConstants.CONTENT_ASSIST, JavaEditorMessages.ContentAssistProposal_label); 47 fRetargetContentAssist.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS); 48 markAsPartListener(fRetargetContentAssist); 49 50 fContentAssist= new RetargetTextEditorAction(JavaEditorMessages.getBundleForConstructedKeys(), "ContentAssistProposal."); fContentAssist.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS); 52 fContentAssist.setImageDescriptor(JavaPluginImages.DESC_ELCL_CODE_ASSIST); 53 fContentAssist.setDisabledImageDescriptor(JavaPluginImages.DESC_DLCL_CODE_ASSIST); 54 55 fContextInformation= new RetargetTextEditorAction(JavaEditorMessages.getBundleForConstructedKeys(), "ContentAssistContextInformation."); fContextInformation.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_CONTEXT_INFORMATION); 57 58 fCorrectionAssist= new RetargetTextEditorAction(JavaEditorMessages.getBundleForConstructedKeys(), "CorrectionAssistProposal."); fCorrectionAssist.setActionDefinitionId(IJavaEditorActionDefinitionIds.CORRECTION_ASSIST_PROPOSALS); 60 61 fChangeEncodingAction= new RetargetTextEditorAction(JavaEditorMessages.getBundleForConstructedKeys(), "Editor.ChangeEncodingAction."); } 63 64 67 public void contributeToMenu(IMenuManager menu) { 68 69 super.contributeToMenu(menu); 70 71 IMenuManager editMenu= menu.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT); 72 if (editMenu != null) { 73 editMenu.add(fChangeEncodingAction); 74 editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE, fRetargetContentAssist); 75 editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE, fCorrectionAssist); 76 editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE, fContextInformation); 77 } 78 } 79 80 83 public void setActiveEditor(IEditorPart part) { 84 super.setActiveEditor(part); 85 86 ITextEditor textEditor= null; 87 if (part instanceof ITextEditor) 88 textEditor= (ITextEditor) part; 89 90 fContentAssist.setAction(getAction(textEditor, "ContentAssistProposal")); fContextInformation.setAction(getAction(textEditor, "ContentAssistContextInformation")); fCorrectionAssist.setAction(getAction(textEditor, "CorrectionAssistProposal")); 94 fChangeEncodingAction.setAction(getAction(textEditor, ITextEditorActionConstants.CHANGE_ENCODING)); 95 96 IActionBars actionBars= getActionBars(); 97 actionBars.setGlobalActionHandler(JdtActionConstants.SHIFT_RIGHT, getAction(textEditor, "ShiftRight")); actionBars.setGlobalActionHandler(JdtActionConstants.SHIFT_LEFT, getAction(textEditor, "ShiftLeft")); 100 actionBars.setGlobalActionHandler(IDEActionFactory.ADD_TASK.getId(), getAction(textEditor, IDEActionFactory.ADD_TASK.getId())); 101 actionBars.setGlobalActionHandler(IDEActionFactory.BOOKMARK.getId(), getAction(textEditor, IDEActionFactory.BOOKMARK.getId())); 102 } 103 104 107 public void init(IActionBars bars, IWorkbenchPage page) { 108 super.init(bars, page); 109 bars.setGlobalActionHandler(JdtActionConstants.CONTENT_ASSIST, fContentAssist); 111 } 112 113 117 public void dispose() { 118 if (fRetargetContentAssist != null) { 119 fRetargetContentAssist.dispose(); 120 fRetargetContentAssist= null; 121 } 122 super.dispose(); 123 } 124 } 125 | Popular Tags |