[gtk/wip/otte/listview-colors] sortlistmodel: Look at order



commit d6a30aca82ff7c4e6896e2b3b5180a8d770ced11
Author: Benjamin Otte <otte redhat com>
Date:   Sun Jun 21 06:53:44 2020 +0200

    sortlistmodel: Look at order
    
    For now, we just look at SORT_ORDER_NONE to bypass any sorting.

 gtk/gtksortlistmodel.c | 58 +++++++++++++++++++++++++++++++++++---------------
 1 file changed, 41 insertions(+), 17 deletions(-)
---
diff --git a/gtk/gtksortlistmodel.c b/gtk/gtksortlistmodel.c
index 5444ee74ae..80f51a7409 100644
--- a/gtk/gtksortlistmodel.c
+++ b/gtk/gtksortlistmodel.c
@@ -308,6 +308,30 @@ gtk_sort_list_model_get_property (GObject     *object,
     }
 }
 
+static void
+gtk_sort_list_model_clear_sequences (GtkSortListModel *self)
+{
+  g_clear_pointer (&self->unsorted, g_sequence_free);
+  g_clear_pointer (&self->sorted, g_sequence_free);
+} 
+
+static void
+gtk_sort_list_model_create_sequences (GtkSortListModel *self)
+{
+  if (self->sorted)
+    return;
+
+  if (self->sorter == NULL ||
+      self->model == NULL ||
+      gtk_sorter_get_order (self->sorter) == GTK_SORTER_ORDER_NONE)
+    return;
+
+  self->sorted = g_sequence_new (gtk_sort_list_entry_free);
+  self->unsorted = g_sequence_new (NULL);
+
+  gtk_sort_list_model_add_items (self, 0, g_list_model_get_n_items (self->model), NULL, NULL);
+}
+
 static void gtk_sort_list_model_resort (GtkSortListModel *self);
 
 static void
@@ -318,6 +342,19 @@ gtk_sort_list_model_sorter_changed_cb (GtkSorter        *sorter,
   gtk_sort_list_model_resort (self);
 }
 
+static void
+gtk_sort_list_model_sorter_order_changed_cb (GtkSorter        *sorter,
+                                             GParamSpec       *pspec,
+                                             GtkSortListModel *self)
+{
+  if (gtk_sorter_get_order (sorter) == GTK_SORTER_ORDER_NONE)
+    gtk_sort_list_model_clear_sequences (self);
+  else
+    gtk_sort_list_model_create_sequences (self);
+
+  /* no need to resort here, we'll get a sorter_changed when that happens */
+}
+
 static void
 gtk_sort_list_model_clear_model (GtkSortListModel *self)
 {
@@ -326,8 +363,7 @@ gtk_sort_list_model_clear_model (GtkSortListModel *self)
 
   g_signal_handlers_disconnect_by_func (self->model, gtk_sort_list_model_items_changed_cb, self);
   g_clear_object (&self->model);
-  g_clear_pointer (&self->sorted, g_sequence_free);
-  g_clear_pointer (&self->unsorted, g_sequence_free);
+  gtk_sort_list_model_clear_sequences (self);
 }
 
 static void
@@ -337,7 +373,9 @@ gtk_sort_list_model_clear_sorter (GtkSortListModel *self)
     return;
 
   g_signal_handlers_disconnect_by_func (self->sorter, gtk_sort_list_model_sorter_changed_cb, self);
+  g_signal_handlers_disconnect_by_func (self->sorter, gtk_sort_list_model_sorter_order_changed_cb, self);
   g_clear_object (&self->sorter);
+  gtk_sort_list_model_clear_sequences (self);
 }
 
 static void
@@ -451,18 +489,6 @@ gtk_sort_list_model_new_for_type (GType item_type)
                        NULL);
 }
 
-static void
-gtk_sort_list_model_create_sequences (GtkSortListModel *self)
-{
-  if (self->sorter == NULL || self->model == NULL)
-    return;
-
-  self->sorted = g_sequence_new (gtk_sort_list_entry_free);
-  self->unsorted = g_sequence_new (NULL);
-
-  gtk_sort_list_model_add_items (self, 0, g_list_model_get_n_items (self->model), NULL, NULL);
-}
-
 /**
  * gtk_sort_list_model_set_model:
  * @self: a #GtkSortListModel
@@ -564,11 +590,9 @@ gtk_sort_list_model_set_sorter (GtkSortListModel *self,
     {
       self->sorter = g_object_ref (sorter);
       g_signal_connect (sorter, "changed", G_CALLBACK (gtk_sort_list_model_sorter_changed_cb), self);
+      g_signal_connect (sorter, "notify::order", G_CALLBACK (gtk_sort_list_model_sorter_order_changed_cb), 
self);
     }
 
-  g_clear_pointer (&self->unsorted, g_sequence_free);
-  g_clear_pointer (&self->sorted, g_sequence_free);
-  
   gtk_sort_list_model_create_sequences (self);
     
   n_items = g_list_model_get_n_items (G_LIST_MODEL (self));


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