[gtk/column-sorting: 3/3] Reimplement column view sorting




commit 5a3db41a51911d1d9eddd1f20225f583c698e7d9
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Oct 19 21:09:45 2022 -0400

    Reimplement column view sorting
    
    Replace the private GtkColumnViewSorter implementation
    with a GtkMultiSorter containing GtkInvertibleSorters
    wrapping the individual column sorters.

 gtk/gtkcolumnview.c              |  11 +-
 gtk/gtkcolumnviewcolumn.c        |  52 ++++---
 gtk/gtkcolumnviewcolumnprivate.h |   3 +
 gtk/gtkcolumnviewsorter.c        | 290 ++++++++-------------------------------
 gtk/gtkcolumnviewsorterprivate.h |  28 ++--
 gtk/gtkcolumnviewtitle.c         |  27 ++--
 6 files changed, 127 insertions(+), 284 deletions(-)
---
diff --git a/gtk/gtkcolumnview.c b/gtk/gtkcolumnview.c
index 95fb02d8eb..9ba7db6c2b 100644
--- a/gtk/gtkcolumnview.c
+++ b/gtk/gtkcolumnview.c
@@ -27,6 +27,7 @@
 #include "gtkcolumnviewcolumnprivate.h"
 #include "gtkcolumnviewlayoutprivate.h"
 #include "gtkcolumnviewsorterprivate.h"
+#include "gtkmultisorter.h"
 #include "gtkcssnodeprivate.h"
 #include "gtkdropcontrollermotion.h"
 #include "gtklistviewprivate.h"
@@ -1303,7 +1304,7 @@ gtk_column_view_init (GtkColumnView *self)
   g_signal_connect (controller, "leave", G_CALLBACK (gtk_column_view_drag_leave), NULL);
   gtk_widget_add_controller (GTK_WIDGET (self), controller);
 
-  self->sorter = GTK_SORTER (gtk_column_view_sorter_new ());
+  self->sorter = GTK_SORTER (gtk_multi_sorter_new ());
   self->factory = gtk_column_list_item_factory_new (self);
   self->listview = GTK_LIST_VIEW (g_object_new (GTK_TYPE_COLUMN_LIST_VIEW, NULL));
   gtk_list_view_set_factory (self->listview, GTK_LIST_ITEM_FACTORY (self->factory));
@@ -1537,7 +1538,7 @@ gtk_column_view_remove_column (GtkColumnView       *self,
         break;
     }
 
-  gtk_column_view_sorter_remove_column (GTK_COLUMN_VIEW_SORTER (self->sorter), column);
+  gtk_column_view_sorter_remove_column (self->sorter, column);
   gtk_column_view_column_set_column_view (column, NULL);
   g_list_store_remove (self->columns, i);
 }
@@ -1699,11 +1700,9 @@ gtk_column_view_sort_by_column (GtkColumnView       *self,
   g_return_if_fail (column == NULL || gtk_column_view_column_get_column_view (column) == self);
 
   if (column == NULL)
-    gtk_column_view_sorter_clear (GTK_COLUMN_VIEW_SORTER (self->sorter));
+    gtk_column_view_sorter_clear (self->sorter);
   else
-    gtk_column_view_sorter_set_column (GTK_COLUMN_VIEW_SORTER (self->sorter),
-                                       column,
-                                       direction == GTK_SORT_DESCENDING);
+    gtk_column_view_sorter_set_column (self->sorter, column, direction);
 }
 
 /**
diff --git a/gtk/gtkcolumnviewcolumn.c b/gtk/gtkcolumnviewcolumn.c
index 74c89c0c8d..f732c7a05a 100644
--- a/gtk/gtkcolumnviewcolumn.c
+++ b/gtk/gtkcolumnviewcolumn.c
@@ -31,7 +31,7 @@
 #include "gtkrbtreeprivate.h"
 #include "gtksizegroup.h"
 #include "gtkwidgetprivate.h"
-#include "gtksorter.h"
+#include "gtkinvertiblesorter.h"
 
 /**
  * GtkColumnViewColumn:
@@ -56,7 +56,7 @@ struct _GtkColumnViewColumn
 
   GtkListItemFactory *factory;
   char *title;
-  GtkSorter *sorter;
+  GtkInvertibleSorter *invertible_sorter;
 
   /* data for the view */
   GtkColumnView *view;
