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



commit 29965e9a2c467ff083c7f0fdbe5412575686c4bf
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 in the visible view.

 gnomemusic/views/baseview.py      | 21 +++++++++++++--------
 gnomemusic/views/playlistsview.py |  2 +-
 2 files changed, 14 insertions(+), 9 deletions(-)
---
diff --git a/gnomemusic/views/baseview.py b/gnomemusic/views/baseview.py
index 08b9d26f..deafb714 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_window_selection_mode_changed)
 
     @log
     def _setup_view(self):
@@ -79,7 +79,12 @@ class BaseView(Gtk.Stack):
         pass
 
     @log
-    def _on_selection_mode_changed(self, widget, data=None):
-        if (self.get_parent().get_visible_child() == self
-                and not self.props.selection_mode):
+    def _on_window_selection_mode_changed(self, widget, data=None):
+        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 85571fc6..efe7ed97 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()
 


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