[pitivi] timeline: Fix selection appearance when moving clip



commit 98975a78c2d000f768bfdf08290425e085409ac3
Author: Alexandru Băluț <alexandru balut gmail com>
Date:   Wed Feb 2 23:27:36 2022 +0100

    timeline: Fix selection appearance when moving clip
    
    When moving a clip to a different layer, the clip widget is recreated
    and the selected status was not being restored.
    
    Fixes #2579

 .pre-commit-config.yaml         |  1 +
 pitivi/timeline/elements.py     |  4 ++++
 pitivi/timeline/timeline.py     |  2 ++
 tests/test_timeline_elements.py | 23 ++++++++++++++++++++++-
 4 files changed, 29 insertions(+), 1 deletion(-)
---
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index b1446e4e5..f37ddefee 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -1,4 +1,5 @@
 ---
+fail_fast: true
 repos:
   - repo: https://github.com/pre-commit/pre-commit-hooks.git
     rev: v4.0.1
diff --git a/pitivi/timeline/elements.py b/pitivi/timeline/elements.py
index 797388686..68de823eb 100644
--- a/pitivi/timeline/elements.py
+++ b/pitivi/timeline/elements.py
@@ -1195,6 +1195,7 @@ class Clip(Gtk.EventBox, Zoomable, Loggable):
         self.ges_clip = ges_clip
         self.ges_clip.ui = self
         self.ges_clip.selected = Selected()
+        self.ges_clip.selected.selected = self.ges_clip in self.timeline.selection
 
         self.audio_widget = None
         self.video_widget = None
@@ -1206,6 +1207,8 @@ class Clip(Gtk.EventBox, Zoomable, Loggable):
             self._add_child(ges_timeline_element)
             self.__connect_to_child(ges_timeline_element)
 
+        set_state_flags_recurse(self, Gtk.StateFlags.SELECTED, are_set=self.ges_clip.selected)
+
         # Connect to Widget signals.
         self.connect("button-release-event", self._button_release_event_cb)
         self.connect("event", self._event_cb)
@@ -1459,6 +1462,7 @@ class Clip(Gtk.EventBox, Zoomable, Loggable):
 
     def _add_child(self, ges_timeline_element):
         ges_timeline_element.selected = Selected()
+        ges_timeline_element.selected.selected = self.ges_clip.selected.selected
         ges_timeline_element.ui = None
 
     def _child_added_cb(self, unused_ges_clip, ges_timeline_element):
diff --git a/pitivi/timeline/timeline.py b/pitivi/timeline/timeline.py
index 8d7123cc5..e868d0b44 100644
--- a/pitivi/timeline/timeline.py
+++ b/pitivi/timeline/timeline.py
@@ -768,6 +768,7 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
             self._scroll_start_y = event.y
 
     def _button_release_event_cb(self, unused_widget, event):
+        self.debug("RELEASED %s", event)
         allow_seek = not self.__got_dragged
 
         res, button = event.get_button()
@@ -1429,6 +1430,7 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
         return new_ges_layer
 
     def drag_end(self):
+        self.debug("Ending dragging")
         if self.editing_context:
             self.__end_snap()
 
diff --git a/tests/test_timeline_elements.py b/tests/test_timeline_elements.py
index 1e87d0935..dfb1be41c 100644
--- a/tests/test_timeline_elements.py
+++ b/tests/test_timeline_elements.py
@@ -28,6 +28,7 @@ from matplotlib.backend_bases import MouseEvent
 
 from pitivi.timeline.elements import GES_TYPE_UI_TYPE
 from pitivi.undo.undo import UndoableActionLog
+from pitivi.utils.timeline import SELECT
 from pitivi.utils.timeline import Zoomable
 from pitivi.utils.ui import LAYER_HEIGHT
 from tests import common
@@ -486,9 +487,29 @@ class TestVideoSource(common.TestCase):
 class TestClip(common.TestCase):
     """Tests for the Clip class."""
 
+    def test_selection_status_persists_when_clip_changes_layer(self):
+        timeline_container = common.create_timeline_container()
+        timeline = timeline_container.timeline
+        selection = timeline.selection
+        layer1 = timeline.ges_timeline.append_layer()
+        layer2 = timeline.ges_timeline.append_layer()
+
+        clip = self.add_clip(layer1, start=0)
+        selection.set_selection([clip], SELECT)
+        self.assertEqual(selection.get_single_clip(), clip)
+        self.assert_clip_selected(clip, expect_selected=True)
+
+        clip.move_to_layer_full(layer2)
+        clip2, = layer2.get_clips()
+        self.assert_clip_selected(clip2, expect_selected=True)
+
     def test_clip_subclasses(self):
         """Checks the constructors of the Clip class."""
+        timeline_container = common.create_timeline_container()
+        timeline = timeline_container.timeline
+        ges_layer = timeline.ges_timeline.append_layer()
+
         for gtype, widget_class in GES_TYPE_UI_TYPE.items():
             ges_object = GObject.new(gtype)
-            widget = widget_class(mock.Mock(), ges_object)
+            widget = widget_class(ges_layer.ui, ges_object)
             self.assertEqual(ges_object.ui, widget, widget_class)


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