Commit d614b647 authored by Alexandru Băluț's avatar Alexandru Băluț

undo: Fix effect priority changed when re-added.

Fixes #2246
parent 19a78e55
Pipeline #40182 passed with stages
in 51 minutes and 12 seconds
......@@ -212,7 +212,11 @@ class TrackElementRemoved(TrackElementAction):
self.remove()
def undo(self):
# Set the priority it had when it was last removed from self.clip,
# because re-adding it can change it, for example if it's an effect.
priority = self.track_element.props.priority
self.add()
self.track_element.props.priority = priority
def asScenarioAction(self):
st = Gst.Structure.new_empty("container-remove-child")
......
......@@ -735,6 +735,19 @@ class TestControlSourceObserver(BaseTestUndoTimeline):
class TestTrackElementObserver(BaseTestUndoTimeline):
def assert_effects(self, clip, *effects):
# Make sure there are no other effects.
actual_effects = set()
for track_element in clip.get_children(recursive=True):
if isinstance(track_element, GES.BaseEffect):
actual_effects.add(track_element)
self.assertEqual(actual_effects, set(effects))
# Make sure their order is correct.
indexes = [clip.get_top_effect_index(effect)
for effect in effects]
self.assertEqual(indexes, list(range(len(effects))))
def test_effects_index(self):
stacks = []
self.action_log.connect("commit", BaseTestUndoTimeline.commit_cb, stacks)
......@@ -746,24 +759,75 @@ class TestTrackElementObserver(BaseTestUndoTimeline):
effect2 = GES.Effect.new("edgetv")
clip1.add(effect1)
clip1.add(effect2)
self.assertEqual(clip1.get_top_effect_index(effect1), 0)
self.assertEqual(clip1.get_top_effect_index(effect2), 1)
self.assert_effects(clip1, effect1, effect2)
with self.action_log.started("move effect"):
assert clip1.set_top_effect_index(effect2, 0)
self.assertEqual(len(stacks), 1)
self.assert_effects(clip1, effect2, effect1)
self.action_log.undo()
self.assert_effects(clip1, effect1, effect2)
self.action_log.redo()
self.assert_effects(clip1, effect2, effect1)
self.assertEqual(clip1.get_top_effect_index(effect1), 1)
self.assertEqual(clip1.get_top_effect_index(effect2), 0)
def test_effects_index_with_removal(self):
stacks = []
self.action_log.connect("commit", BaseTestUndoTimeline.commit_cb, stacks)
clip1 = GES.TitleClip()
self.layer.add_clip(clip1)
effect1 = GES.Effect.new("agingtv")
effect2 = GES.Effect.new("dicetv")
effect3 = GES.Effect.new("edgetv")
with self.action_log.started("Add effect1"):
clip1.add(effect1)
with self.action_log.started("Add effect2"):
clip1.add(effect2)
with self.action_log.started("Add effect3"):
clip1.add(effect3)
self.assert_effects(clip1, effect1, effect2, effect3)
self.action_log.undo()
self.assertEqual(clip1.get_top_effect_index(effect1), 0)
self.assertEqual(clip1.get_top_effect_index(effect2), 1)
self.assert_effects(clip1, effect1, effect2)
self.action_log.redo()
self.assert_effects(clip1, effect1, effect2, effect3)
with self.action_log.started("Remove effect"):
assert clip1.remove(effect2)
self.assertEqual(len(stacks), 4)
self.assert_effects(clip1, effect1, effect3)
self.action_log.undo()
self.assert_effects(clip1, effect1, effect2, effect3)
self.action_log.redo()
self.assert_effects(clip1, effect1, effect3)
self.action_log.undo()
self.assert_effects(clip1, effect1, effect2, effect3)
self.action_log.undo()
self.assert_effects(clip1, effect1, effect2)
self.action_log.undo()
self.assert_effects(clip1, effect1)
self.action_log.undo()
self.assert_effects(clip1)
self.action_log.redo()
self.assert_effects(clip1, effect1)
self.action_log.redo()
self.assert_effects(clip1, effect1, effect2)
self.action_log.redo()
self.assert_effects(clip1, effect1, effect2, effect3)
self.action_log.redo()
self.assert_effects(clip1, effect1, effect3)
self.action_log.undo()
self.assert_effects(clip1, effect1, effect2, effect3)
self.action_log.redo()
self.assertEqual(clip1.get_top_effect_index(effect1), 1)
self.assertEqual(clip1.get_top_effect_index(effect2), 0)
self.assert_effects(clip1, effect1, effect3)
class TestTimelineElementObserver(BaseTestUndoTimeline):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment