diff options
Diffstat (limited to 'platform/vcs-impl/src/com/intellij/openapi/vcs/ex')
-rw-r--r-- | platform/vcs-impl/src/com/intellij/openapi/vcs/ex/LineStatusTracker.java | 83 | ||||
-rw-r--r-- | platform/vcs-impl/src/com/intellij/openapi/vcs/ex/RollbackLineStatusAction.java | 20 |
2 files changed, 74 insertions, 29 deletions
diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/LineStatusTracker.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/LineStatusTracker.java index daef43857c4e..abc43dd3a34d 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/LineStatusTracker.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/LineStatusTracker.java @@ -295,6 +295,23 @@ public class LineStatusTracker { } } + private void markFileUnchanged() { + ApplicationManager.getApplication().invokeLater(new Runnable() { + @Override + public void run() { + FileDocumentManager.getInstance().saveDocument(myDocument); + boolean stillEmpty; + synchronized (myLock) { + stillEmpty = myRanges.isEmpty(); + } + if (stillEmpty) { + // file was modified, and now it's not -> dirty local change + myVcsDirtyScopeManager.fileDirty(myVirtualFile); + } + } + }); + } + private class MyDocumentListener extends DocumentAdapter { // We have 3 document versions: // * VCS version @@ -457,20 +474,7 @@ public class LineStatusTracker { } if (myRanges.isEmpty() && myVirtualFile != null) { - ApplicationManager.getApplication().invokeLater(new Runnable() { - @Override - public void run() { - FileDocumentManager.getInstance().saveDocument(myDocument); - boolean stillEmpty; - synchronized (myLock) { - stillEmpty = myRanges.isEmpty(); - } - if (stillEmpty) { - // file was modified, and now it's not -> dirty local change - myVcsDirtyScopeManager.fileDirty(myVirtualFile); - } - } - }); + markFileUnchanged(); } } } @@ -764,15 +768,10 @@ public class LineStatusTracker { } } - public void rollbackChanges(@NotNull BitSet lines) { - myApplication.assertWriteAccessAllowed(); - - synchronized (myLock) { - if (myBulkUpdate) return; - - try { - mySuppressUpdate = true; - + public void rollbackChanges(@NotNull final BitSet lines) { + runBulkRollback(new Runnable() { + @Override + public void run() { Range first = null; Range last = null; @@ -816,11 +815,41 @@ public class LineStatusTracker { doUpdateRanges(beforeChangedLine1, beforeChangedLine2, shift, beforeTotalLines); } } - catch (Throwable e) { + }); + } + + public void rollbackAllChanges() { + runBulkRollback(new Runnable() { + @Override + public void run() { + myDocument.setText(myVcsDocument.getText()); + + removeAnathema(); + removeHighlightersFromMarkupModel(); + + markFileUnchanged(); + } + }); + } + + private void runBulkRollback(@NotNull Runnable task) { + myApplication.assertWriteAccessAllowed(); + + synchronized (myLock) { + if (myBulkUpdate) return; + + try { + mySuppressUpdate = true; + + task.run(); + } + catch (Error e) { + reinstallRanges(); + throw e; + } + catch (RuntimeException e) { reinstallRanges(); - if (e instanceof Error) throw ((Error)e); - if (e instanceof RuntimeException) throw ((RuntimeException)e); - throw new RuntimeException(e); + throw e; } finally { mySuppressUpdate = false; diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/RollbackLineStatusAction.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/RollbackLineStatusAction.java index 1286b6815fcf..529da7371bf7 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/RollbackLineStatusAction.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/RollbackLineStatusAction.java @@ -12,8 +12,6 @@ */ package com.intellij.openapi.vcs.ex; -import com.intellij.icons.AllIcons; -import com.intellij.idea.ActionsBundle; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.CommonDataKeys; import com.intellij.openapi.application.ApplicationManager; @@ -73,6 +71,15 @@ public class RollbackLineStatusAction extends DumbAwareAction { BitSet lines = new BitSet(totalLines + 1); List<Caret> carets = editor.getCaretModel().getAllCarets(); + + if (carets.size() == 1) { + Caret caret = carets.get(0); + if (caret.getSelectionStart() == 0 && caret.getSelectionEnd() == document.getTextLength()) { + doRollback(tracker); + return; + } + } + for (Caret caret : carets) { if (caret.hasSelection()) { int line1 = editor.offsetToLogicalPosition(caret.getSelectionStart()).line; @@ -107,6 +114,15 @@ public class RollbackLineStatusAction extends DumbAwareAction { }); } + private static void doRollback(@NotNull final LineStatusTracker tracker) { + execute(tracker, new Runnable() { + @Override + public void run() { + tracker.rollbackAllChanges(); + } + }); + } + private static void execute(@NotNull final LineStatusTracker tracker, @NotNull final Runnable task) { CommandProcessor.getInstance().executeCommand(tracker.getProject(), new Runnable() { public void run() { |