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.internal.texteditor.NLSUtility; 19 import org.eclipse.ui.texteditor.ITextEditor; 20 21 26 public class RestoreAction extends QuickDiffRestoreAction { 27 28 private static final String PREFIX= "RestoreAction."; 30 31 private int fLine; 32 33 39 public RestoreAction(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.getRemovedLinesAbove() <= 0 && info.getRemovedLinesBelow() <= 0)) 58 return false; 59 60 if (info.getRemovedLinesBelow() == 0) { 61 fLine--; 62 } else if (info.getRemovedLinesAbove() != 0) { 63 } 65 info= differ.getLineInfo(fLine); 66 if (info == null) 67 return false; 68 if (info.getRemovedLinesBelow() == 1) 69 setText(QuickDiffMessages.RestoreAction_label); 70 else 71 setText(NLSUtility.format(QuickDiffMessages.RestoreAction_multiple_label, String.valueOf(info.getRemovedLinesBelow()))); 72 return true; 73 } 74 75 78 public void runCompoundChange() { 79 if (!isEnabled()) 80 return; 81 ILineDiffer differ= getDiffer(); 82 if (differ != null) { 83 try { 84 differ.restoreAfterLine(fLine); 85 } catch (BadLocationException e) { 86 setStatus(e.getMessage()); 87 } 88 } 89 } 90 } 91 | Popular Tags |