sidebar: Give TagBoxes a sort_func()
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
ef759c2e64
commit
2614db8923
|
@ -14,6 +14,7 @@ class TagBox(Gtk.ScrolledWindow):
|
|||
self.set_child(self.listbox)
|
||||
self.set_vexpand(True)
|
||||
|
||||
self.listbox.set_sort_func(self.sort_func)
|
||||
tagstore.Added.register(self.tag_added)
|
||||
tagstore.Removed.register(self.tag_removed)
|
||||
|
||||
|
@ -24,6 +25,13 @@ class TagBox(Gtk.ScrolledWindow):
|
|||
while (row := self[0]) != None:
|
||||
self.on_tag_removed(row.tag)
|
||||
|
||||
def sort_func(self, lhs, rhs):
|
||||
if lhs.tag < rhs.tag:
|
||||
return -1
|
||||
if rhs.tag < lhs.tag:
|
||||
return 1
|
||||
return 0
|
||||
|
||||
def on_tag_added(self, tag):
|
||||
tag.widgets = tagrow.TagRow(tag, self.icon)
|
||||
tag.TrackAdded.register(self.tag_changed)
|
||||
|
|
|
@ -74,3 +74,15 @@ class TestTagBox(unittest.TestCase):
|
|||
self.assertNotIn(tbox.tag_changed, tag2.TrackAdded.subscribers)
|
||||
self.assertNotIn(tbox.tag_changed, tag1.TrackRemoved.subscribers)
|
||||
self.assertNotIn(tbox.tag_changed, tag2.TrackRemoved.subscribers)
|
||||
|
||||
def test_tag_box_sort(self):
|
||||
store = lib.tagstore.TagStore()
|
||||
tbox = tagbox.TagBox(store, "missing-icon")
|
||||
tagB = store.add("B", fake.Track(1))
|
||||
tagA = store.add("A", fake.Track(1))
|
||||
tagC = store.add("C", fake.Track(1))
|
||||
|
||||
tbox.bus.complete()
|
||||
self.assertEqual(tbox[0].tag, tagA)
|
||||
self.assertEqual(tbox[1].tag, tagB)
|
||||
self.assertEqual(tbox[2].tag, tagC)
|
||||
|
|
Loading…
Reference in New Issue
Block a user