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 RevertBlockAction extends QuickDiffRestoreAction { 27 28 private static final String PREFIX= "RevertBlockAction."; 30 31 private int fLine; 32 33 39 public RevertBlockAction(ITextEditor editor, boolean isRulerAction) { 40 super(PREFIX, editor, isRulerAction); 41 } 42 43 46 public boolean computeEnablement() { 47 if (!super.computeEnablement()) 48 return false; 49 50 fLine= getLastLine(); 51 if (fLine == -1) 52 return false; 53 ILineDiffer differ= getDiffer(); 54 if (differ == null) 55 return false; 56 ILineDiffInfo info= differ.getLineInfo(fLine); 57 if (info == null || info.getChangeType() == ILineDiffInfo.UNCHANGED) 58 return false; 59 60 boolean hasBlock= false; 61 if (fLine > 0) { 62 info= differ.getLineInfo(fLine - 1); 63 hasBlock= info != null && info.hasChanges(); 64 } 65 if (!hasBlock) { 66 info= differ.getLineInfo(fLine + 1); 67 hasBlock= info != null && info.hasChanges(); 68 } 69 if (hasBlock) 70 return true; 71 72 return false; 73 } 74 75 78 public void runCompoundChange() { 79 if (!isEnabled()) 80 return; 81 ILineDiffer differ= getDiffer(); 82 if (differ != null) { 83 try { 84 differ.revertBlock(fLine); 85 } catch (BadLocationException e) { 86 setStatus(e.getMessage()); 87 } 88 } 89 } 90 } 91 | Popular Tags |