Commit 819c13f2 authored by Alexandru Băluț's avatar Alexandru Băluț Committed by Thibault Saunier

timeline: Avoid updating layers multiple times

The layers are updated when their priorities are in good order, in
__update_layers which is called also when the priority of a layer has
been changed.
Reviewed-by: Thibault Saunier's avatarThibault Saunier <tsaunier@gnome.org>
Differential Revision: https://phabricator.freedesktop.org/D1661
parent 7cf776c9
......@@ -904,7 +904,7 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
CommitTimelineFinalizingAction(pipeline)):
if self.__on_separators:
priority = self.separator_priority(self.__on_separators[1])
created_layer = self.createLayer(priority)
created_layer = self.create_layer(priority)
else:
created_layer = None
for layer, clip in self.__last_clips_on_leave:
......@@ -1001,6 +1001,21 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
for ges_layer in self.ges_timeline.get_layers():
self.__update_layer(ges_layer)
def __update_layer(self, ges_layer):
"""Sets the position of the layer and its controls in their parent."""
position = ges_layer.props.priority * 2 + 1
# Update the position of the LayerControls and Layer widgets and
# also the position of the separators below them.
controls_separator, layers_separator = self._separators[ges_layer.props.priority + 1]
vbox = self.layout.layers_vbox
vbox.child_set_property(ges_layer.ui, "position", position)
vbox.child_set_property(layers_separator, "position", position + 1)
vbox = self._layers_controls_vbox
vbox.child_set_property(ges_layer.control_ui, "position", position)
vbox.child_set_property(controls_separator, "position", position + 1)
def _remove_layer(self, ges_layer):
self.info("Removing layer: %s", ges_layer.props.priority)
self.layout.layers_vbox.remove(ges_layer.ui)
......@@ -1192,49 +1207,28 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
self.editing_context.edit_to(position, self._on_layer)
def createLayer(self, priority):
def create_layer(self, priority):
"""Adds a new layer to the GES timeline."""
self.debug("Creating layer: priority = %s", priority)
ges_layers = self.ges_timeline.get_layers()
assert 0 <= priority <= len(ges_layers)
new_ges_layer = GES.Layer.new()
new_ges_layer.props.priority = priority
self.ges_timeline.add_layer(new_ges_layer)
ges_layers = self.ges_timeline.get_layers()
if priority < len(ges_layers):
for ges_layer in ges_layers:
if ges_layer == new_ges_layer:
continue
if ges_layer.get_priority() >= priority:
ges_layer.props.priority += 1
self.__update_layer(ges_layer)
self.__update_layer(new_ges_layer)
for ges_layer in ges_layers:
if priority <= ges_layer.get_priority():
ges_layer.props.priority += 1
return new_ges_layer
def __update_layer(self, ges_layer):
"""Sets the position of the layer and its controls in their parent."""
position = ges_layer.props.priority * 2 + 1
# Update the position of the LayerControls and Layer widgets and
# also the position of the separators below them.
controls_separator, layers_separator = self._separators[ges_layer.props.priority + 1]
vbox = self.layout.layers_vbox
vbox.child_set_property(ges_layer.ui, "position", position)
vbox.child_set_property(layers_separator, "position", position + 1)
vbox = self._layers_controls_vbox
vbox.child_set_property(ges_layer.control_ui, "position", position)
vbox.child_set_property(controls_separator, "position", position + 1)
def dragEnd(self):
if self.editing_context:
self._snapEndedCb()
if self.__on_separators and self.__got_dragged and not self.__clickedHandle:
priority = self.separator_priority(self.__on_separators[1])
ges_layer = self.createLayer(priority)
ges_layer = self.create_layer(priority)
position = self.editing_context.new_position
self.editing_context.edit_to(position, ges_layer)
......
......@@ -88,7 +88,7 @@ class TestLayers(BaseTestTimeline):
# Allocate layers
y = 0
for priority, height in enumerate(heights):
ges_layer = timeline.createLayer(priority=priority)
ges_layer = timeline.create_layer(priority=priority)
rect = Gdk.Rectangle()
rect.y = y
rect.height = height
......@@ -159,7 +159,7 @@ class TestLayers(BaseTestTimeline):
timeline = create_timeline_container().timeline
ges_layers = []
for priority in start_priorities:
ges_layer = timeline.createLayer(priority)
ges_layer = timeline.create_layer(priority)
self.assertEqual(ges_layer.props.priority, priority)
ges_layers.append(ges_layer)
self.check_priorities_and_positions(timeline, ges_layers, expected_priorities)
......@@ -218,7 +218,7 @@ class TestLayers(BaseTestTimeline):
# Pitivi doesn't support removing the last remaining layer,
# that's why we create an extra layer.
for priority in range(len(removal_order) + 1):
ges_layer = timeline.createLayer(priority)
ges_layer = timeline.create_layer(priority)
ges_layers.append(ges_layer)
# Remove layers one by one in the specified order.
......@@ -243,7 +243,7 @@ class TestLayers(BaseTestTimeline):
# Add layers to move them later.
ges_layers = []
for priority in range(len(expected_priorities)):
ges_layer = timeline.createLayer(priority)
ges_layer = timeline.create_layer(priority)
ges_layers.append(ges_layer)
timeline.moveLayer(ges_layers[from_priority], to_priority)
......
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