[gtk/column-sorting: 9/10] columnview: Reimplement column view sorting




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

    columnview: 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        | 335 ++++++++++-----------------------------
 gtk/gtkcolumnviewsorterprivate.h |  27 ++--
 gtk/gtkcolumnviewtitle.c         |  32 ++--
 6 files changed, 155 insertions(+), 305 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..e352e7019a 100644
--- a/gtk/gtkcolumnviewsorter.c
+++ b/gtk/gtkcolumnviewsorter.c
@@ -20,311 +20,146 @@
 #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)
+static GtkColumnViewColumn *
+get_column (GtkInvertibleSorter *sorter)
 {
-  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);
+  return GTK_COLUMN_VIEW_COLUMN (g_object_get_data (G_OBJECT (sorter), "column"));
 }
 
-struct _GtkColumnViewSorter
+static void
+remove_column (GtkSorter           *self,
+               GtkColumnViewColumn *column)
 {
-  GtkSorter parent_instance;
+  GtkInvertibleSorter *sorter = gtk_column_view_column_get_invertible_sorter (column);
 
-  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;
+  if (sorter == NULL)
+    return;
 
-  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);
+      GtkInvertibleSorter *s;
 
-      result = gtk_sorter_compare (s->sorter, item1, item2);
-      if (s->inverted)
-        result = - result;
+      s = g_list_model_get_item (G_LIST_MODEL (self), i);
+      g_object_unref (s);
 
-      if (result != GTK_ORDERING_EQUAL)
-        break;
-    }
-
-  return result;
-}
-
-static GtkSorterOrder
-gtk_column_view_sorter_get_order (GtkSorter *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))
+      if (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;
+          gtk_multi_sorter_remove (GTK_MULTI_SORTER (self), i);
+          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)
+void
+gtk_column_view_sorter_activate_column (GtkSorter           *self,
+                                        GtkColumnViewColumn *column)
 {
-  self->sorters = g_sequence_new (free_sorter);
-}
+  GtkMultiSorter *multi = GTK_MULTI_SORTER (self);
+  GtkInvertibleSorter *sorter, *s;
 
-GtkColumnViewSorter *
-gtk_column_view_sorter_new (void)
-{
-  return g_object_new (GTK_TYPE_COLUMN_VIEW_SORTER, NULL);
-}
+  g_return_if_fail (GTK_IS_MULTI_SORTER (self));
+  g_return_if_fail (GTK_IS_COLUMN_VIEW_COLUMN (column));
 
-static void
-gtk_column_view_sorter_changed_cb (GtkSorter *sorter, int change, gpointer data)
-{
-  gtk_sorter_changed (GTK_SORTER (data), GTK_SORTER_CHANGE_DIFFERENT);
-}
-
-static gboolean
-remove_column (GtkColumnViewSorter *self,
-               GtkColumnViewColumn *column)
-{
-  GSequenceIter *iter;
+  sorter = gtk_column_view_column_get_invertible_sorter (column);
+  if (sorter == NULL)
+    return;
 
-  for (iter = g_sequence_get_begin_iter (self->sorters);
-       !g_sequence_iter_is_end (iter);
-       iter = g_sequence_iter_next (iter))
+  if (g_list_model_get_n_items (G_LIST_MODEL (self)) > 0)
     {
-      Sorter *s = g_sequence_get (iter);
-
-      if (s->column == column)
-        {
-          g_sequence_remove (iter);
-          return TRUE;
-        }
+      s = g_list_model_get_item (G_LIST_MODEL (self), 0);
     }
+  else
+    s = NULL;
 
-  return FALSE;
-}
-
-gboolean
-gtk_column_view_sorter_add_column (GtkColumnViewSorter *self,
-                                   GtkColumnViewColumn *column)
-{
-  GSequenceIter *iter;
-  GtkSorter *sorter;
-  Sorter *s, *first;
-
-  g_return_val_if_fail (GTK_IS_COLUMN_VIEW_SORTER (self), FALSE);
-  g_return_val_if_fail (GTK_IS_COLUMN_VIEW_COLUMN (column), FALSE);
-
-  sorter = gtk_column_view_column_get_sorter (column);
-  if (sorter == NULL)
-    return FALSE;
+  if (s == sorter)
+    {
+      /* column is already first, toggle sort order */
+      gtk_invertible_sorter_set_sort_order (s, 1 - gtk_invertible_sorter_get_sort_order (s));
 
-  iter = g_sequence_get_begin_iter (self->sorters);
-  if (!g_sequence_iter_is_end (iter))
+      gtk_column_view_column_notify_sort (column);
+    }
+  else
     {
-      first = g_sequence_get (iter);
-      if (first->column == column)
+      /* move column to the first position */
+      remove_column (self, column);
+      gtk_invertible_sorter_set_sort_order (GTK_INVERTIBLE_SORTER (sorter), GTK_SORT_ASCENDING);
+      g_object_ref (sorter);
+      gtk_multi_sorter_splice (multi, 0, 0, (GtkSorter **)&sorter, 1);
+
+      if (s)
         {
-          first->inverted = !first->inverted;
-          goto out;
+          gtk_column_view_column_notify_sort (get_column (s));
+          g_object_unref (s);
         }
+      gtk_column_view_column_notify_sort (column);
     }
-  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);
-
-  gtk_column_view_column_notify_sort (column);
-
-  return TRUE;
 }
 
