diff options
Diffstat (limited to 'platform/vcs-impl/src/com/intellij/openapi/vcs/ex/LineStatusTracker.java')
-rw-r--r-- | platform/vcs-impl/src/com/intellij/openapi/vcs/ex/LineStatusTracker.java | 83 |
1 files changed, 56 insertions, 27 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; |