@@ -114,7 +114,7 @@ gtk_column_view_column_dispose (GObject *object)
   g_assert (self->first_cell == NULL); /* no view = no children */
 
   g_clear_object (&self->factory);
-  g_clear_object (&self->sorter);
+  g_clear_object (&self->invertible_sorter);
   g_clear_pointer (&self->title, g_free);
   g_clear_object (&self->menu);
 
@@ -144,7 +144,7 @@ gtk_column_view_column_get_property (GObject    *object,
       break;
 
     case PROP_SORTER:
-      g_value_set_object (value, self->sorter);
+      g_value_set_object (value, gtk_column_view_column_get_sorter (self));
       break;
 
     case PROP_VISIBLE:
@@ -699,24 +699,13 @@ gtk_column_view_column_get_title (GtkColumnViewColumn *self)
   return self->title;
 }
 
-#if 0
-static void
-gtk_column_view_column_add_to_sorter (GtkColumnViewColumn *self)
-{
-  if (self->view == NULL)
-    return;
-  
-  gtk_column_view_sorter_add_column (GTK_COLUMN_VIEW_SORTER (gtk_column_view_get_sorter (self->view)), self);
-}
-#endif
-
 static void
 gtk_column_view_column_remove_from_sorter (GtkColumnViewColumn *self)
 {
   if (self->view == NULL)
     return;
   
-  gtk_column_view_sorter_remove_column (GTK_COLUMN_VIEW_SORTER (gtk_column_view_get_sorter (self->view)), 
self);
+  gtk_column_view_sorter_remove_column (gtk_column_view_get_sorter (self->view), self);
 }
 
 /**
@@ -742,9 +731,25 @@ gtk_column_view_column_set_sorter (GtkColumnViewColumn *self,
   g_return_if_fail (GTK_IS_COLUMN_VIEW_COLUMN (self));
   g_return_if_fail (sorter == NULL || GTK_IS_SORTER (sorter));
 
-  if (!g_set_object (&self->sorter, sorter))
+  if (self->invertible_sorter == NULL && sorter == NULL)
+    return;
+
+  if (self->invertible_sorter != NULL &&
+      sorter == gtk_invertible_sorter_get_sorter (self->invertible_sorter))
     return;
 
+  if (sorter)
+    {
+      if (!self->invertible_sorter)
+        {
+          self->invertible_sorter = gtk_invertible_sorter_new (NULL);
+          g_object_set_data (G_OBJECT (self->invertible_sorter), "column", self);
+        }
+      gtk_invertible_sorter_set_sorter (self->invertible_sorter, sorter);
+    }
+  else
+    g_clear_object (&self->invertible_sorter);
+
   gtk_column_view_column_remove_from_sorter (self);
 
   if (self->header)
@@ -766,7 +771,10 @@ gtk_column_view_column_get_sorter (GtkColumnViewColumn *self)
 {
   g_return_val_if_fail (GTK_IS_COLUMN_VIEW_COLUMN (self), NULL);
 
-  return self->sorter;
+  if (self->invertible_sorter)
+    return gtk_invertible_sorter_get_sorter (self->invertible_sorter);
+
+  return NULL;
 }
 
 void
@@ -1015,3 +1023,11 @@ gtk_column_view_column_get_header_allocation (GtkColumnViewColumn *self,
   if (size)
     *size = self->allocation_size;
 }
+
+
+GtkInvertibleSorter *
+gtk_column_view_column_get_invertible_sorter (GtkColumnViewColumn *self)
+{
+  return self->invertible_sorter;
+}
+
diff --git a/gtk/gtkcolumnviewcolumnprivate.h b/gtk/gtkcolumnviewcolumnprivate.h
index d71bc8a9dd..ca3c54b4c9 100644
--- a/gtk/gtkcolumnviewcolumnprivate.h
+++ b/gtk/gtkcolumnviewcolumnprivate.h
@@ -23,6 +23,7 @@
 #include "gtk/gtkcolumnviewcolumn.h"
 
 #include "gtk/gtkcolumnviewcellprivate.h"
+#include "gtk/gtkinvertiblesorter.h"
 
 
 void                    gtk_column_view_column_set_column_view          (GtkColumnViewColumn    *self,
@@ -57,4 +58,6 @@ void                    gtk_column_view_column_get_header_allocation    (GtkColu
                                                                          int                    *offset,
                                                                          int                    *size);
 
+GtkInvertibleSorter *   gtk_column_view_column_get_invertible_sorter    (GtkColumnViewColumn *self);
+
 #endif  /* __GTK_COLUMN_VIEW_COLUMN_PRIVATE_H__ */
