[pitivi] timeline: Avoid creating new layer when trimming



commit 4d4e644cd885dab66f8fd7b71793dd5ee9eeb050
Author: Alexandru Băluț <alexandru balut gmail com>
Date:   Mon Oct 3 15:43:18 2016 +0200

    timeline: Avoid creating new layer when trimming
    
    Fixes https://phabricator.freedesktop.org/T7568
    
    Reviewed-by: Thibault Saunier <tsaunier gnome org>
    Differential Revision: https://phabricator.freedesktop.org/D1343

 pitivi/timeline/timeline.py     |    6 +++++-
 tests/test_timeline_timeline.py |   38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+), 1 deletions(-)
---
diff --git a/pitivi/timeline/timeline.py b/pitivi/timeline/timeline.py
index fdaadb3..e7e542b 100644
--- a/pitivi/timeline/timeline.py
+++ b/pitivi/timeline/timeline.py
@@ -269,8 +269,12 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
         self.layout.put(self.__marquee, 0, 0)
 
         # Clip editing.
+        # Which clip is being edited.
         self.draggingElement = None
+        # Which handle of the draggingElement has been clicked, if any.
+        # If set, it means we are in a trim operation.
         self.__clickedHandle = None
+        # The GES object for controlling the operation.
         self.editing_context = None
         # Whether draggingElement really got dragged.
         self.__got_dragged = False
@@ -1122,7 +1126,7 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
         if self.editing_context:
             self._snapEndedCb()
 
-            if self.__on_separators and self.__got_dragged:
+            if self.__on_separators and self.__got_dragged and not self.__clickedHandle:
                 layer = self.__getDroppedLayer()
                 self.editing_context.editTo(self.editing_context.new_position,
                                             layer.get_priority())
diff --git a/tests/test_timeline_timeline.py b/tests/test_timeline_timeline.py
index d492180..0a5bb55 100644
--- a/tests/test_timeline_timeline.py
+++ b/tests/test_timeline_timeline.py
@@ -35,6 +35,7 @@ THICK = ui.LAYER_HEIGHT
 
 
 class BaseTestTimeline(common.TestCase):
+
     def createTimeline(self):
         app = common.create_pitivi_mock()
         project_manager = ProjectManager(app)
@@ -63,6 +64,7 @@ class BaseTestTimeline(common.TestCase):
 
 
 class TestLayers(BaseTestTimeline):
+
     def testDraggingLayer(self):
         self.checkGetLayerAt([THIN, THIN, THIN], 1, True,
                              [0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2])
@@ -158,6 +160,7 @@ class TestLayers(BaseTestTimeline):
 
 
 class TestGrouping(BaseTestTimeline):
+
     def groupClips(self, num_clips):
         timeline = self.createTimeline()
         timeline.app.settings.leftClickAlsoSeeks = False
@@ -296,6 +299,7 @@ class TestGrouping(BaseTestTimeline):
 
 
 class TestCopyPaste(BaseTestTimeline):
+
     def copyClips(self, num_clips):
         timeline = self.createTimeline()
 
@@ -338,3 +342,37 @@ class TestCopyPaste(BaseTestTimeline):
         self.assertEqual(len(copied_clips), 2)
         self.assertEqual(copied_clips[0].props.start, position)
         self.assertEqual(copied_clips[1].props.start, position + 10)
+
+
+class TestEditing(BaseTestTimeline):
+
+    def test_trimming_on_layer_separator(self):
+        # Create a clip
+        timeline = self.createTimeline()
+        clip, = self.addClipsSimple(timeline, 1)
+        layer = clip.get_layer()
+
+        # Click the right trim handle of the clip.
+        with mock.patch.object(timeline, 'get_event_widget') as get_event_widget:
+            event = mock.Mock()
+            event.get_button.return_value = True, 1
+            get_event_widget.return_value = clip.ui.rightHandle
+            timeline._button_press_event_cb(None, event)
+            self.assertIsNotNone(timeline.draggingElement)
+
+            # Drag it to the left, on the separator below.
+            event = mock.Mock()
+            event.get_state.return_value = Gdk.ModifierType.BUTTON1_MASK
+            with mock.patch.object(clip.ui.rightHandle, "translate_coordinates") as translate_coordinates:
+                translate_coordinates.return_value = (0, 0)
+                with mock.patch.object(timeline, "_get_layer_at") as _get_layer_at:
+                    _get_layer_at.return_value = layer, [layer.ui.after_sep]
+                    timeline._motion_notify_event_cb(None, event)
+            self.assertTrue(timeline.got_dragged)
+
+        # Release the mouse button.
+        event = mock.Mock()
+        event.get_button.return_value = True, 1
+        timeline._button_release_event_cb(None, event)
+        self.assertEqual(len(timeline.ges_timeline.get_layers()), 1,
+                         "No new layer should have been created")


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