[gnome-music/wip/mschraal/searchview-selection-fixes: 2/2] window: Move selection handling to views
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/mschraal/searchview-selection-fixes: 2/2] window: Move selection handling to views
- Date: Sat, 8 Feb 2020 14:49:29 +0000 (UTC)
commit 53e40a65f9aaf1a249582916c92635c2fbd1fcb1
Author: Marinus Schraal <mschraal gnome org>
Date: Sat Feb 8 15:41:27 2020 +0100
window: Move selection handling to views
The select all/none actions of views with children (AlbumsView &
SearchView) was previously handled in Window. As SearchView became more
complicated this is no longer feasible.
Instead let AlbumsView and SearchView pass the given actions to their
active child if active.
Closes: #364
gnomemusic/views/albumsview.py | 12 ++++++---
gnomemusic/views/searchview.py | 61 ++++++++++++++++++++++++++++++++----------
gnomemusic/window.py | 14 +++-------
3 files changed, 59 insertions(+), 28 deletions(-)
---
diff --git a/gnomemusic/views/albumsview.py b/gnomemusic/views/albumsview.py
index e479fec5..0e050365 100644
--- a/gnomemusic/views/albumsview.py
+++ b/gnomemusic/views/albumsview.py
@@ -245,9 +245,15 @@ class AlbumsView(Gtk.Stack):
Selects or deselects all items without sending the notify::active
signal for performance purposes.
"""
- with self._window._app.props.coreselection.freeze_notify():
- for child in self._flowbox.get_children():
- child.props.selected = selected
+ if self.get_visible_child() == self._album_widget:
+ if selected is True:
+ self._album_widget.select_all()
+ else:
+ self._album_widget.deselect_all()
+ else:
+ with self._window._app.props.coreselection.freeze_notify():
+ for child in self._flowbox.get_children():
+ child.props.selected = selected
def select_all(self):
self._toggle_all_selection(True)
diff --git a/gnomemusic/views/searchview.py b/gnomemusic/views/searchview.py
index 31d64e5a..65da0699 100644
--- a/gnomemusic/views/searchview.py
+++ b/gnomemusic/views/searchview.py
@@ -22,7 +22,9 @@
# code, but you are not obligated to do so. If you do not wish to do so,
# delete this exception statement from your version.
+from enum import IntEnum
from gettext import gettext as _
+
from gi.repository import Gdk, GObject, Gtk
from gnomemusic.player import PlayerPlaylist
@@ -44,8 +46,18 @@ class SearchView(Gtk.Stack):
__gtype_name__ = "SearchView"
+ class State(IntEnum):
+ """The different states of SearchView
+ """
+ MAIN = 0
+ ALL_ALBUMS = 1
+ ALL_ARTISTS = 2
+ ALBUM = 3
+ ARTIST = 4
+
search_state = GObject.Property(type=int, default=Search.State.NONE)
selection_mode = GObject.Property(type=bool, default=False)
+ state = GObject.Property(type=int, default=State.MAIN)
_album_header = Gtk.Template.Child()
_album_flowbox = Gtk.Template.Child()
@@ -317,6 +329,7 @@ class SearchView(Gtk.Stack):
# Update and display the album widget if not in selection mode
self._album_widget.update(corealbum)
+ self.props.state = SearchView.State.ALBUM
self._headerbar.props.state = HeaderBar.State.SEARCH
self._headerbar.props.title = corealbum.props.title
self._headerbar.props.subtitle = corealbum.props.artist
@@ -345,6 +358,7 @@ class SearchView(Gtk.Stack):
"selection-mode", artist_albums_widget, "selection-mode",
GObject.BindingFlags.BIDIRECTIONAL)
+ self.props.state = SearchView.State.ARTIST
self._headerbar.props.state = HeaderBar.State.SEARCH
self._headerbar.props.title = coreartist.props.artist
self._headerbar.props.subtitle = None
@@ -354,6 +368,7 @@ class SearchView(Gtk.Stack):
@Gtk.Template.Callback()
def _on_all_artists_clicked(self, widget, event, user_data=None):
+ self.props.state = SearchView.State.ALL_ARTISTS
self._headerbar.props.state = HeaderBar.State.SEARCH
self._headerbar.props.title = _("Artists Results")
self._headerbar.props.subtitle = None
@@ -368,6 +383,7 @@ class SearchView(Gtk.Stack):
@Gtk.Template.Callback()
def _on_all_albums_clicked(self, widget, event, user_data=None):
+ self.props.state = SearchView.State.ALL_ALBUMS
self._headerbar.props.state = HeaderBar.State.SEARCH
self._headerbar.props.title = _("Albums Results")
self._headerbar.props.subtitle = None
@@ -381,20 +397,36 @@ class SearchView(Gtk.Stack):
self.props.search_mode_active = False
def _select_all(self, value):
- with self._model.freeze_notify():
- def song_select(child):
- song_widget = child.get_child()
- song_widget.props.selected = value
-
- def album_select(child):
- child.props.selected = value
-
- def artist_select(child):
- child.props.selected = value
-
- self._songs_listbox.foreach(song_select)
- self._album_flowbox.foreach(album_select)
- self._artist_flowbox.foreach(artist_select)
+ def child_select(child):
+ child.props.selected = value
+
+ if self.props.state == SearchView.State.MAIN:
+ with self._model.freeze_notify():
+ def song_select(child):
+ song_widget = child.get_child()
+ song_widget.props.selected = value
+
+ self._songs_listbox.foreach(song_select)
+ self._album_flowbox.foreach(child_select)
+ self._artist_flowbox.foreach(child_select)
+ elif self.props.state == SearchView.State.ALL_ALBUMS:
+ with self._model.freeze_notify():
+ self._album_all_flowbox.foreach(child_select)
+ elif self.props.state == SearchView.State.ALL_ARTISTS:
+ with self._model.freeze_notify():
+ self._artist_all_flowbox.foreach(child_select)
+ elif self.props.state == SearchView.State.ALBUM:
+ view = self.get_visible_child()
+ if value is True:
+ view.select_all()
+ else:
+ view.deselect_all()
+ elif self.props.state == SearchView.State.ARTIST:
+ view = self.get_visible_child().get_child().get_child()
+ if value is True:
+ view.select_all()
+ else:
+ view.deselect_all()
def select_all(self):
self._select_all(True)
@@ -412,6 +444,7 @@ class SearchView(Gtk.Stack):
self.set_visible_child(self._search_results)
self.props.search_mode_active = True
+ self.props.state = SearchView.State.MAIN
self._headerbar.props.state = HeaderBar.State.MAIN
def _on_selection_mode_changed(self, widget, data=None):
diff --git a/gnomemusic/window.py b/gnomemusic/window.py
index cd5a2855..cfc62af9 100644
--- a/gnomemusic/window.py
+++ b/gnomemusic/window.py
@@ -287,22 +287,14 @@ class Window(Gtk.ApplicationWindow):
def _select_all(self, action=None, param=None):
if not self.props.selection_mode:
return
- if self._headerbar.props.state == HeaderBar.State.MAIN:
- view = self.props.active_view
- else:
- view = self.props.active_view.get_visible_child()
- view.select_all()
+ self.props.active_view.select_all()
def _deselect_all(self, action=None, param=None):
if not self.props.selection_mode:
return
- if self._headerbar.props.state == HeaderBar.State.MAIN:
- view = self.props.active_view
- view.deselect_all()
- else:
- view = self.props.active_view.get_visible_child()
- view.deselect_all()
+
+ self.props.active_view.deselect_all()
def _on_key_press(self, widget, event):
modifiers = event.get_state() & Gtk.accelerator_get_default_mod_mask()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]