1 11 package org.eclipse.ui.internal.editors.quickdiff; 12 13 14 import org.eclipse.jface.text.BadLocationException; 15 import org.eclipse.jface.text.source.ILineDiffInfo; 16 import org.eclipse.jface.text.source.ILineDiffer; 17 18 import org.eclipse.ui.texteditor.ITextEditor; 19 20 26 public class RevertLineAction extends QuickDiffRestoreAction { 27 28 private static final String PREFIX= "RevertLineAction."; 30 private static final String DELETE_KEY= PREFIX + "delete.label"; 32 private static final String REVERT_KEY= PREFIX + "label"; 34 35 private int fLine; 36 37 43 public RevertLineAction(ITextEditor editor, boolean isRulerAction) { 44 super(QuickDiffMessages.getResourceBundle(), PREFIX, editor, isRulerAction); 45 } 46 47 50 public boolean computeEnablement() { 51 if (!super.computeEnablement()) 52 return false; 53 54 fLine= getLastLine(); 55 if (fLine == -1) 56 return false; 57 ILineDiffer differ= getDiffer(); 58 if (differ == null) 59 return false; 60 ILineDiffInfo info= differ.getLineInfo(fLine); 61 if (info == null || info.getChangeType() == ILineDiffInfo.UNCHANGED) 62 return false; 63 64 if (info.getChangeType() == ILineDiffInfo.ADDED) 65 setText(QuickDiffMessages.getString(DELETE_KEY)); 66 else 67 setText(QuickDiffMessages.getString(REVERT_KEY)); 68 return true; 69 } 70 71 74 public void runCompoundChange() { 75 if (!isEnabled()) 76 return; 77 ILineDiffer differ= getDiffer(); 78 if (differ != null) { 79 try { 80 differ.revertLine(fLine); 81 } catch (BadLocationException e) { 82 setStatus(e.getMessage()); 83 } 84 } 85 } 86 } 87 | Popular Tags |