[pitivi] undo: Avoid passing app to UndoableActionLog



commit bfa6090708416528de3e4dd5c166cf8759e7a4c5
Author: Alexandru Băluț <alexandru balut gmail com>
Date:   Tue Apr 26 13:08:24 2016 +0200

    undo: Avoid passing app to UndoableActionLog
    
    Differential Revision: https://phabricator.freedesktop.org/D964

 pitivi/application.py |   12 +++++++++++-
 pitivi/undo/undo.py   |   15 +++------------
 2 files changed, 14 insertions(+), 13 deletions(-)
---
diff --git a/pitivi/application.py b/pitivi/application.py
index c6a5e89..5d27292 100644
--- a/pitivi/application.py
+++ b/pitivi/application.py
@@ -264,7 +264,8 @@ class Pitivi(Gtk.Application, Loggable):
         self._setScenarioFile(project.get_uri())
 
     def _newProjectLoaded(self, unused_project_manager, project):
-        self.action_log = UndoableActionLog(self)
+        self.action_log = UndoableActionLog()
+        self.action_log.connect("pre-push", self._action_log_pre_push_cb)
         self.action_log.connect("commit", self._actionLogCommit)
         self.action_log.connect("undo", self._actionLogUndo)
         self.action_log.connect("redo", self._actionLogRedo)
@@ -353,6 +354,15 @@ class Pitivi(Gtk.Application, Loggable):
     def _redoCb(self, unused_action, unused_param):
         self.action_log.redo()
 
+    def _action_log_pre_push_cb(self, unused_action_log, action):
+        try:
+            st = action.asScenarioAction()
+        except NotImplementedError:
+            self.warning("No serialization method for action %s", action)
+            return
+        if st:
+            self.write_action(st)
+
     def _actionLogCommit(self, action_log, unused_stack):
         if action_log.is_in_transaction():
             return
diff --git a/pitivi/undo/undo.py b/pitivi/undo/undo.py
index c718c29..f8cb150 100644
--- a/pitivi/undo/undo.py
+++ b/pitivi/undo/undo.py
@@ -133,6 +133,7 @@ class UndoableActionLog(GObject.Object, Loggable):
 
     __gsignals__ = {
         "begin": (GObject.SIGNAL_RUN_LAST, None, (object,)),
+        "pre-push": (GObject.SIGNAL_RUN_LAST, None, (object,)),
         "push": (GObject.SIGNAL_RUN_LAST, None, (object, object)),
         "rollback": (GObject.SIGNAL_RUN_LAST, None, (object,)),
         "commit": (GObject.SIGNAL_RUN_LAST, None, (object,)),
@@ -140,14 +141,10 @@ class UndoableActionLog(GObject.Object, Loggable):
         "redo": (GObject.SIGNAL_RUN_LAST, None, (object,)),
     }
 
-    def __init__(self, app=None):
+    def __init__(self):
         GObject.Object.__init__(self)
         Loggable.__init__(self)
 
-        if app is not None:
-            self.app = weakref.proxy(app)
-        else:
-            self.app = None
         self.undo_stacks = []
         self.redo_stacks = []
         self.stacks = []
@@ -181,13 +178,7 @@ class UndoableActionLog(GObject.Object, Loggable):
         """
         Adds an action to the current transaction.
         """
-        if action is not None:
-            try:
-                st = action.asScenarioAction()
-                if self.app is not None and st is not None:
-                    self.app.write_action(st)
-            except NotImplementedError:
-                self.warning("No serialization method for that action")
+        self.emit("pre-push", action)
 
         if self.running:
             self.debug("Ignore push because running")


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