[pitivi] undo: Run the finalizing_action when the operation is committed
- From: Alexandru Băluț <alexbalut src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi] undo: Run the finalizing_action when the operation is committed
- Date: Thu, 6 Oct 2016 09:58:06 +0000 (UTC)
commit 2b33d6b6fa0bf919bd24cde5ab45d9e871862195
Author: Alexandru Băluț <alexandru balut gmail com>
Date: Wed Oct 5 01:30:45 2016 +0200
undo: Run the finalizing_action when the operation is committed
This way we make sure the same finalizing action is executed always.
This is the behaviour assumed by 967d73139cf445d44c4b4f14445eab38e06b1f80
Fixes https://phabricator.freedesktop.org/T7564
Reviewed-by: Thibault Saunier <tsaunier gnome org>
Differential Revision: https://phabricator.freedesktop.org/D1347
pitivi/undo/undo.py | 12 +++++++-----
tests/test_undo.py | 11 +++++++++++
2 files changed, 18 insertions(+), 5 deletions(-)
---
diff --git a/pitivi/undo/undo.py b/pitivi/undo/undo.py
index 625480e..8b8ae48 100644
--- a/pitivi/undo/undo.py
+++ b/pitivi/undo/undo.py
@@ -152,16 +152,17 @@ class UndoableActionStack(UndoableAction):
def do(self):
self._runAction(self.undone_actions, "do")
self.done_actions = self.undone_actions[::-1]
-
- if self.finalizing_action:
- self.finalizing_action.do()
+ self.finish_operation()
def undo(self):
self._runAction(self.done_actions, "undo")
self.undone_actions = self.done_actions[::-1]
+ self.finish_operation()
- if self.finalizing_action:
- self.finalizing_action.do()
+ def finish_operation(self):
+ if not self.finalizing_action:
+ return
+ self.finalizing_action.do()
class UndoableActionLog(GObject.Object, Loggable):
@@ -261,6 +262,7 @@ class UndoableActionLog(GObject.Object, Loggable):
return
if not self.stacks:
self.undo_stacks.append(stack)
+ stack.finish_operation()
else:
self.stacks[-1].push(stack)
diff --git a/tests/test_undo.py b/tests/test_undo.py
index f189fd8..27eb94f 100644
--- a/tests/test_undo.py
+++ b/tests/test_undo.py
@@ -201,6 +201,17 @@ class TestUndoableActionLog(TestCase):
self.assertEqual(len(self.log.undo_stacks), 1)
self.assertEqual(len(self.log.redo_stacks), 0)
+ def test_finalizing_action(self):
+ action1 = mock.Mock()
+ action2 = mock.Mock()
+ with self.log.started("one", finalizing_action=action1):
+ self.log.push(mock.Mock())
+ with self.log.started("two", finalizing_action=action2):
+ self.log.push(mock.Mock())
+ action1.do.assert_called_once_with()
+ # For now, we call the finalizing action only for the top stack.
+ action2.do.assert_not_called()
+
def testRollback(self):
"""
Test a rollback.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]