[gnome-music/wip/jfelder/selection-misc-cleanups: 4/20] baseview: Do not change selection-mode if the view is not visible



commit a755b53974e9ab654f3b8f2f845e4732cddc2197
Author: Jean Felder <jfelder src gnome org>
Date:   Thu Jan 9 15:55:53 2020 +0100

    baseview: Do not change selection-mode if the view is not visible
    
    A user can only select songs, albums or artists if the view is
    visible.

 gnomemusic/views/artistsview.py   |  4 ++++
 gnomemusic/views/baseview.py      | 19 ++++++++++++-------
 gnomemusic/views/playlistsview.py |  2 +-
 gnomemusic/views/songsview.py     |  4 ++++
 4 files changed, 21 insertions(+), 8 deletions(-)
---
diff --git a/gnomemusic/views/artistsview.py b/gnomemusic/views/artistsview.py
index d49803c6..d61301c6 100644
--- a/gnomemusic/views/artistsview.py
+++ b/gnomemusic/views/artistsview.py
@@ -189,6 +189,10 @@ class ArtistsView(BaseView):
 
     @log
     def _on_selection_mode_changed(self, widget, data=None):
+        selection_mode = self._window.props.selection_mode
+        if selection_mode == self.props.selection_mode:
+            return
+
         super()._on_selection_mode_changed(widget, data)
 
         self._view.props.sensitive = not self.props.selection_mode
diff --git a/gnomemusic/views/baseview.py b/gnomemusic/views/baseview.py
index 08b9d26f..3aa19219 100644
--- a/gnomemusic/views/baseview.py
+++ b/gnomemusic/views/baseview.py
@@ -66,12 +66,12 @@ class BaseView(Gtk.Stack):
         self.add(self._grid)
         self.show_all()
 
-        self._selection_mode_id = self.connect(
-            "notify::selection-mode", self._on_selection_mode_changed)
-
         self.bind_property(
-            'selection-mode', self._window, 'selection-mode',
-            GObject.BindingFlags.BIDIRECTIONAL)
+            "selection-mode", self._window, "selection-mode",
+            GObject.BindingFlags.DEFAULT)
+
+        self._selection_mode_id = self._window.connect(
+            "notify::selection-mode", self._on_selection_mode_changed)
 
     @log
     def _setup_view(self):
@@ -80,6 +80,11 @@ class BaseView(Gtk.Stack):
 
     @log
     def _on_selection_mode_changed(self, widget, data=None):
-        if (self.get_parent().get_visible_child() == self
-                and not self.props.selection_mode):
+        selection_mode = self._window.props.selection_mode
+        if (selection_mode == self.props.selection_mode
+                or self.get_parent().get_visible_child() != self):
+            return
+
+        self.props.selection_mode = selection_mode
+        if self.props.selection_mode is False:
             self.unselect_all()
diff --git a/gnomemusic/views/playlistsview.py b/gnomemusic/views/playlistsview.py
index 3a272670..ec3d2541 100644
--- a/gnomemusic/views/playlistsview.py
+++ b/gnomemusic/views/playlistsview.py
@@ -97,7 +97,7 @@ class PlaylistsView(BaseView):
             "notify::active-playlist", self._on_active_playlist_changed)
 
         # Selection is only possible from the context menu
-        self.disconnect(self._selection_mode_id)
+        self._window.disconnect(self._selection_mode_id)
 
         self.show_all()
 
diff --git a/gnomemusic/views/songsview.py b/gnomemusic/views/songsview.py
index c56c4dc2..a786cdd9 100644
--- a/gnomemusic/views/songsview.py
+++ b/gnomemusic/views/songsview.py
@@ -155,6 +155,10 @@ class SongsView(BaseView):
 
     @log
     def _on_selection_mode_changed(self, widget, data=None):
+        selection_mode = self._window.props.selection_mode
+        if selection_mode == self.props.selection_mode:
+            return
+
         super()._on_selection_mode_changed(widget, data)
 
         cols = self._view.get_columns()


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