[pitivi] undo: Allow PropertyChangedActions to merge
- From: Thibault Saunier <tsaunier src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi] undo: Allow PropertyChangedActions to merge
- Date: Sun, 19 Feb 2017 23:48:56 +0000 (UTC)
commit 00e79c4fa52afeddcd33d900d0cf25fda0594088
Author: Alexandru Băluț <alexandru balut gmail com>
Date: Sat Feb 11 23:20:36 2017 +0100
undo: Allow PropertyChangedActions to merge
This is useful for example when dragging a clip, instead of recording
multiple actions representing each change of the clip's 'start', only
one is recorded (assuming no other actions interfere).
Reviewed-by: Thibault Saunier <tsaunier gnome org>
Differential Revision: https://phabricator.freedesktop.org/D1658
pitivi/undo/undo.py | 8 ++++++++
tests/test_undo.py | 24 ++++++++++++++++++++++--
2 files changed, 30 insertions(+), 2 deletions(-)
---
diff --git a/pitivi/undo/undo.py b/pitivi/undo/undo.py
index 845cbbd..1108804 100644
--- a/pitivi/undo/undo.py
+++ b/pitivi/undo/undo.py
@@ -403,6 +403,14 @@ class PropertyChangedAction(UndoableAutomaticObjectAction):
def undo(self):
self.auto_object.set_property(self.field_name, self.old_value)
+ def expand(self, action):
+ if not isinstance(action, PropertyChangedAction) or \
+ self.auto_object != action.auto_object or \
+ self.field_name != action.field_name:
+ return False
+ self.new_value = action.new_value
+ return True
+
class GObjectObserver(GObject.Object):
"""Monitor for GObject.Object's props, reporting UndoableActions.
diff --git a/tests/test_undo.py b/tests/test_undo.py
index 03b9b29..214bf7a 100644
--- a/tests/test_undo.py
+++ b/tests/test_undo.py
@@ -22,6 +22,7 @@ from unittest import TestCase
from gi.repository import GES
from pitivi.undo.undo import GObjectObserver
+from pitivi.undo.undo import PropertyChangedAction
from pitivi.undo.undo import UndoableAction
from pitivi.undo.undo import UndoableActionLog
from pitivi.undo.undo import UndoableActionStack
@@ -381,6 +382,7 @@ class TestGObjectObserver(TestCase):
stack, = action_log.stacks
clip = GES.TitleClip()
+ clip.props.start = 1
unused_observer = GObjectObserver(clip, ["start"], action_log)
self.assertEqual(len(stack.done_actions), 0)
@@ -391,7 +393,25 @@ class TestGObjectObserver(TestCase):
self.assertEqual(len(stack.done_actions), 1)
clip.props.start = 4
- self.assertEqual(len(stack.done_actions), 2)
+ self.assertEqual(len(stack.done_actions), 1)
action = stack.done_actions[-1]
- self.assertEqual(action.old_value, 2)
+ self.assertEqual(action.old_value, 1)
self.assertEqual(action.new_value, 4)
+
+
+class TestPropertyChangedAction(TestCase):
+
+ def test_expand(self):
+ stack = UndoableActionStack("good one!")
+ gobject = mock.Mock()
+ stack.push(PropertyChangedAction(gobject, "field", 5, 7))
+ stack.push(PropertyChangedAction(gobject, "field", 11, 13))
+ self.assertEqual(len(stack.done_actions), 1, stack.done_actions)
+ self.assertEqual(stack.done_actions[0].old_value, 5)
+ self.assertEqual(stack.done_actions[0].new_value, 13)
+
+ stack.push(PropertyChangedAction(gobject, "field2", 0, 1))
+ self.assertEqual(len(stack.done_actions), 2, stack.done_actions)
+
+ stack.push(PropertyChangedAction(mock.Mock(), "field", 0, 1))
+ self.assertEqual(len(stack.done_actions), 3, stack.done_actions)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]