[pitivi] Add checkpoint() and dirty() to UndoableActionLog.
- From: Edward Hervey <edwardrv src gnome org>
- To: svn-commits-list gnome org
- Subject: [pitivi] Add checkpoint() and dirty() to UndoableActionLog.
- Date: Fri, 12 Jun 2009 12:34:51 -0400 (EDT)
commit 3f4186726709107ad6d1976e3fe00d00bd4fe312
Author: Alessandro Decina <alessandro d gmail com>
Date: Fri Jun 12 13:41:26 2009 +0200
Add checkpoint() and dirty() to UndoableActionLog.
The methods can be used to save the current state of the log and check if it's
been modified.
pitivi/undo.py | 14 ++++++++++++++
tests/test_undo.py | 21 +++++++++++++++++++++
2 files changed, 35 insertions(+), 0 deletions(-)
---
diff --git a/pitivi/undo.py b/pitivi/undo.py
index dfa3cfc..c2efc60 100644
--- a/pitivi/undo.py
+++ b/pitivi/undo.py
@@ -104,6 +104,7 @@ class UndoableActionLog(Signallable):
self.redo_stacks = []
self.stacks = []
self.running = False
+ self._checkpoint = self._takeSnapshot()
def begin(self, action_group_name):
if self.running:
@@ -185,6 +186,19 @@ class UndoableActionLog(Signallable):
self._runStack(stack, stack.clean)
self.emit("cleaned")
+ def _takeSnapshot(self):
+ return list(self.undo_stacks)
+
+ def checkpoint(self):
+ if self.stacks:
+ raise UndoWrongStateError()
+
+ self._checkpoint = self._takeSnapshot()
+
+ def dirty(self):
+ current_snapshot = self._takeSnapshot()
+ return current_snapshot != self._checkpoint
+
def _runStack(self, stack, run):
self.running = True
try:
diff --git a/tests/test_undo.py b/tests/test_undo.py
index 8db84f8..dbcad1a 100644
--- a/tests/test_undo.py
+++ b/tests/test_undo.py
@@ -178,6 +178,27 @@ class TestUndoableActionLog(TestCase):
def testRedoWrongState(self):
self.failUnlessRaises(UndoWrongStateError, self.log.redo)
+ def testCheckpoint(self):
+ self.log.begin("meh")
+ self.log.push(DummyUndoableAction())
+ self.failUnlessRaises(UndoWrongStateError, self.log.checkpoint)
+ self.log.rollback()
+ self.log.checkpoint()
+ self.failIfEqual(self.log._checkpoint, None)
+
+ def testDirty(self):
+ self.failIf(self.log.dirty())
+ self.log.begin("meh")
+ self.log.push(DummyUndoableAction())
+ self.log.commit()
+ self.failUnless(self.log.dirty())
+ self.log.checkpoint()
+ self.failIf(self.log.dirty())
+ self.log.undo()
+ self.failUnless(self.log.dirty())
+ self.log.redo()
+ self.failIf(self.log.dirty())
+
def testCommit(self):
"""
Commit a stack.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]