[pitivi] undo: Ignore false property changes



commit a776562baf101de8c7be4eb860f3e836c3ea27f9
Author: Alexandru Băluț <alexandru balut gmail com>
Date:   Tue Oct 11 15:27:25 2016 +0200

    undo: Ignore false property changes
    
    GObjects emit notify::<property-name> when the property is set without
    checking if it has been changed.
    
    Reviewed-by: Thibault Saunier <tsaunier gnome org>
    Differential Revision: https://phabricator.freedesktop.org/D1379

 pitivi/undo/undo.py |    2 ++
 tests/test_undo.py  |   27 +++++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 0 deletions(-)
---
diff --git a/pitivi/undo/undo.py b/pitivi/undo/undo.py
index 8b8ae48..c5dcef2 100644
--- a/pitivi/undo/undo.py
+++ b/pitivi/undo/undo.py
@@ -427,6 +427,8 @@ class GObjectObserver(GObject.Object):
     def _property_changed_cb(self, gobject, pspec, property_name, field_name):
         old_value = self.properties[property_name]
         property_value = gobject.get_property(field_name)
+        if old_value == property_value:
+            return
         self.properties[property_name] = property_value
         action = PropertyChangedAction(gobject, field_name,
                                        old_value, property_value)
diff --git a/tests/test_undo.py b/tests/test_undo.py
index 27eb94f..68a4ed9 100644
--- a/tests/test_undo.py
+++ b/tests/test_undo.py
@@ -19,6 +19,9 @@
 from unittest import mock
 from unittest import TestCase
 
+from gi.repository import GES
+
+from pitivi.undo.undo import GObjectObserver
 from pitivi.undo.undo import UndoableAction
 from pitivi.undo.undo import UndoableActionLog
 from pitivi.undo.undo import UndoableActionStack
@@ -362,3 +365,27 @@ class TestUndoableActionLog(TestCase):
         order.assert_has_calls([mock.call.action3.undo(),
                                 mock.call.action2.undo(),
                                 mock.call.action1.undo()])
+
+
+class TestGObjectObserver(TestCase):
+
+    def test_property_change(self):
+        action_log = UndoableActionLog()
+        action_log.begin("complex stuff")
+        stack, = action_log.stacks
+
+        clip = GES.TitleClip()
+        unused_observer = GObjectObserver(clip, ["start"], action_log)
+
+        self.assertEqual(len(stack.done_actions), 0)
+        clip.props.start = 2
+        self.assertEqual(len(stack.done_actions), 1)
+
+        clip.props.start = 2
+        self.assertEqual(len(stack.done_actions), 1)
+
+        clip.props.start = 4
+        self.assertEqual(len(stack.done_actions), 2)
+        action = stack.done_actions[-1]
+        self.assertEqual(action.old_value, 2)
+        self.assertEqual(action.new_value, 4)


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