[gnome-music/wip/jfelder/songswidget-selection: 2/2] songwidget: Handle checkbox interactions with selection-mode



commit fc8c764a720add947827098b4015622e3fbb7f43
Author: Jean Felder <jfelder src gnome org>
Date:   Thu Jul 25 09:30:31 2019 +0200

    songwidget: Handle checkbox interactions with selection-mode
    
    There is a bidirectional binding between the coresong selected
    property and the checkbox active state. It keeps these properties
    synchronized.
    However, the selection change from the DiscBox is deactivated because
    a selection change would be propagated to the checkbox which would
    undo the selection.
    
    Solve this issue by adding a flag which keeps track of the clicks and
    prevents the same event from happening twice (one time in the checkbox
    and again in the SongWidget).

 data/ui/SongWidget.ui                   |  1 +
 gnomemusic/widgets/disclistboxwidget.py | 12 +++++++++---
 gnomemusic/widgets/songwidget.py        |  7 +++++++
 3 files changed, 17 insertions(+), 3 deletions(-)
---
diff --git a/data/ui/SongWidget.ui b/data/ui/SongWidget.ui
index 31a8e2d6..27d54fcf 100644
--- a/data/ui/SongWidget.ui
+++ b/data/ui/SongWidget.ui
@@ -53,6 +53,7 @@
                 <property name="receives_default">False</property>
                 <property name="no_show_all">True</property>
                 <property name="draw_indicator">True</property>
+                <signal name="toggled" handler="_on_select_button_toggled"/>
               </object>
             </child>
             <child>
diff --git a/gnomemusic/widgets/disclistboxwidget.py b/gnomemusic/widgets/disclistboxwidget.py
index d4b5542f..83806506 100644
--- a/gnomemusic/widgets/disclistboxwidget.py
+++ b/gnomemusic/widgets/disclistboxwidget.py
@@ -112,11 +112,16 @@ class DiscBox(Gtk.Box):
 
     @log
     def _song_activated(self, widget, event):
+        if widget.props.select_click:
+            widget.props.select_click = False
+            return
+
         mod_mask = Gtk.accelerator_get_default_mod_mask()
         if ((event.get_state() & mod_mask) == Gdk.ModifierType.CONTROL_MASK
                 and not self.props.selection_mode
                 and self.props.selection_mode_allowed):
             self.props.selection_mode = True
+            widget.props.select_click = True
             widget.props.coresong.props.selected = True
             return
 
@@ -125,9 +130,10 @@ class DiscBox(Gtk.Box):
                 and not self.props.selection_mode):
             self.emit('song-activated', widget)
 
-        # FIXME: Need to ignore the event from the checkbox.
-        # if self.props.selection_mode:
-        #     widget.props.selected = not widget.props.selected
+        if self.props.selection_mode:
+            widget.props.select_click = True
+            selection_state = widget.props.coresong.props.selected
+            widget.props.coresong.props.selected = not selection_state
 
         return True
 
diff --git a/gnomemusic/widgets/songwidget.py b/gnomemusic/widgets/songwidget.py
index 2da33fd2..571e70c5 100644
--- a/gnomemusic/widgets/songwidget.py
+++ b/gnomemusic/widgets/songwidget.py
@@ -57,6 +57,7 @@ class SongWidget(Gtk.EventBox):
     }
 
     coresong = GObject.Property(type=CoreSong, default=None)
+    select_click = GObject.Property(type=bool, default=False)
     selected = GObject.Property(type=bool, default=False)
     show_duration = GObject.Property(type=bool, default=True)
     show_favorite = GObject.Property(type=bool, default=True)
@@ -210,6 +211,12 @@ class SongWidget(Gtk.EventBox):
 
         self.emit("widget-moved", source_position)
 
+    @Gtk.Template.Callback()
+    def _on_select_button_toggled(self, widget):
+        # This property is used to ignore the click to select interactions
+        # between the SongWidget and the DiscBox.
+        self.props.select_click = not self.props.select_click
+
     @Gtk.Template.Callback()
     @log
     def _on_star_toggle(self, widget, event):


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