1 11 package org.eclipse.ui.internal.texteditor.quickdiff; 12 13 14 import org.eclipse.jface.text.BadLocationException; 15 import org.eclipse.jface.text.ITextSelection; 16 import org.eclipse.jface.text.source.ILineDiffInfo; 17 import org.eclipse.jface.text.source.ILineDiffer; 18 19 import org.eclipse.ui.texteditor.ITextEditor; 20 21 27 public class RevertSelectionAction extends QuickDiffRestoreAction { 28 29 private int fStartLine; 30 31 private int fEndLine; 32 33 39 public RevertSelectionAction(ITextEditor editor, boolean isRulerAction) { 40 super("RevertSelectionAction.", editor, isRulerAction); } 42 43 46 public boolean computeEnablement() { 47 if (!super.computeEnablement()) 48 return false; 49 50 ITextSelection selection= getSelection(); 51 if (selection == null) 52 return false; 53 fStartLine= selection.getStartLine(); 54 fEndLine= selection.getEndLine(); 55 int activityLine= getLastLine(); 57 if (activityLine == -1 || activityLine < fStartLine || activityLine > fEndLine + 1) 58 return false; 60 ILineDiffer differ= getDiffer(); 61 if (differ == null) 62 return false; 63 if (fEndLine > fStartLine) { 65 for (int i= fStartLine; i <= fEndLine; i++) { 66 ILineDiffInfo info= differ.getLineInfo(i); 67 if (info != null && info.hasChanges()) { 68 return true; 69 } 70 } 71 } 72 return false; 73 } 74 75 78 public void runCompoundChange() { 79 if (!isEnabled()) 81 return; 82 83 ILineDiffer differ= getDiffer(); 84 if (differ != null) { 85 try { 86 differ.revertSelection(fStartLine, fEndLine - fStartLine + 1); 87 } catch (BadLocationException e) { 88 setStatus(e.getMessage()); 89 } 90 } 91 } 92 93 } 94 | Popular Tags |