[pitivi] timeline: Fix drag on separator does not create layer



commit c72e8c1fdc646b9ad5dfb1b121437e3b3ea21651
Author: Alexandru Băluț <alexandru balut gmail com>
Date:   Mon Jan 18 00:47:49 2016 +0100

    timeline: Fix drag on separator does not create layer
    
    Partially reverts 72fa2fdadd059956426f876bdae800b9ef25e295.
    Added comments to clarify sometimes we need to de-highlight the
    separators without forgetting them.
    
    Fixes https://phabricator.freedesktop.org/T3531
    
    Differential Revision: https://phabricator.freedesktop.org/D679

 pitivi/timeline/timeline.py     |   37 ++++++++++++++++++++-----------------
 tests/test_timeline_timeline.py |    9 ++++++++-
 2 files changed, 28 insertions(+), 18 deletions(-)
---
diff --git a/pitivi/timeline/timeline.py b/pitivi/timeline/timeline.py
index 41f6a11..cf9f8d3 100644
--- a/pitivi/timeline/timeline.py
+++ b/pitivi/timeline/timeline.py
@@ -671,7 +671,7 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
         elif self.__moving_layer:
             event_widget = self.get_event_widget(event)
             unused_x, y = event_widget.translate_coordinates(self, event.x, event.y)
-            layer, unused_on_sep = self.__getLayerAt(
+            layer, unused_on_sep = self._getLayerAt(
                 y, prefer_bLayer=self.__moving_layer, past_middle_when_adjacent=True)
             if layer != self.__moving_layer:
                 priority = layer.get_priority()
@@ -739,7 +739,7 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
             else:
                 clip_duration = asset.get_duration()
 
-            bLayer, unused_on_sep = self.__getLayerAt(y)
+            bLayer, unused_on_sep = self._getLayerAt(y)
             if not placement:
                 placement = self.pixelToNs(x)
             placement = max(0, placement)
@@ -780,7 +780,10 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
         return True
 
     def __dragLeaveCb(self, unused_widget, unused_context, unused_timestamp):
-        self.__unsetHoverSeparators()
+        # De-highlight the separators. We still need to remember them.
+        # See how __on_separators is used in __dragDropCb for details
+        self._setSeparatorsPrelight(False)
+
         if self.draggingElement:
             self.__last_clips_on_leave = [(clip.get_layer(), clip)
                                           for clip in self.current_group.get_children(False)]
@@ -947,7 +950,8 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
     def __layerGetSeps(self, bLayer, sep_name):
         return [getattr(bLayer.ui, sep_name), getattr(bLayer.control_ui, sep_name)]
 
-    def __getLayerAt(self, y, prefer_bLayer=None, past_middle_when_adjacent=False):
+    def _getLayerAt(self, y, prefer_bLayer=None, past_middle_when_adjacent=False):
+        """ Used in the testsuite """
         bLayers = self.bTimeline.get_layers()
         if y < 20:
             # The cursor is at the top, above the first layer.
@@ -1001,15 +1005,13 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
                 self.debug("Returning layer %s, separators: %s", bLayer, separators)
                 return bLayer, separators
 
-    def __setHoverSeparators(self, separators):
-        self.__on_separators = separators
-        for sep in self.__on_separators:
-            set_children_state_recurse(sep, Gtk.StateFlags.PRELIGHT)
-
-    def __unsetHoverSeparators(self):
+    def _setSeparatorsPrelight(self, light):
+        """ Used in the testsuite """
         for sep in self.__on_separators:
-            unset_children_state_recurse(sep, Gtk.StateFlags.PRELIGHT)
-        self.__on_separators = []
+            if light:
+                set_children_state_recurse(sep, Gtk.StateFlags.PRELIGHT)
+            else:
+                unset_children_state_recurse(sep, Gtk.StateFlags.PRELIGHT)
 
     def __dragUpdate(self, event_widget, x, y):
         if not self.draggingElement:
@@ -1044,15 +1046,15 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
         else:
             position = self.pixelToNs(x - self.__drag_start_x)
 
-        self.__unsetHoverSeparators()
-        self._on_layer, on_separators = self.__getLayerAt(y,
-                                                          prefer_bLayer=self._on_layer)
+        self._setSeparatorsPrelight(False)
+        res = self._getLayerAt(y, prefer_bLayer=self._on_layer)
+        self._on_layer, self.__on_separators = res
         if (mode != GES.EditMode.EDIT_NORMAL or
                 self.current_group.props.height > 1):
             # When dragging clips from more than one layer, do not allow
             # them to be dragged between layers to create a new layer.
             on_separators = []
-        self.__setHoverSeparators(on_separators)
+        self._setSeparatorsPrelight(True)
 
         priority = self._on_layer.props.priority
         self.editing_context.editTo(position, priority)
@@ -1120,7 +1122,8 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
         for layer in self.bTimeline.get_layers():
             layer.ui.checkMediaTypes()
 
-        self.__unsetHoverSeparators()
+        self._setSeparatorsPrelight(False)
+        self.__on_separators = []
 
         self.queue_draw()
 
diff --git a/tests/test_timeline_timeline.py b/tests/test_timeline_timeline.py
index ffba28a..b1383e6 100644
--- a/tests/test_timeline_timeline.py
+++ b/tests/test_timeline_timeline.py
@@ -118,7 +118,7 @@ class TestLayers(BaseTestTimeline):
         s = SEPARATOR_HEIGHT
 
         def assertLayerAt(bLayer, y):
-            result = timeline._Timeline__getLayerAt(
+            result = timeline._getLayerAt(
                 int(y),
                 prefer_bLayer=preferred_bLayer,
                 past_middle_when_adjacent=past_middle_when_adjacent)
@@ -153,6 +153,13 @@ class TestLayers(BaseTestTimeline):
         assertLayerAt(bLayers[expectations[14]], h[0] + s + h[1] + s + h[2] / 2)
         assertLayerAt(bLayers[expectations[15]], h[0] + s + h[1] + s + h[2] - 1)
 
+    def testSetSeparatorsPrelight(self):
+        timeline = self.createTimeline()
+        timeline.__on_separators = [mock.Mock()]
+        timeline._setSeparatorsPrelight(False)
+        self.assertEqual(len(timeline.__on_separators), 1,
+                         "The separators must be forgotten only in dragEnd()")
+
 
 class TestGrouping(BaseTestTimeline):
     def groupClips(self, num_clips):


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