1 11 package org.eclipse.pde.internal.ui.editor; 12 13 import java.util.Iterator ; 14 import java.util.Map ; 15 import java.util.Set ; 16 17 import org.eclipse.jdt.ui.IContextMenuConstants; 18 import org.eclipse.jdt.ui.actions.IJavaEditorActionDefinitionIds; 19 import org.eclipse.jface.action.IAction; 20 import org.eclipse.jface.action.IMenuManager; 21 import org.eclipse.jface.action.IStatusLineManager; 22 import org.eclipse.jface.action.IToolBarManager; 23 import org.eclipse.jface.action.Separator; 24 import org.eclipse.pde.internal.ui.editor.actions.FormatAction; 25 import org.eclipse.pde.internal.ui.editor.actions.HyperlinkAction; 26 import org.eclipse.pde.internal.ui.editor.actions.PDEActionConstants; 27 import org.eclipse.ui.IActionBars; 28 import org.eclipse.ui.IEditorActionBarContributor; 29 import org.eclipse.ui.IEditorPart; 30 import org.eclipse.ui.IWorkbenchActionConstants; 31 import org.eclipse.ui.SubActionBars; 32 import org.eclipse.ui.actions.ActionFactory; 33 import org.eclipse.ui.editors.text.TextEditorActionContributor; 34 import org.eclipse.ui.forms.editor.IFormPage; 35 import org.eclipse.ui.texteditor.ITextEditor; 36 import org.eclipse.ui.texteditor.ITextEditorActionConstants; 37 import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; 38 import org.eclipse.ui.texteditor.RetargetTextEditorAction; 39 40 public class PDEFormTextEditorContributor extends PDEFormEditorContributor { 41 42 private RetargetTextEditorAction fCorrectionAssist; 43 private HyperlinkAction fHyperlinkAction; 44 private FormatAction fFormatAction; 45 private RetargetTextEditorAction fContentAssist; 46 47 private TextEditorActionContributor fSourceContributor; 48 private SubActionBars fSourceActionBars; 49 50 class PDETextEditorActionContributor extends TextEditorActionContributor { 51 public void contributeToMenu(IMenuManager mm) { 52 super.contributeToMenu(mm); 53 IMenuManager editMenu = mm.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT); 54 if (editMenu != null) { 55 editMenu.add(new Separator(IContextMenuConstants.GROUP_OPEN)); 56 editMenu.add(new Separator(IContextMenuConstants.GROUP_GENERATE)); 57 editMenu.add(new Separator(IContextMenuConstants.GROUP_ADDITIONS)); 58 if (fCorrectionAssist != null) 59 editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE, fCorrectionAssist); 60 if (fContentAssist != null) 61 editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE, fContentAssist); 62 } 63 } 64 65 public void contributeToToolBar(IToolBarManager toolBarManager) { 66 super.contributeToToolBar(toolBarManager); 67 if (fHyperlinkAction != null) 68 toolBarManager.add(fHyperlinkAction); 69 } 70 71 public void setActiveEditor(IEditorPart part) { 72 super.setActiveEditor(part); 73 IActionBars actionBars = getActionBars(); 74 IStatusLineManager manager = actionBars.getStatusLineManager(); 75 manager.setMessage(null); 76 manager.setErrorMessage(null); 77 78 ITextEditor textEditor = (part instanceof ITextEditor) ? (ITextEditor) part : null; 79 if (fCorrectionAssist != null) 80 fCorrectionAssist.setAction(getAction(textEditor, ITextEditorActionConstants.QUICK_ASSIST)); if (fHyperlinkAction != null) 82 fHyperlinkAction.setTextEditor(textEditor); 83 if (fFormatAction != null) 84 fFormatAction.setTextEditor(textEditor); 85 if (fContentAssist != null) 86 fContentAssist.setAction(getAction(textEditor, "ContentAssist")); } 88 } 89 90 public PDEFormTextEditorContributor(String menuName) { 91 super(menuName); 92 fSourceContributor = createSourceContributor(); 93 if (supportsCorrectionAssist()) { 94 fCorrectionAssist = new RetargetTextEditorAction(PDESourcePage.getBundleForConstructedKeys(), "CorrectionAssistProposal."); fCorrectionAssist.setActionDefinitionId(ITextEditorActionDefinitionIds.QUICK_ASSIST); 96 } 97 if (supportsHyperlinking()) { 98 fHyperlinkAction = new HyperlinkAction(); 99 fHyperlinkAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.OPEN_EDITOR); 100 } 101 if (supportsFormatAction()) { 102 fFormatAction = new FormatAction(); 103 fFormatAction.setActionDefinitionId(PDEActionConstants.DEFN_FORMAT); 104 } 105 if (supportsContentAssist()) { 106 fContentAssist = new RetargetTextEditorAction(PDESourcePage.getBundleForConstructedKeys(), "ContentAssistProposal."); fContentAssist.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS); 108 } 109 } 110 111 public boolean supportsCorrectionAssist() { 112 return false; 113 } 114 115 public boolean supportsContentAssist() { 116 return false; 117 } 118 119 public boolean supportsFormatAction() { 120 return false; 121 } 122 123 public boolean supportsHyperlinking() { 124 return false; 125 } 126 127 public IEditorActionBarContributor getSourceContributor() { 128 return fSourceContributor; 129 } 130 131 public void init(IActionBars bars) { 132 super.init(bars); 133 fSourceActionBars = new SubActionBars(bars); 134 fSourceContributor.init(fSourceActionBars); 135 } 136 137 public void dispose() { 138 fSourceActionBars.dispose(); 139 fSourceContributor.dispose(); 140 super.dispose(); 141 } 142 143 protected void setSourceActionBarsActive(boolean active) { 144 IActionBars rootBars = getActionBars(); 145 rootBars.clearGlobalActionHandlers(); 146 rootBars.updateActionBars(); 147 if (active) { 148 fSourceActionBars.activate(); 149 Map handlers = fSourceActionBars.getGlobalActionHandlers(); 150 if (handlers != null) { 151 Set keys = handlers.keySet(); 152 for (Iterator iter = keys.iterator(); iter.hasNext();) { 153 String id = (String ) iter.next(); 154 rootBars.setGlobalActionHandler(id, (IAction) handlers.get(id)); 155 } 156 } 157 } else { 158 fSourceActionBars.deactivate(); 159 registerGlobalActionHandlers(); 160 } 161 rootBars.setGlobalActionHandler(PDEActionConstants.OPEN, active ? fHyperlinkAction : null); 162 rootBars.setGlobalActionHandler(PDEActionConstants.FORMAT, active ? fFormatAction : null); 163 rootBars.setGlobalActionHandler(ActionFactory.REVERT.getId(), getRevertAction()); 165 166 rootBars.updateActionBars(); 167 } 168 169 private void registerGlobalActionHandlers() { 170 registerGlobalAction(ActionFactory.DELETE.getId()); 171 registerGlobalAction(ActionFactory.UNDO.getId()); 172 registerGlobalAction(ActionFactory.REDO.getId()); 173 registerGlobalAction(ActionFactory.CUT.getId()); 174 registerGlobalAction(ActionFactory.COPY.getId()); 175 registerGlobalAction(ActionFactory.PASTE.getId()); 176 registerGlobalAction(ActionFactory.SELECT_ALL.getId()); 177 registerGlobalAction(ActionFactory.FIND.getId()); 178 } 179 180 private void registerGlobalAction(String id) { 181 IAction action = getGlobalAction(id); 182 getActionBars().setGlobalActionHandler(id, action); 183 } 184 185 public void setActivePage(IEditorPart newEditor) { 186 if (fEditor == null) 187 return; 188 189 IFormPage oldPage = fPage; 190 fPage = fEditor.getActivePageInstance(); 191 if (fPage == null) 192 return; 193 updateQuickOutlineMenuEntry(); 195 196 updateActions(); 197 if (oldPage != null && !oldPage.isEditor() && !fPage.isEditor()) { 198 getActionBars().updateActionBars(); 199 return; 200 } 201 202 boolean isSourcePage = fPage instanceof PDESourcePage; 203 if (isSourcePage && fPage.equals(oldPage)) 204 return; 205 fSourceContributor.setActiveEditor(fPage); 206 setSourceActionBarsActive(isSourcePage); 207 } 208 209 212 private void updateQuickOutlineMenuEntry() { 213 IActionBars actionBars = getActionBars(); 215 IMenuManager menuManager = actionBars.getMenuManager(); 216 IMenuManager navigateMenu = 218 menuManager.findMenuUsingPath(IWorkbenchActionConstants.M_NAVIGATE); 219 if (navigateMenu == null) { 221 return; 222 } 223 navigateMenu.remove(PDEActionConstants.COMMAND_ID_QUICK_OUTLINE); 229 if ((fPage instanceof PDEProjectionSourcePage) == false) { 232 return; 233 } 234 PDEProjectionSourcePage page = (PDEProjectionSourcePage)fPage; 235 if (page.isQuickOutlineEnabled() == false) { 237 return; 238 } 239 IAction quickOutlineAction = page.getAction( 242 PDEActionConstants.COMMAND_ID_QUICK_OUTLINE); 243 if (quickOutlineAction == null) { 245 return; 246 } 247 try { 251 navigateMenu.insertAfter("showIn", quickOutlineAction); } catch (IllegalArgumentException e) { 253 } 255 } 256 257 protected TextEditorActionContributor createSourceContributor() { 258 return new PDETextEditorActionContributor(); 259 } 260 261 protected HyperlinkAction getHyperlinkAction() { 262 return fHyperlinkAction; 263 } 264 protected FormatAction getFormatAction() { 265 return fFormatAction; 266 } 267 268 } 269 | Popular Tags |