[gnome-music/wip/gbsneto/flowbox: 6/10] albums: fix select/unselect all



commit 61a8e5bca470818227f9b897f6906ea1ae32ff6f
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Tue Aug 9 04:29:49 2016 -0300

    albums: fix select/unselect all
    
    https://bugzilla.gnome.org/show_bug.cgi?id=760164

 gnomemusic/view.py   |   45 +++++++++++++++++++++++++++++++++++++++++++--
 gnomemusic/window.py |   39 ++++++++-------------------------------
 2 files changed, 51 insertions(+), 33 deletions(-)
---
diff --git a/gnomemusic/view.py b/gnomemusic/view.py
index fc89c1c..e02bede 100644
--- a/gnomemusic/view.py
+++ b/gnomemusic/view.py
@@ -274,6 +274,37 @@ class ViewContainer(Gtk.Stack):
     def _on_list_widget_star_render(self, col, cell, model, _iter, data):
         pass
 
+    @log
+    def _set_selection(self, value, parent=None):
+        count = 0
+        _iter = self.model.iter_children(parent)
+        while _iter is not None:
+            if self.model.iter_has_child(_iter):
+                count += self._set_selection(value, _iter)
+            if self.model[_iter][5]:
+                self.model[_iter][6] = value
+                count += 1
+            _iter = self.model.iter_next(_iter)
+        return count
+
+    @log
+    def select_all(self):
+        count = self._set_selection(True)
+
+        if count > 0:
+            self.selection_toolbar._add_to_playlist_button.set_sensitive(True)
+            self.selection_toolbar._remove_from_playlist_button.set_sensitive(True)
+
+        self.update_header_from_selection(count)
+        self.view.queue_draw()
+
+    @log
+    def unselect_all(self):
+        self._set_selection(False)
+        self.selection_toolbar._add_to_playlist_button.set_sensitive(False)
+        self.selection_toolbar._remove_from_playlist_button.set_sensitive(False)
+        self.header_bar._selection_menu_label.set_text(_("Click on items to select them"))
+        self.queue_draw()
 
 # Class for the Empty View
 class Empty(Gtk.Stack):
@@ -422,8 +453,6 @@ class Albums(ViewContainer):
             self.items_selected = []
             self.items_selected_callback = callback
             self.albums_index = 0
-            self.albums_selected = [self.model.get_value(self.model.get_iter(path), 5)
-                                    for path in self.view.get_selection()]
             if len(self.albums_selected):
                 self._get_selected_album_songs()
 
@@ -496,6 +525,18 @@ class Albums(ViewContainer):
             else:
                 self.items_selected_callback(self.items_selected)
 
+    def _toggle_all_selection(self, selected):
+        for child in self.view.get_children():
+            child.check.set_active(selected)
+
+    @log
+    def select_all(self):
+        self._toggle_all_selection(True)
+
+    @log
+    def unselect_all(self):
+        self._toggle_all_selection(False)
+
 
 class Songs(ViewContainer):
 
diff --git a/gnomemusic/window.py b/gnomemusic/window.py
index fa5c5f0..8de1240 100644
--- a/gnomemusic/window.py
+++ b/gnomemusic/window.py
@@ -279,47 +279,24 @@ class Window(Gtk.ApplicationWindow):
         self.views[0].populate()
 
     @log
-    def _set_selection(self, model, value, parent=None):
-        count = 0
-        _iter = model.iter_children(parent)
-        while _iter is not None:
-            if model.iter_has_child(_iter):
-                count += self._set_selection(model, value, _iter)
-            if model[_iter][5]:
-                model.set(_iter, [6], [value])
-                count += 1
-            _iter = model.iter_next(_iter)
-        return count
-
-    @log
     def _on_select_all(self, action, param):
         if self.toolbar._selectionMode is False:
             return
         if self.toolbar._state == ToolbarState.MAIN:
-            model = self._stack.get_visible_child().model
+            view = self._stack.get_visible_child()
         else:
-            model = self._stack.get_visible_child().get_visible_child().model
-        count = self._set_selection(model, True)
-        if count > 0:
-            self.toolbar._selection_menu_label.set_text(
-                ngettext("Selected %d item", "Selected %d items", count) % count)
-            self.selection_toolbar._add_to_playlist_button.set_sensitive(True)
-            self.selection_toolbar._remove_from_playlist_button.set_sensitive(True)
-        elif count == 0:
-            self.toolbar._selection_menu_label.set_text(_("Click on items to select them"))
-        self._stack.get_visible_child().queue_draw()
+            view = self._stack.get_visible_child().get_visible_child()
+
+        view.select_all()
 
     @log
     def _on_select_none(self, action, param):
         if self.toolbar._state == ToolbarState.MAIN:
-            model = self._stack.get_visible_child().model
+            view = self._stack.get_visible_child()
         else:
-            model = self._stack.get_visible_child().get_visible_child().model
-        self._set_selection(model, False)
-        self.selection_toolbar._add_to_playlist_button.set_sensitive(False)
-        self.selection_toolbar._remove_from_playlist_button.set_sensitive(False)
-        self.toolbar._selection_menu_label.set_text(_("Click on items to select them"))
-        self._stack.get_visible_child().queue_draw()
+            view = self._stack.get_visible_child().get_visible_child()
+
+        view.unselect_all()
 
     def _show_notification(self):
         self.notification_handler = None


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