[gnome-music/wip/jfelder/3.34-playlist-deletion: 2/2] playlistsview: Select the next playlist on playlist deletion



commit d84b5861a36d1861749cc68611cdafa1ebecc979
Author: Jean Felder <jfelder src gnome org>
Date:   Tue Jan 7 01:12:31 2020 +0100

    playlistsview: Select the next playlist on playlist deletion
    
    When a user playlist is deleted, the next playlist from the list is
    selected. If there is no next playlist, the previous one is selected.
    
    This fixes a regression from the core rewrite (commits
    e626a26ad0912e2b322a09638ef1fa95bceb117d and
    bda877bb538d8fbddca65dea8a79b13583e3d6f9).
    
    Closes: #359
    (cherry picked from commit 8c0aa3f4f63d214042772ad09595a4cf16428199)

 gnomemusic/views/playlistsview.py | 12 ++++++++++++
 1 file changed, 12 insertions(+)
---
diff --git a/gnomemusic/views/playlistsview.py b/gnomemusic/views/playlistsview.py
index bc133426..e7c60755 100644
--- a/gnomemusic/views/playlistsview.py
+++ b/gnomemusic/views/playlistsview.py
@@ -149,10 +149,22 @@ class PlaylistsView(BaseView):
 
     def _on_playlists_loaded(self, klass):
         self._coremodel.disconnect(self._loaded_id)
+        self._model.connect("items-changed", self._on_playlists_model_changed)
+
         first_row = self._sidebar.get_row_at_index(0)
         self._sidebar.select_row(first_row)
         first_row.emit("activate")
 
+    def _on_playlists_model_changed(self, model, position, removed, added):
+        if removed == 0:
+            return
+
+        row_next = (self._sidebar.get_row_at_index(position)
+                    or self._sidebar.get_row_at_index(position - 1))
+        if row_next:
+            self._sidebar.select_row(row_next)
+            row_next.emit("activate")
+
     @log
     def _on_view_right_clicked(self, gesture, n_press, x, y):
         requested_row = self._view.get_row_at_y(y)


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