diff --git a/gtk/gtkcolumnviewsorter.c b/gtk/gtkcolumnviewsorter.c
index a90a14a292..3ccb8bf60e 100644
--- a/gtk/gtkcolumnviewsorter.c
+++ b/gtk/gtkcolumnviewsorter.c
@@ -20,158 +20,35 @@
 #include "config.h"
 
 #include "gtkcolumnviewsorterprivate.h"
-
 #include "gtkcolumnviewcolumnprivate.h"
 #include "gtktypebuiltins.h"
+#include "gtkmultisorter.h"
 
-typedef struct
-{
-  GtkColumnViewColumn *column;
-  GtkSorter *sorter;
-  gboolean   inverted;
-  gulong     changed_id;
-} Sorter;
- 
-static void
-free_sorter (gpointer data)
-{
-  Sorter *s = data;
-
-  g_signal_handler_disconnect (s->sorter, s->changed_id);
-  g_object_unref (s->sorter);
-  g_object_unref (s->column);
-  g_free (s);
-}
-
-struct _GtkColumnViewSorter
-{
-  GtkSorter parent_instance;
-
-  GSequence *sorters;
-};
-
-G_DEFINE_TYPE (GtkColumnViewSorter, gtk_column_view_sorter, GTK_TYPE_SORTER)
-
-static GtkOrdering
-gtk_column_view_sorter_compare (GtkSorter *sorter,
-                                gpointer   item1,
-                                gpointer   item2)
-{
-  GtkColumnViewSorter *self = GTK_COLUMN_VIEW_SORTER (sorter);
-  GtkOrdering result = GTK_ORDERING_EQUAL;
-  GSequenceIter *iter;
-
-  for (iter = g_sequence_get_begin_iter (self->sorters);
-       !g_sequence_iter_is_end (iter);
-       iter = g_sequence_iter_next (iter))
-    {
-      Sorter *s = g_sequence_get (iter);
-
-      result = gtk_sorter_compare (s->sorter, item1, item2);
-      if (s->inverted)
-        result = - result;
-
-      if (result != GTK_ORDERING_EQUAL)
-        break;
-    }
-
-  return result;
-}
-
-static GtkSorterOrder
-gtk_column_view_sorter_get_order (GtkSorter *sorter)
+static GtkColumnViewColumn *
+get_column (GtkInvertibleSorter *sorter)
 {
-  GtkColumnViewSorter *self = GTK_COLUMN_VIEW_SORTER (sorter);
-  GtkSorterOrder result = GTK_SORTER_ORDER_NONE;
-  GSequenceIter *iter;
-
-  for (iter = g_sequence_get_begin_iter (self->sorters);
-       !g_sequence_iter_is_end (iter);
-       iter = g_sequence_iter_next (iter))
-    {
-      Sorter *s = g_sequence_get (iter);
-
-      switch (gtk_sorter_get_order (s->sorter))
-        {
-          case GTK_SORTER_ORDER_PARTIAL:
-            result = GTK_SORTER_ORDER_PARTIAL;
-            break;
-          case GTK_SORTER_ORDER_NONE:
-            break;
-          case GTK_SORTER_ORDER_TOTAL:
-            return GTK_SORTER_ORDER_TOTAL;
-          default:
-            g_assert_not_reached ();
-            break;
-        }
-    }
-
-  return result;
-}
-
-static void
-gtk_column_view_sorter_dispose (GObject *object)
-{
-  GtkColumnViewSorter *self = GTK_COLUMN_VIEW_SORTER (object);
-
-  /* The sorter is owned by the columview and is unreffed
-   * after the columns, so the sequence must be empty at
-   * this point.
-   * The sorter can outlive the columview it comes from
-   * (the model might still have a ref), but that does
-   * not change the fact that all columns will be gone.
-   */
-  g_assert (g_sequence_is_empty (self->sorters));
-  g_clear_pointer (&self->sorters, g_sequence_free);
-
-  G_OBJECT_CLASS (gtk_column_view_sorter_parent_class)->dispose (object);
-}
-
-static void
-gtk_column_view_sorter_class_init (GtkColumnViewSorterClass *class)
-{
-  GtkSorterClass *sorter_class = GTK_SORTER_CLASS (class);
-  GObjectClass *object_class = G_OBJECT_CLASS (class);
-
-  sorter_class->compare = gtk_column_view_sorter_compare;
-  sorter_class->get_order = gtk_column_view_sorter_get_order;
-
-  object_class->dispose = gtk_column_view_sorter_dispose;
-}
-
-static void
-gtk_column_view_sorter_init (GtkColumnViewSorter *self)
-{
-  self->sorters = g_sequence_new (free_sorter);
-}
-
-GtkColumnViewSorter *
-gtk_column_view_sorter_new (void)
-{
-  return g_object_new (GTK_TYPE_COLUMN_VIEW_SORTER, NULL);
-}
-
-static void
-gtk_column_view_sorter_changed_cb (GtkSorter *sorter, int change, gpointer data)
-{
-  gtk_sorter_changed (GTK_SORTER (data), GTK_SORTER_CHANGE_DIFFERENT);
+  return GTK_COLUMN_VIEW_COLUMN (g_object_get_data (G_OBJECT (sorter), "column"));
 }
 
 static gboolean
