[gnome-music/wip/mschraal/remove-playlists-loaded-signal] playlistsview: Rework initial row selection
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/mschraal/remove-playlists-loaded-signal] playlistsview: Rework initial row selection
- Date: Wed, 8 Jan 2020 16:18:50 +0000 (UTC)
commit 0df14f835e22a26d215ea410e39b20a43669a7e0
Author: Marinus Schraal <mschraal gnome org>
Date: Wed Jan 8 17:11:14 2020 +0100
playlistsview: Rework initial row selection
The view by default selects a row for intial display if the list is
filled. This was done by emitting a signal after the initial playlists
being loaded. However, in certain conditions this signal could already
have fired before the view was even created, so no initial row would be
selected.
Instead directly listen to the playlists model for changes and use an
initial state variable to check if it is needed to activate a row.
Closes: #348
gnomemusic/coremodel.py | 1 -
gnomemusic/grilowrappers/grltrackerplaylists.py | 1 -
gnomemusic/views/playlistsview.py | 27 ++++++++++++++++---------
3 files changed, 17 insertions(+), 12 deletions(-)
---
diff --git a/gnomemusic/coremodel.py b/gnomemusic/coremodel.py
index a8579159..37c8f230 100644
--- a/gnomemusic/coremodel.py
+++ b/gnomemusic/coremodel.py
@@ -68,7 +68,6 @@ class CoreModel(GObject.GObject):
__gsignals__ = {
"artists-loaded": (GObject.SignalFlags.RUN_FIRST, None, ()),
"playlist-loaded": (GObject.SignalFlags.RUN_FIRST, None, (int,)),
- "playlists-loaded": (GObject.SignalFlags.RUN_FIRST, None, ()),
}
active_playlist = GObject.Property(type=Playlist, default=None)
diff --git a/gnomemusic/grilowrappers/grltrackerplaylists.py b/gnomemusic/grilowrappers/grltrackerplaylists.py
index acd626a9..546e2852 100644
--- a/gnomemusic/grilowrappers/grltrackerplaylists.py
+++ b/gnomemusic/grilowrappers/grltrackerplaylists.py
@@ -145,7 +145,6 @@ class GrlTrackerPlaylists(GObject.GObject):
self._window.notifications_popup.pop_loading()
return
if not media:
- self._coremodel.emit("playlists-loaded")
self._window.notifications_popup.pop_loading()
return
diff --git a/gnomemusic/views/playlistsview.py b/gnomemusic/views/playlistsview.py
index e7c60755..8bc56b66 100644
--- a/gnomemusic/views/playlistsview.py
+++ b/gnomemusic/views/playlistsview.py
@@ -62,6 +62,8 @@ class PlaylistsView(BaseView):
self._window = application.props.window
self._player = player
+ self._clean_fill = True
+
self._song_popover = PlaylistContextMenu(self._view)
play_song = Gio.SimpleAction.new('play_song', None)
@@ -108,11 +110,12 @@ class PlaylistsView(BaseView):
self._sidebar.bind_model(self._model, self._add_playlist_to_sidebar)
- self._loaded_id = self._coremodel.connect(
- "playlists-loaded", self._on_playlists_loaded)
self._active_playlist_id = self._coremodel.connect(
"notify::active-playlist", self._on_active_playlist_changed)
+ self._model.connect("items-changed", self._on_playlists_model_changed)
+ self._on_playlists_model_changed(self._model, 0, 0, 0)
+
# Selection is only possible from the context menu
self.disconnect(self._selection_mode_id)
@@ -147,15 +150,17 @@ class PlaylistsView(BaseView):
row = PlaylistTile(playlist)
return row
- 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 model.get_n_items() == 0:
+ self._clean_fill = True
+ return
+ elif self._clean_fill:
+ first_row = self._sidebar.get_row_at_index(0)
+ self._sidebar.select_row(first_row)
+ first_row.emit("activate")
+ self._clean_fill = True
+ return
+
if removed == 0:
return
@@ -164,6 +169,7 @@ class PlaylistsView(BaseView):
if row_next:
self._sidebar.select_row(row_next)
row_next.emit("activate")
+ self._clean_fill = True
@log
def _on_view_right_clicked(self, gesture, n_press, x, y):
@@ -218,6 +224,7 @@ class PlaylistsView(BaseView):
@log
def _on_playlist_activated(self, sidebar, row, data=None):
"""Update view with content from selected playlist"""
+ self._clean_fill = False
playlist = row.props.playlist
if self.rename_active:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]