Commit 16927e16 authored by Stefan Popa's avatar Stefan Popa Committed by Alexandru Băluț

timeline: Allow undoing a paste operation

When pasting a copied clip, the undo button behaves as if the paste
operation didn't take place (i.e. it undoes the operation previous to
the paste operation).

To fix this, I logged the paste operation in the action_log.

Fixes https://phabricator.freedesktop.org/T7688

Differential Revision: https://phabricator.freedesktop.org/D1678
parent cc57ff06
......@@ -1656,12 +1656,16 @@ class TimelineContainer(Gtk.Grid, Zoomable, Loggable):
self.updateActions()
def __pasteClipsCb(self, unused_action, unused_parameter):
if self.__copiedGroup:
if not self.__copiedGroup:
self.info("Nothing to paste.")
return
with self.app.action_log.started("paste",
CommitTimelineFinalizingAction(self._project.pipeline)):
save = self.__copiedGroup.copy(True)
position = self._project.pipeline.getPosition()
self.__copiedGroup.paste(position)
self.__copiedGroup = save
self._project.pipeline.commit_timeline()
def _alignSelectedCb(self, unused_action, unused_parameter):
if not self.ges_timeline:
......
......@@ -585,6 +585,40 @@ class TestLayerObserver(BaseTestUndoTimeline):
self.action_log.redo()
self.assertIsNotNone(self.get_transition_element(self.layer))
def test_paste_undo(self):
"""Checks a paste operation can be undone."""
self.setup_timeline_container()
timeline = self.timeline_container.timeline
project = timeline.ges_timeline.get_asset()
# Create test clip
clip = common.create_test_clip(GES.TitleClip)
clip.props.start = 0
clip.props.duration = 10
self.layer.add_clip(clip)
self.assertEqual(len(self.layer.get_clips()), 1)
# Select the test clip
event = mock.Mock()
event.get_button.return_value = (True, 1)
with mock.patch.object(Gtk, "get_event_widget") as get_event_widget:
get_event_widget.return_value = clip.ui
clip.ui.timeline._button_press_event_cb(None, event)
clip.ui._button_release_event_cb(None, event)
self.timeline_container.copy_action.emit("activate", None)
position = 10
project.pipeline.getPosition = mock.Mock(return_value=position)
self.timeline_container.paste_action.emit("activate", None)
self.assertEqual(len(self.layer.get_clips()), 2)
self.action_log.undo()
self.assertEqual(len(self.layer.get_clips()), 1)
self.action_log.redo()
self.assertEqual(len(self.layer.get_clips()), 2)
class TestControlSourceObserver(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