[pitivi] Pass the name of the action group to UndoableActionLog.begin.



commit e60bc558cdbf1502651df2b8fef949f77d244090
Author: Alessandro Decina <alessandro d gmail com>
Date:   Wed Jun 10 11:46:16 2009 +0200

    Pass the name of the action group to UndoableActionLog.begin.

 pitivi/undo.py     |   38 +++++++++++++++++++++++++++++++++++---
 tests/test_undo.py |   26 +++++++++++++-------------
 2 files changed, 48 insertions(+), 16 deletions(-)
---
diff --git a/pitivi/undo.py b/pitivi/undo.py
index dfd3aa4..fec4ce3 100644
--- a/pitivi/undo.py
+++ b/pitivi/undo.py
@@ -20,6 +20,7 @@
 # Boston, MA 02111-1307, USA.
 
 from pitivi.signalinterface import Signallable
+from pitivi.log.loggable import Loggable
 
 class UndoError(Exception):
     pass
@@ -57,7 +58,8 @@ class UndoableActionStack(UndoableAction):
         "error": ["exception"],
     }
 
-    def __init__(self):
+    def __init__(self, action_group_name):
+        self.action_group_name = action_group_name
         self.done_actions = []
         self.undone_actions = []
         self.actions = []
@@ -144,8 +146,8 @@ class UndoableActionLog(Signallable):
         self.redo_stacks = []
         self.stacks = []
 
-    def begin(self):
-        stack = UndoableActionStack()
+    def begin(self, action_group_name):
+        stack = UndoableActionStack(action_group_name)
         nested = self._stackIsNested(stack)
         self.stacks.append(stack)
         self.emit("begin", stack, nested)
@@ -214,3 +216,33 @@ class UndoableActionLog(Signallable):
 
     def _error(self, exception):
         self.emit("error", exception)
+
+class DebugActionLogObserver(Loggable):
+    def startObserving(self, log):
+        self._connectToActionLog(log)
+
+    def stopObserving(self, log):
+        self._disconnectFromActionLog(log)
+
+    def _connectToActionLog(self, log):
+        log.connect("begin", self._actionLogBeginCb)
+        log.connect("commit", self._actionLogCommitCb)
+        log.connect("rollback", self._actionLogRollbackCb)
+        log.connect("push", self._actionLogPushCb)
+
+    def _disconnectFromActionLog(self, log):
+        for method in (self._actionLogBeginCb, self._actionLogCommitCb,
+                self._actionLogrollbackCb, self._actionLogPushCb):
+            log.disconnect_by_func(method)
+
+    def _actionLogBeginCb(self, log, stack, nested):
+        self.debug("begin action nested: %s", nested)
+
+    def _actionLogCommitCb(self, log, stack, nested):
+        self.debug("commit action nested: %s", nested)
+
+    def _actionLogRollbackCb(self, log, stack, nested):
+        self.debug("rollback action nested: %s", nested)
+
+    def _actionLogPushCb(self, log, action):
+        self.debug("push %s", action)
diff --git a/tests/test_undo.py b/tests/test_undo.py
index e36977c..de71b75 100644
--- a/tests/test_undo.py
+++ b/tests/test_undo.py
@@ -64,7 +64,7 @@ class TestUndoableActionStack(TestCase):
         def doneCb(action, value):
             state["done"] = value
 
-        stack = UndoableActionStack()
+        stack = UndoableActionStack("meh")
         stack.connect("done", doneCb, True)
         stack.connect("undone", doneCb, False)
 
@@ -92,7 +92,7 @@ class TestUndoableActionStack(TestCase):
                 state["actions"] -= 1
                 self._undone()
 
-        stack = UndoableActionStack()
+        stack = UndoableActionStack("meh")
         stack.connect("done", doneCb, True)
         stack.connect("undone", doneCb, False)
         action1 = Action()
@@ -131,7 +131,7 @@ class TestUndoableActionStack(TestCase):
             def undo_fail(self):
                 self._error(UndoError("boom"))
 
