[gnome-music/wip/gbsneto/flowbox: 1/6] albums: fix select/unselect all
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/gbsneto/flowbox: 1/6] albums: fix select/unselect all
- Date: Thu, 11 Aug 2016 01:58:50 +0000 (UTC)
commit 19f7fe5125f4a5fb31da44c5a755b1436ad1b679
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 | 47 +++++++++++++++++++++++++++++++++++++++++++++--
gnomemusic/window.py | 39 ++++++++-------------------------------
2 files changed, 53 insertions(+), 33 deletions(-)
---
diff --git a/gnomemusic/view.py b/gnomemusic/view.py
index fc89c1c..4b2cc64 100644
--- a/gnomemusic/view.py
+++ b/gnomemusic/view.py
@@ -274,6 +274,39 @@ 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):
+ """Select all the available tracks."""
+ 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):
+ """Unselects all the selected tracks."""
+ 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 +455,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 +527,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]