From 3a0871ec2291b9623c9ff4ad95ba7320e45c30d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Thu, 3 Sep 2026 09:54:28 -0700 Subject: [PATCH] Use sort models --- src/Widgets/NotificationsList.vala | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/Widgets/NotificationsList.vala b/src/Widgets/NotificationsList.vala index d47a55c4..f53a7e1b 100644 --- a/src/Widgets/NotificationsList.vala +++ b/src/Widgets/NotificationsList.vala @@ -10,7 +10,7 @@ public class Notifications.NotificationsList : Granite.Bin { public const string ACTION_GROUP_PREFIX = "notifications-list"; public const string ACTION_PREFIX = ACTION_GROUP_PREFIX + "."; - private GLib.HashTable app_datetime; + private static GLib.HashTable app_datetime; private Gee.HashMap app_entries; private ListStore list_store; @@ -36,11 +36,15 @@ public class Notifications.NotificationsList : Granite.Bin { list_store = new GLib.ListStore (typeof (Notification)); + var sort_list_model = new Gtk.SortListModel (list_store, new Gtk.CustomSorter ((GLib.CompareDataFunc) Notification.compare)) { + section_sorter = new Gtk.CustomSorter ((GLib.CompareDataFunc) section_func) + }; + var listbox = new Gtk.ListBox () { activate_on_single_click = true, selection_mode = NONE }; - listbox.bind_model (list_store, create_widget_func); + listbox.bind_model (sort_list_model, create_widget_func); listbox.set_placeholder (placeholder); listbox.set_header_func (header_func); @@ -61,13 +65,7 @@ public class Notifications.NotificationsList : Granite.Bin { }); } - private int sort_func (Object obj1, Object obj2) { - var a = ((Notification) obj1); - var b = ((Notification) obj2); - if (a.desktop_id == b.desktop_id) { - return Notification.compare (a, b); - } - + private static int section_func (Notification a, Notification b) { unowned GLib.DateTime? time_a = app_datetime[a.desktop_id]; unowned GLib.DateTime? time_b = app_datetime[b.desktop_id]; @@ -119,7 +117,7 @@ public class Notifications.NotificationsList : Granite.Bin { app_datetime[notification.desktop_id] = notification.timestamp; } - list_store.insert_sorted (notification, sort_func); + list_store.append (notification); Idle.add (add_entry.callback); yield;