-gboolean
-gtk_column_view_sorter_remove_column (GtkColumnViewSorter *self,
+void
+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_COLUMN_VIEW_COLUMN (column), FALSE);
+  g_return_if_fail (GTK_IS_MULTI_SORTER (self));
+  g_return_if_fail (GTK_IS_COLUMN_VIEW_COLUMN (column));
 
-  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 FALSE;
+  remove_column (self, column);
 }
 
-gboolean
-gtk_column_view_sorter_set_column (GtkColumnViewSorter *self,
+void
+gtk_column_view_sorter_set_column (GtkSorter           *self,
                                    GtkColumnViewColumn *column,
-                                   gboolean             inverted)
+                                   GtkSortType          direction)
 {
+  GtkMultiSorter *multi = GTK_MULTI_SORTER (self);
   GtkSorter *sorter;
-  Sorter *s;
+  GtkInvertibleSorter *s;
+
+  g_return_if_fail (GTK_IS_MULTI_SORTER (self));
+  g_return_if_fail (GTK_IS_COLUMN_VIEW_COLUMN (column));
 
-  g_return_val_if_fail (GTK_IS_COLUMN_VIEW_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;
+    return;
 
-  g_object_ref (column);
+  if (g_list_model_get_n_items (G_LIST_MODEL (self)) > 0)
+    s = g_list_model_get_item (G_LIST_MODEL (self), 0);
+  else
+    s = NULL;
 
-  g_sequence_remove_range (g_sequence_get_begin_iter (self->sorters),
-                           g_sequence_get_end_iter (self->sorters));
+  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 = inverted;
- 
-  g_sequence_prepend (self->sorters, s);
+  gtk_invertible_sorter_set_sort_order (GTK_INVERTIBLE_SORTER (sorter), direction);
+  g_object_ref (sorter);
+  gtk_multi_sorter_splice (multi, 0, 0, &sorter, 1);
 
-  gtk_sorter_changed (GTK_SORTER (self), GTK_SORTER_CHANGE_DIFFERENT);
+  if (s)
+    {
+      gtk_column_view_column_notify_sort (get_column (s));
+      g_object_unref (s);
+    }
 
   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;
-  GtkColumnViewColumn *column;
+  GtkMultiSorter *multi = GTK_MULTI_SORTER (self);
+  GtkInvertibleSorter *s;
 
-  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);
-
-  g_sequence_remove_range (iter, g_sequence_get_end_iter (self->sorters));
-
-  gtk_sorter_changed (GTK_SORTER (self), GTK_SORTER_CHANGE_DIFFERENT);
-
-  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);
+  s = g_list_model_get_item (G_LIST_MODEL (self), 0);
 
-  *inverted = s->inverted;
+  gtk_multi_sorter_splice (multi, 0, g_list_model_get_n_items (G_LIST_MODEL (self)), NULL, 0);
 
-  return s->column;
+  gtk_column_view_column_notify_sort (get_column (s));
+  g_object_unref (s);
 }
diff --git a/gtk/gtkcolumnviewsorterprivate.h b/gtk/gtkcolumnviewsorterprivate.h
index 9d47d0a105..8fe73d72b6 100644
--- a/gtk/gtkcolumnviewsorterprivate.h
+++ b/gtk/gtkcolumnviewsorterprivate.h
@@ -30,28 +30,19 @@
 
 G_BEGIN_DECLS
 
-#define GTK_TYPE_COLUMN_VIEW_SORTER             (gtk_column_view_sorter_get_type ())
+void      gtk_column_view_sorter_activate_column (GtkSorter           *self,
+                                                  GtkColumnViewColumn *column);
+void      gtk_column_view_sorter_remove_column   (GtkSorter           *self,
+                                                  GtkColumnViewColumn *column);
 
-G_DECLARE_FINAL_TYPE (GtkColumnViewSorter, gtk_column_view_sorter, GTK, COLUMN_VIEW_SORTER, GtkSorter)
+void      gtk_column_view_sorter_clear           (GtkSorter           *self);
 
-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_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..9899e3d450 100644
--- a/gtk/gtkcolumnviewtitle.c
+++ b/gtk/gtkcolumnviewtitle.c
@@ -189,15 +189,15 @@ 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));
-  gtk_column_view_sorter_add_column (view_sorter, self->column);
+  view_sorter = gtk_column_view_get_sorter (view);
+  gtk_column_view_sorter_activate_column (view_sorter, self->column);
 }
 
 static void
@@ -291,29 +291,35 @@ 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 = NULL;
+      GtkSortType direction = GTK_SORT_ASCENDING;
+
       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);
+      if (g_list_model_get_n_items (G_LIST_MODEL (view_sorter)) > 0)
+        {
+          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]