-remove_column (GtkColumnViewSorter *self,
+remove_column (GtkSorter           *self,
                GtkColumnViewColumn *column)
 {
-  GSequenceIter *iter;
+  GtkSorter *sorter = GTK_SORTER (gtk_column_view_column_get_invertible_sorter (column));
+
+  if (sorter == NULL)
+    return FALSE;
 
-  for (iter = g_sequence_get_begin_iter (self->sorters);
-       !g_sequence_iter_is_end (iter);
-       iter = g_sequence_iter_next (iter))
+  for (guint i = 0; i < g_list_model_get_n_items (G_LIST_MODEL (self)); i++)
     {
-      Sorter *s = g_sequence_get (iter);
+      GtkSorter *s;
 
-      if (s->column == column)
+      s = g_list_model_get_item (G_LIST_MODEL (self), i);
+      g_object_unref (s);
+
+      if (s == sorter)
         {
-          g_sequence_remove (iter);
+          gtk_multi_sorter_remove (GTK_MULTI_SORTER (self), i);
           return TRUE;
         }
     }
@@ -180,49 +57,43 @@ remove_column (GtkColumnViewSorter *self,
 }
 
 gboolean
-gtk_column_view_sorter_add_column (GtkColumnViewSorter *self,
+gtk_column_view_sorter_add_column (GtkSorter           *self,
                                    GtkColumnViewColumn *column)
 {
-  GSequenceIter *iter;
-  GtkSorter *sorter;
-  Sorter *s, *first;
+  GtkMultiSorter *multi = GTK_MULTI_SORTER (self);
+  GtkInvertibleSorter *sorter, *s;
 
-  g_return_val_if_fail (GTK_IS_COLUMN_VIEW_SORTER (self), FALSE);
+  g_return_val_if_fail (GTK_IS_MULTI_SORTER (self), FALSE);
   g_return_val_if_fail (GTK_IS_COLUMN_VIEW_COLUMN (column), FALSE);
 
-  sorter = gtk_column_view_column_get_sorter (column);
+  sorter = gtk_column_view_column_get_invertible_sorter (column);
   if (sorter == NULL)
     return FALSE;
 
-  iter = g_sequence_get_begin_iter (self->sorters);
-  if (!g_sequence_iter_is_end (iter))
+  s = g_list_model_get_item (G_LIST_MODEL (self), 0);
+  g_object_unref (s);
+  if (s == sorter)
     {
-      first = g_sequence_get (iter);
-      if (first->column == column)
+      switch (gtk_invertible_sorter_get_sort_order (s))
         {
-          first->inverted = !first->inverted;
-          goto out;
+        case GTK_SORT_ASCENDING:
+          gtk_invertible_sorter_set_sort_order (s, GTK_SORT_DESCENDING);
+          break;
+        case GTK_SORT_DESCENDING:
+          gtk_invertible_sorter_set_sort_order (s, GTK_SORT_ASCENDING);
+          break;
+        default:
+          g_assert_not_reached ();
+          break;
         }
     }
   else
-    first = NULL;
-
-  remove_column (self, column);
-
-  s = g_new (Sorter, 1);
-  s->column = g_object_ref (column);
-  s->sorter = g_object_ref (sorter);
-  s->changed_id = g_signal_connect (sorter, "changed", G_CALLBACK (gtk_column_view_sorter_changed_cb), self);
-  s->inverted = FALSE;
- 
-  g_sequence_insert_before (iter, s);
-
-  /* notify the previous first column to stop drawing an arrow */
-  if (first)
-    gtk_column_view_column_notify_sort (first->column);
-
-out:
-  gtk_sorter_changed (GTK_SORTER (self), GTK_SORTER_CHANGE_DIFFERENT);
+    {
+      /* notify the previous first column to stop drawing an arrow */
+      gtk_column_view_column_notify_sort (get_column (s));
+      remove_column (self, column);
+      gtk_multi_sorter_splice (multi, 0, 0, (GtkSorter **)&sorter, 1);
+    }
 
   gtk_column_view_column_notify_sort (column);
 
@@ -230,101 +101,62 @@ out:
 }
 
 gboolean
-gtk_column_view_sorter_remove_column (GtkColumnViewSorter *self,
+gtk_column_view_sorter_remove_column (GtkSorter           *self,
                                       GtkColumnViewColumn *column)
 {
-  g_return_val_if_fail (GTK_IS_COLUMN_VIEW_SORTER (self), FALSE);
+  g_return_val_if_fail (GTK_IS_MULTI_SORTER (self), FALSE);
   g_return_val_if_fail (GTK_IS_COLUMN_VIEW_COLUMN (column), FALSE);
 
   if (remove_column (self, column))
-    {
-      gtk_sorter_changed (GTK_SORTER (self), GTK_SORTER_CHANGE_DIFFERENT);
-      gtk_column_view_column_notify_sort (column);
-      return TRUE;
-    }
+    return TRUE;
 
   return FALSE;
 }
 
 gboolean
-gtk_column_view_sorter_set_column (GtkColumnViewSorter *self,
+gtk_column_view_sorter_set_column (GtkSorter           *self,
                                    GtkColumnViewColumn *column,
-                                   gboolean             inverted)
+                                   GtkSortType          direction)
 {
+  GtkMultiSorter *multi = GTK_MULTI_SORTER (self);
   GtkSorter *sorter;
-  Sorter *s;
 
-  g_return_val_if_fail (GTK_IS_COLUMN_VIEW_SORTER (self), FALSE);
+  g_return_val_if_fail (GTK_IS_MULTI_SORTER (self), FALSE);
   g_return_val_if_fail (GTK_IS_COLUMN_VIEW_COLUMN (column), FALSE);
-  
-  sorter = gtk_column_view_column_get_sorter (column);
+
+  sorter = GTK_SORTER (gtk_column_view_column_get_invertible_sorter (column));
   if (sorter == NULL)
     return FALSE;
 
-  g_object_ref (column);
-
-  g_sequence_remove_range (g_sequence_get_begin_iter (self->sorters),
-                           g_sequence_get_end_iter (self->sorters));
-
-  s = g_new (Sorter, 1);
-  s->column = g_object_ref (column);
-  s->sorter = g_object_ref (sorter);
-  s->changed_id = g_signal_connect (sorter, "changed", G_CALLBACK (gtk_column_view_sorter_changed_cb), self);
-  s->inverted = inverted;
- 
-  g_sequence_prepend (self->sorters, s);
-
-  gtk_sorter_changed (GTK_SORTER (self), GTK_SORTER_CHANGE_DIFFERENT);
+  gtk_invertible_sorter_set_sort_order (GTK_INVERTIBLE_SORTER (sorter), direction);
+  gtk_multi_sorter_splice (multi, 0, g_list_model_get_n_items (G_LIST_MODEL (self)), &sorter, 1);
 
   gtk_column_view_column_notify_sort (column);
 
-  g_object_unref (column);
-
   return TRUE;
 }
 
 void
-gtk_column_view_sorter_clear (GtkColumnViewSorter *self)
+gtk_column_view_sorter_clear (GtkSorter *self)
 {
-  GSequenceIter *iter;
-  Sorter *s;
+  GtkMultiSorter *multi = GTK_MULTI_SORTER (self);
+  GtkInvertibleSorter *sorter;
   GtkColumnViewColumn *column;
 
-  g_return_if_fail (GTK_IS_COLUMN_VIEW_SORTER (self));
+  g_return_if_fail (GTK_IS_MULTI_SORTER (self));
 
-  if (g_sequence_is_empty (self->sorters))
+  if (g_list_model_get_n_items (G_LIST_MODEL (self)) == 0)
     return;
 
-  iter = g_sequence_get_begin_iter (self->sorters);
-  s = g_sequence_get (iter);
-
-  column = g_object_ref (s->column);
+  sorter = g_list_model_get_item (G_LIST_MODEL (self), 0);
+  g_object_unref (sorter);
 
-  g_sequence_remove_range (iter, g_sequence_get_end_iter (self->sorters));
+  column = get_column (sorter);
+  g_object_ref (column);
 
-  gtk_sorter_changed (GTK_SORTER (self), GTK_SORTER_CHANGE_DIFFERENT);
+  gtk_multi_sorter_splice (multi, 0, g_list_model_get_n_items (G_LIST_MODEL (self)), NULL, 0);
 
   gtk_column_view_column_notify_sort (column);
 
   g_object_unref (column);
 }
-
-GtkColumnViewColumn *
-gtk_column_view_sorter_get_sort_column (GtkColumnViewSorter *self,
-                                        gboolean            *inverted)
-{
-  GSequenceIter *iter;
-  Sorter *s;
-
-  g_return_val_if_fail (GTK_IS_COLUMN_VIEW_SORTER (self), NULL);
-
-  if (g_sequence_is_empty (self->sorters))
-    return NULL;
-
-  iter = g_sequence_get_begin_iter (self->sorters);
-  s = g_sequence_get (iter);
-
-  *inverted = s->inverted;
-
-  return s->column;
-}
diff --git a/gtk/gtkcolumnviewsorterprivate.h b/gtk/gtkcolumnviewsorterprivate.h
index 9d47d0a105..545d9b4063 100644
--- a/gtk/gtkcolumnviewsorterprivate.h
+++ b/gtk/gtkcolumnviewsorterprivate.h
@@ -30,28 +30,18 @@
 
 G_BEGIN_DECLS
 
-#define GTK_TYPE_COLUMN_VIEW_SORTER             (gtk_column_view_sorter_get_type ())
+gboolean              gtk_column_view_sorter_add_column      (GtkSorter           *self,
+                                                              GtkColumnViewColumn *column);
+gboolean              gtk_column_view_sorter_remove_column   (GtkSorter           *self,
+                                                              GtkColumnViewColumn *column);
 
-G_DECLARE_FINAL_TYPE (GtkColumnViewSorter, gtk_column_view_sorter, GTK, COLUMN_VIEW_SORTER, GtkSorter)
-
-GtkColumnViewSorter *   gtk_column_view_sorter_new              (void);
-
-gboolean                gtk_column_view_sorter_add_column       (GtkColumnViewSorter    *self,
-                                                                 GtkColumnViewColumn    *column);
-gboolean                gtk_column_view_sorter_remove_column    (GtkColumnViewSorter    *self,
-                                                                 GtkColumnViewColumn    *column);
-
-void                    gtk_column_view_sorter_clear            (GtkColumnViewSorter    *self);
-
-GtkColumnViewColumn *   gtk_column_view_sorter_get_sort_column  (GtkColumnViewSorter    *self,
-                                                                 gboolean               *inverted);
-
-gboolean   gtk_column_view_sorter_set_column    (GtkColumnViewSorter *self,
-                                                 GtkColumnViewColumn *column,
-                                                 gboolean             inverted);
+void                  gtk_column_view_sorter_clear           (GtkSorter           *self);
 
+gboolean              gtk_column_view_sorter_set_column      (GtkSorter           *self,
+                                                              GtkColumnViewColumn *column,
+                                                              GtkSortType          direction);
 
 G_END_DECLS
 
-#endif /* __GTK_SORTER_H__ */
+#endif /* __GTK_COLUMN_VIEW_SORTER_H__ */
 
diff --git a/gtk/gtkcolumnviewtitle.c b/gtk/gtkcolumnviewtitle.c
index cb75bc1d74..e1807ca022 100644
--- a/gtk/gtkcolumnviewtitle.c
+++ b/gtk/gtkcolumnviewtitle.c
@@ -189,14 +189,14 @@ activate_sort (GtkColumnViewTitle *self)
 {
   GtkSorter *sorter;
   GtkColumnView *view;
-  GtkColumnViewSorter *view_sorter;
+  GtkSorter *view_sorter;
 
   sorter = gtk_column_view_column_get_sorter (self->column);
   if (sorter == NULL)
     return;
 
   view = gtk_column_view_column_get_column_view (self->column);
-  view_sorter = GTK_COLUMN_VIEW_SORTER (gtk_column_view_get_sorter (view));
+  view_sorter = gtk_column_view_get_sorter (view);
   gtk_column_view_sorter_add_column (view_sorter, self->column);
 }
 
@@ -291,29 +291,32 @@ gtk_column_view_title_new (GtkColumnViewColumn *column)
 void
 gtk_column_view_title_update (GtkColumnViewTitle *self)
 {
-  GtkSorter *sorter;
-  GtkColumnView *view;
-  GtkColumnViewSorter *view_sorter;
-  gboolean inverted;
-  GtkColumnViewColumn *active;
+  GtkInvertibleSorter *sorter;
 
   gtk_label_set_label (GTK_LABEL (self->title), gtk_column_view_column_get_title (self->column));
 
-  sorter = gtk_column_view_column_get_sorter (self->column);
+  sorter = gtk_column_view_column_get_invertible_sorter (self->column);
 
   if (sorter)
     {
+      GtkColumnView *view;
+      GtkSorter *view_sorter;
+      GtkInvertibleSorter *active;
+      GtkSortType direction;
+
       view = gtk_column_view_column_get_column_view (self->column);
-      view_sorter = GTK_COLUMN_VIEW_SORTER (gtk_column_view_get_sorter (view));
-      active = gtk_column_view_sorter_get_sort_column (view_sorter, &inverted);
+      view_sorter = gtk_column_view_get_sorter (view);
+      active = g_list_model_get_item (G_LIST_MODEL (view_sorter), 0);
+      g_object_unref (active);
+      direction = gtk_invertible_sorter_get_sort_order (active);
 
       gtk_widget_show (self->sort);
       gtk_widget_remove_css_class (self->sort, "ascending");
       gtk_widget_remove_css_class (self->sort, "descending");
       gtk_widget_remove_css_class (self->sort, "unsorted");
-      if (self->column != active)
+      if (sorter != active)
         gtk_widget_add_css_class (self->sort, "unsorted");
-      else if (inverted)
+      else if (direction == GTK_SORT_DESCENDING)
         gtk_widget_add_css_class (self->sort, "descending");
       else
         gtk_widget_add_css_class (self->sort, "ascending");


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