-        stack = UndoableActionStack()
+        stack = UndoableActionStack("meh")
         stack.connect("done", doneCb)
         stack.connect("error", errorCb)
         action1 = Action()
@@ -168,7 +168,7 @@ class TestUndoableActionStack(TestCase):
             def undo_fail(self):
                 raise Exception("boom")
 
-        stack = UndoableActionStack()
+        stack = UndoableActionStack("meh")
         stack.connect("undone", doneCb, False)
         stack.connect("error", errorCb)
         action1 = Action()
@@ -245,7 +245,7 @@ class TestUndoableActionLog(TestCase):
         """
         self.failUnlessEqual(len(self.log.undo_stacks), 0)
         self.failUnlessEqual(len(self.log.redo_stacks), 0)
-        self.log.begin()
+        self.log.begin("meh")
         self.failUnlessEqual(len(self.signals), 1)
         name, (stack, nested) = self.signals[0]
         self.failUnlessEqual(name, "begin")
@@ -266,7 +266,7 @@ class TestUndoableActionLog(TestCase):
         """
         self.failUnlessEqual(len(self.log.undo_stacks), 0)
         self.failUnlessEqual(len(self.log.redo_stacks), 0)
-        self.log.begin()
+        self.log.begin("meh")
         self.failUnlessEqual(len(self.signals), 1)
         name, (stack, nested) = self.signals[0]
         self.failUnlessEqual(name, "begin")
@@ -274,7 +274,7 @@ class TestUndoableActionLog(TestCase):
 
         self.failUnlessEqual(len(self.log.undo_stacks), 0)
         self.failUnlessEqual(len(self.log.redo_stacks), 0)
-        self.log.begin()
+        self.log.begin("nested")
         self.failUnlessEqual(len(self.signals), 2)
         name, (stack, nested) = self.signals[1]
         self.failUnlessEqual(name, "begin")
@@ -304,7 +304,7 @@ class TestUndoableActionLog(TestCase):
         """
         self.failUnlessEqual(len(self.log.undo_stacks), 0)
         self.failUnlessEqual(len(self.log.redo_stacks), 0)
-        self.log.begin()
+        self.log.begin("meh")
         self.failUnlessEqual(len(self.signals), 1)
         name, (stack, nested) = self.signals[0]
         self.failUnlessEqual(name, "begin")
@@ -324,7 +324,7 @@ class TestUndoableActionLog(TestCase):
         """
         self.failUnlessEqual(len(self.log.undo_stacks), 0)
         self.failUnlessEqual(len(self.log.redo_stacks), 0)
-        self.log.begin()
+        self.log.begin("meh")
         self.failUnlessEqual(len(self.signals), 1)
         name, (stack, nested) = self.signals[0]
         self.failUnlessEqual(name, "begin")
@@ -332,7 +332,7 @@ class TestUndoableActionLog(TestCase):
 
         self.failUnlessEqual(len(self.log.undo_stacks), 0)
         self.failUnlessEqual(len(self.log.redo_stacks), 0)
-        self.log.begin()
+        self.log.begin("nested")
         self.failUnlessEqual(len(self.signals), 2)
         name, (stack, nested) = self.signals[1]
         self.failUnlessEqual(name, "begin")
@@ -359,7 +359,7 @@ class TestUndoableActionLog(TestCase):
         Try an undo() redo() sequence.
         """
         # begin
-        self.log.begin()
+        self.log.begin("meh")
         self.failUnlessEqual(len(self.signals), 1)
         name, (stack, nested) = self.signals[0]
         self.failUnlessEqual(name, "begin")
@@ -437,9 +437,9 @@ class TestUndoableActionLog(TestCase):
         action2 = Action(2)
         action3 = Action(3)
 
-        self.log.begin()
+        self.log.begin("meh")
         self.log.push(action1)
-        self.log.begin()
+        self.log.begin("nested")
         self.log.push(action2)
         self.log.commit()
         self.log.push(action3)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]