[pitivi] undo: Separate MetaContainerObserver out of ProjectObserver



commit c0069821db869111a4f9b735772f569bd75486b3
Author: Alexandru Băluț <alexandru balut gmail com>
Date:   Tue May 3 01:42:01 2016 +0200

    undo: Separate MetaContainerObserver out of ProjectObserver
    
    Differential Revision: https://phabricator.freedesktop.org/D986

 pitivi/application.py  |    3 +--
 pitivi/undo/project.py |   46 ++++++----------------------------------------
 pitivi/undo/undo.py    |   45 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 52 insertions(+), 42 deletions(-)
---
diff --git a/pitivi/application.py b/pitivi/application.py
index 647d040..915df95 100644
--- a/pitivi/application.py
+++ b/pitivi/application.py
@@ -273,8 +273,7 @@ class Pitivi(Gtk.Application, Loggable):
         timeline_observer = TimelineObserver(self.action_log, app=self)
         timeline_observer.startObserving(project.timeline)
 
-        project_observer = ProjectObserver(self.action_log)
-        project_observer.startObserving(project)
+        project_observer = ProjectObserver(project, self.action_log)
 
     def _projectClosed(self, unused_project_manager, project):
         if project.loaded:
diff --git a/pitivi/undo/project.py b/pitivi/undo/project.py
index 21859c5..aa2f56e 100644
--- a/pitivi/undo/project.py
+++ b/pitivi/undo/project.py
@@ -21,6 +21,7 @@
 from gi.repository import GObject
 from gi.repository import Gst
 
+from pitivi.undo.undo import MetaContainerObserver
 from pitivi.undo.undo import UndoableAction
 
 
@@ -66,53 +67,18 @@ class AssetRemovedAction(UndoableAction):
         return st
 
 
-class MetaChangedAction(UndoableAction):
-
-    def __init__(self, meta_container, item, current_value, new_value):
-        UndoableAction.__init__(self)
-        self.meta_container = meta_container
-        self.item = item
-        self.old_value = current_value
-        self.new_value = new_value
-
-    def do(self):
-        self.meta_container.set_meta(self.item, self.new_value)
-
-    def undo(self):
-        self.meta_container.set_meta(self.item, self.old_value)
-
-
-class ProjectObserver():
+class ProjectObserver(MetaContainerObserver):
     """Monitors a project instance and reports UndoableActions.
 
-    Attributes:
-        action_log (UndoableActionLog): The action log where to report actions.
+    Args:
+        project (Project): The project to be monitored.
     """
 
-    def __init__(self, action_log):
-        self.action_log = action_log
-
-    def startObserving(self, project):
-        """Starts monitoring the specified Project.
-
-        Args:
-            project (Project): The project to be monitored.
-        """
-        self.metas = {}
-        def set_meta(project, item, value):
-            self.metas[item] = value
-        project.foreach(set_meta)
-
-        project.connect("notify-meta", self._settingsChangedCb)
+    def __init__(self, project, action_log):
+        MetaContainerObserver.__init__(self, project, action_log)
         project.connect("asset-added", self._assetAddedCb)
         project.connect("asset-removed", self._assetRemovedCb)
 
-    def _settingsChangedCb(self, project, item, value):
-        current_value = self.metas.get(item)
-        action = MetaChangedAction(project, item, current_value, value)
-        self.metas[item] = value
-        self.action_log.push(action)
-
     def _assetAddedCb(self, project, asset):
         action = AssetAddedAction(project, asset)
         self.action_log.push(action)
diff --git a/pitivi/undo/undo.py b/pitivi/undo/undo.py
index a9b3e33..63dce16 100644
--- a/pitivi/undo/undo.py
+++ b/pitivi/undo/undo.py
@@ -298,6 +298,51 @@ class UndoableActionLog(GObject.Object, Loggable):
         return bool(self.stacks)
 
 
+class MetaChangedAction(UndoableAction):
+
+    def __init__(self, meta_container, item, current_value, new_value):
+        UndoableAction.__init__(self)
+        self.meta_container = meta_container
+        self.item = item
+        self.old_value = current_value
+        self.new_value = new_value
+
+    def do(self):
+        self.meta_container.set_meta(self.item, self.new_value)
+
+    def undo(self):
+        self.meta_container.set_meta(self.item, self.old_value)
+
+
+class MetaContainerObserver(GObject.Object):
+    """
+    Monitors a MetaContainer's changes.
+
+    Args:
+        meta_container (GES.MetaContainer): The object to be monitored.
+
+    Attributes:
+        action_log (UndoableActionLog): The action log where to report actions.
+    """
+
+    def __init__(self, meta_container, action_log):
+        self.action_log = action_log
+
+        self.metas = {}
+
+        def set_meta(unused_meta_container, item, value):
+            self.metas[item] = value
+        meta_container.foreach(set_meta)
+
+        meta_container.connect("notify-meta", self._notify_meta_cb)
+
+    def _notify_meta_cb(self, meta_container, item, value):
+        current_value = self.metas.get(item)
+        action = MetaChangedAction(meta_container, item, current_value, value)
+        self.metas[item] = value
+        self.action_log.push(action)
+
+
 class PropertyChangeTracker(GObject.Object):
     """
     Monitors a GObject.Object's props and reports UndoableActions.


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