1 11 package org.eclipse.ui.internal.texteditor.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 29 private int fLine; 30 31 37 public RevertLineAction(ITextEditor editor, boolean isRulerAction) { 38 super("RevertLineAction.", editor, isRulerAction); } 40 41 44 public boolean computeEnablement() { 45 if (!super.computeEnablement()) 46 return false; 47 48 fLine= getLastLine(); 49 if (fLine == -1) 50 return false; 51 ILineDiffer differ= getDiffer(); 52 if (differ == null) 53 return false; 54 ILineDiffInfo info= differ.getLineInfo(fLine); 55 if (info == null || info.getChangeType() == ILineDiffInfo.UNCHANGED) 56 return false; 57 58 if (info.getChangeType() == ILineDiffInfo.ADDED) 59 setText(QuickDiffMessages.RevertLineAction_delete_label); 60 else 61 setText(QuickDiffMessages.RevertLineAction_label); 62 return true; 63 } 64 65 68 public void runCompoundChange() { 69 if (!isEnabled()) 70 return; 71 ILineDiffer differ= getDiffer(); 72 if (differ != null) { 73 try { 74 differ.revertLine(fLine); 75 } catch (BadLocationException e) { 76 setStatus(e.getMessage()); 77 } 78 } 79 } 80 } 81 | Popular Tags |