[gnome-music/wip/jfelder/baseview-selection-fixes] baseview: Fix selection-mode changes



commit 4248e9bc6dd4f0caccc20444944f6c3b72111856
Author: Jean Felder <jfelder src gnome org>
Date:   Fri Jan 17 00:49:17 2020 +0100

    baseview: Fix selection-mode changes
    
    This fixes a regresssion introduced by commits
    a755b53974e9ab654f3b8f2f845e4732cddc2197,
    c61a2469589176f7138d459796085880f2f322d1 and
    b5e86fb8693a7c4659f237164f38dcf426384817.
    
    Those commits tried to prevent selection-mode changes when a main view
    is not visible. It introduced two changes:
    - remove the "selection-mode" bidirectional binding between the
    window and the base view and replaced it with a binding from the base
    view to the window.
    - listen to selection-mode changes from the window to prevent a
    selection-mode change of a view if the value is unchanged or if the
    view is not the visible view.
    
    This introduced the following regression: the specific selection-mode
    changes of ArtistsView and SongsView are not called anymore when
    activating selection-mode via a Ctrl + left click. Indeed, in that
    case, Window and View already have the same selection-mode value.
    
    It turns out, this issue can be fixed by making two changes:
    - restore the bidirectional binding between the Window and the
    BaseView.
    - simplify the selection-mode change test: test for the visible view
    only.

 gnomemusic/views/artistsview.py   | 4 +---
 gnomemusic/views/baseview.py      | 9 +++------
 gnomemusic/views/playlistsview.py | 2 +-
 gnomemusic/views/songsview.py     | 4 +---
 4 files changed, 6 insertions(+), 13 deletions(-)
---
diff --git a/gnomemusic/views/artistsview.py b/gnomemusic/views/artistsview.py
index 9ada990c..2ed4ad35 100644
--- a/gnomemusic/views/artistsview.py
+++ b/gnomemusic/views/artistsview.py
@@ -189,9 +189,7 @@ 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
-                or self.get_parent().get_visible_child() != self):
+        if self.get_parent().get_visible_child() != self:
             return
 
         super()._on_selection_mode_changed(widget, data)
diff --git a/gnomemusic/views/baseview.py b/gnomemusic/views/baseview.py
index 8cb7ce08..80235b52 100644
--- a/gnomemusic/views/baseview.py
+++ b/gnomemusic/views/baseview.py
@@ -67,9 +67,9 @@ class BaseView(Gtk.Stack):
 
         self.bind_property(
             "selection-mode", self._window, "selection-mode",
-            GObject.BindingFlags.DEFAULT)
+            GObject.BindingFlags.BIDIRECTIONAL)
 
-        self._selection_mode_id = self._window.connect(
+        self._selection_mode_id = self.connect(
             "notify::selection-mode", self._on_selection_mode_changed)
 
     @log
@@ -79,11 +79,8 @@ class BaseView(Gtk.Stack):
 
     @log
     def _on_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):
+        if self.get_parent().get_visible_child() != self:
             return
 
-        self.props.selection_mode = selection_mode
         if self.props.selection_mode is False:
             self.deselect_all()
diff --git a/gnomemusic/views/playlistsview.py b/gnomemusic/views/playlistsview.py
index ec3d2541..3a272670 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._window.disconnect(self._selection_mode_id)
+        self.disconnect(self._selection_mode_id)
 
         self.show_all()
 
diff --git a/gnomemusic/views/songsview.py b/gnomemusic/views/songsview.py
index 756635d5..9c6e3c09 100644
--- a/gnomemusic/views/songsview.py
+++ b/gnomemusic/views/songsview.py
@@ -155,9 +155,7 @@ 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
-                or self.get_parent().get_visible_child() != self):
+        if self.get_parent().get_visible_child() != self:
             return
 
         super()._on_selection_mode_changed(widget, data)


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