[pitivi] medialibrary: Fix selection post import



commit 4ea491268d116cac22ac8b5147c0eef1629da12e
Author: Alexandru Băluț <alexandru balut gmail com>
Date:   Sat Sep 21 01:11:50 2019 +0200

    medialibrary: Fix selection post import
    
    The test was not detecting the failure because it was using the ALL
    proxying strategy. In this case proxies are created and this mechanism
    fills out _last_imported_uris. Instead of overloading that logic, the
    detection is moved now simply in the asset-added signal handler.
    
    Fixes #1799

 pitivi/medialibrary.py      | 12 ++++++++----
 tests/test_media_library.py | 14 +++++++++++---
 2 files changed, 19 insertions(+), 7 deletions(-)
---
diff --git a/pitivi/medialibrary.py b/pitivi/medialibrary.py
index 2024e6c8..b7f355fc 100644
--- a/pitivi/medialibrary.py
+++ b/pitivi/medialibrary.py
@@ -994,8 +994,6 @@ class MediaLibraryWidget(Gtk.Box, Loggable):
                 len(proxying_files), progress,
                 self.__last_proxying_estimate_time)
             self._progressbar.set_text(progress_message)
-            self._last_imported_uris.update([asset.props.id for asset in
-                                             project.loading_assets])
 
         if progress == 100:
             self._doneImporting()
@@ -1027,6 +1025,8 @@ class MediaLibraryWidget(Gtk.Box, Loggable):
 
     def _assetAddedCb(self, unused_project, asset):
         """Checks whether the asset added to the project should be shown."""
+        self._last_imported_uris.add(asset.props.id)
+
         if asset in [row[COL_ASSET] for row in self.storemodel]:
             self.info("Asset %s already in!", asset.props.id)
             return
@@ -1633,15 +1633,19 @@ class MediaLibraryWidget(Gtk.Box, Loggable):
         self._project = None
 
     def __paths_walked_cb(self, uris):
-        """Handles the end of the path walking when importing files and dirs."""
+        """Handles the end of the path walking when importing dragged dirs."""
         if not uris:
             return
+
         if not self._project:
-            self.warning("Cannot add URIs, project missing")
+            return
+
+        # At the end of the import operation, these will be selected.
         self._last_imported_uris = set(uris)
         assets = self._project.assetsForUris(uris)
         if assets:
             # All the files have already been added.
+            # This is the only chance we have to select them.
             self._selectLastImportedUris()
         else:
             self._project.addUris(uris)
diff --git a/tests/test_media_library.py b/tests/test_media_library.py
index be4c3fbf..3d38b506 100644
--- a/tests/test_media_library.py
+++ b/tests/test_media_library.py
@@ -259,15 +259,23 @@ class TestMediaLibrary(BaseTestMediaLibrary):
             project = self.app.project_manager.current_project
             self.assertEqual(project.list_assets(GES.Extractable), [])
 
-    def testNewlyImportedAssetSelected(self):
+    def check_selection_post_import(self, **kwargs):
         samples = ["30fps_numeroted_frames_red.mkv",
                    "30fps_numeroted_frames_blue.webm"]
         with common.cloned_sample(*samples):
-            self.check_import(samples)
-
+            self.check_import(samples, **kwargs)
         self.assertEqual(len(list(self.medialibrary.getSelectedPaths())),
                          len(self.samples))
 
+    def test_newly_imported_asset_selected_optimize_all(self):
+        self.check_selection_post_import(proxying_strategy=ProxyingStrategy.ALL)
+
+    def test_newly_imported_asset_selected_optimize_automatic(self):
+        self.check_selection_post_import(proxying_strategy=ProxyingStrategy.AUTOMATIC)
+
+    def test_newly_imported_asset_selected_optimize_nothing(self):
+        self.check_selection_post_import(proxying_strategy=ProxyingStrategy.NOTHING)
+
     def test_stop_using_proxies(self):
         sample_name = "30fps_numeroted_frames_red.mkv"
         with common.cloned_sample(sample_name):


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