[pitivi] timeline: Simplify the layer creation code



commit 9902c337346c7bb972ab36f8368167968d5a276c
Author: Thibault Saunier <tsaunier gnome org>
Date:   Fri Sep 4 12:34:20 2015 +0200

    timeline: Simplify the layer creation code
    
    And make sure that new layers are created when drag and dropping
    between two layers from the media library

 pitivi/timeline/timeline.py |   32 +++++++++++++++++++-------------
 1 files changed, 19 insertions(+), 13 deletions(-)
---
diff --git a/pitivi/timeline/timeline.py b/pitivi/timeline/timeline.py
index b114b25..520854e 100644
--- a/pitivi/timeline/timeline.py
+++ b/pitivi/timeline/timeline.py
@@ -779,9 +779,12 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
                 self.dropData = None
                 self.dropDataReady = False
 
+                created_layer = None
                 for layer, clip in self.__last_clips_on_leave:
-                    if self.__on_separators:
-                        layer = self.__getDroppedLayer(True)
+                    if self.__on_separators and not created_layer:
+                        created_layer = self.__getDroppedLayer()
+                    if created_layer:
+                        layer = created_layer
                     layer.add_clip(clip)
 
                 if zoom_was_fitted:
@@ -1033,18 +1036,20 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
 
         return new_bLayer
 
-    def __getDroppedLayer(self, dropping):
+    def __getDroppedLayer(self):
+        """
+        Get the layer to which the clip should land, creating
+        layer as necessary.
+
+        If always_create_layer is True, a new layer with proper
+        priority will be created, otherwize it will try to retrieve
+        the layer at the priority and create only if it does not
+        exist
+        """
         priority = self._on_layer.props.priority
         if self.__on_separators[0] == self._on_layer.ui.after_sep:
             priority = self._on_layer.props.priority + 1
 
-        self.debug("On separator --> %s" % priority)
-        if dropping:
-            try:
-                return self.bTimeline.get_layers()[priority]
-            except IndexError:
-                pass
-
         self.createLayer(max(0, priority))
         return self.bTimeline.get_layers()[priority]
 
@@ -1052,9 +1057,10 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
         if (self.draggingElement is not None and self.__got_dragged) or dropping:
             self._snapEndedCb()
 
-            if self.__on_separators:
-                priority = self.__getDroppedLayer(dropping).get_priority()
-                self.editing_context.editTo(self.editing_context.new_position, priority)
+            if self.__on_separators and not dropping:
+                layer = self.__getDroppedLayer()
+                self.editing_context.editTo(self.editing_context.new_position,
+                                            layer.get_priority())
             self.layout.props.width = self._computeTheoricalWidth()
 
             self.editing_context.finish()


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