1 11 package org.eclipse.compare.internal; 12 13 import java.util.ResourceBundle ; 14 15 import org.eclipse.jface.action.*; 16 17 import org.eclipse.ui.*; 18 import org.eclipse.ui.actions.ActionFactory; 19 import org.eclipse.ui.help.IWorkbenchHelpSystem; 20 import org.eclipse.ui.part.EditorActionBarContributor; 21 import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; 22 23 import org.eclipse.compare.*; 24 25 26 public class CompareEditorContributor extends EditorActionBarContributor { 27 28 private IEditorPart fActiveEditorPart= null; 29 30 private ChangePropertyAction fIgnoreWhitespace; 31 private NavigationAction fNext; 32 private NavigationAction fPrevious; 33 34 private NavigationAction fToolbarNext; 35 private NavigationAction fToolbarPrevious; 36 37 public CompareEditorContributor() { 38 ResourceBundle bundle= CompareUI.getResourceBundle(); 39 40 IWorkbenchHelpSystem helpSystem= PlatformUI.getWorkbench().getHelpSystem(); 41 42 fIgnoreWhitespace= ChangePropertyAction.createIgnoreWhiteSpaceAction(bundle, null); 43 helpSystem.setHelp(fIgnoreWhitespace, ICompareContextIds.IGNORE_WHITESPACE_ACTION); 44 45 fNext= new NavigationAction(bundle, true); 46 helpSystem.setHelp(fNext, ICompareContextIds.GLOBAL_NEXT_DIFF_ACTION); 47 48 fPrevious= new NavigationAction(bundle, false); 49 helpSystem.setHelp(fPrevious, ICompareContextIds.GLOBAL_PREVIOUS_DIFF_ACTION); 50 51 fToolbarNext= new NavigationAction(bundle, true); 52 helpSystem.setHelp(fToolbarNext, ICompareContextIds.NEXT_DIFF_ACTION); 53 54 fToolbarPrevious= new NavigationAction(bundle, false); 55 helpSystem.setHelp(fToolbarPrevious, ICompareContextIds.PREVIOUS_DIFF_ACTION); 56 } 57 58 61 public void contributeToToolBar(IToolBarManager tbm) { 62 tbm.add(new Separator()); 63 tbm.add(fIgnoreWhitespace); 64 tbm.add(fToolbarNext); 65 tbm.add(fToolbarPrevious); 66 } 67 68 71 public void contributeToMenu(IMenuManager menuManager) { 72 } 74 75 public void setActiveEditor(IEditorPart targetEditor) { 76 77 if (fActiveEditorPart == targetEditor) 78 return; 79 80 fActiveEditorPart= targetEditor; 81 82 if (fActiveEditorPart != null) { 83 IEditorInput input= fActiveEditorPart.getEditorInput(); 84 if (input instanceof CompareEditorInput) { 85 CompareEditorInput compareInput= (CompareEditorInput) input; 86 fNext.setCompareEditorInput(compareInput); 87 fPrevious.setCompareEditorInput(compareInput); 88 fToolbarNext.setCompareEditorInput(compareInput); 90 fToolbarPrevious.setCompareEditorInput(compareInput); 91 } 93 } 94 95 if (targetEditor instanceof CompareEditor) { 96 IActionBars actionBars= getActionBars(); 97 98 CompareEditor editor= (CompareEditor) targetEditor; 99 editor.setActionBars(actionBars); 100 101 actionBars.setGlobalActionHandler(ActionFactory.NEXT.getId(), fNext); 102 actionBars.setGlobalActionHandler(ActionFactory.PREVIOUS.getId(), fPrevious); 103 104 actionBars.setGlobalActionHandler(ITextEditorActionDefinitionIds.GOTO_NEXT_ANNOTATION, fNext); 105 actionBars.setGlobalActionHandler(ITextEditorActionDefinitionIds.GOTO_PREVIOUS_ANNOTATION, fPrevious); 106 107 CompareConfiguration cc= editor.getCompareConfiguration(); 108 fIgnoreWhitespace.setCompareConfiguration(cc); 109 } else { 110 IActionBars actionBars= getActionBars(); 111 actionBars.setGlobalActionHandler(ActionFactory.NEXT.getId(), null); 112 actionBars.setGlobalActionHandler(ActionFactory.PREVIOUS.getId(), null); 113 actionBars.setGlobalActionHandler(ITextEditorActionDefinitionIds.GOTO_NEXT_ANNOTATION, null); 114 actionBars.setGlobalActionHandler(ITextEditorActionDefinitionIds.GOTO_PREVIOUS_ANNOTATION, null); 115 } 116 } 117 118 public void dispose() { 119 setActiveEditor(null); 120 super.dispose(); 121 fIgnoreWhitespace.dispose(); 122 } 123 } 124 | Popular Tags |