[gtk/wip/matthiasc/columnview-sorter-refactor: 2/4] Add gtk_multi_sorter_prepend




commit 896a00f8cb3b5a858a44d3f43534e3bf557c84ee
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon May 16 17:51:54 2022 -0400

    Add gtk_multi_sorter_prepend
    
    This can be useful in implementing columnview
    sorting.

 gtk/gtkmultisorter.c | 27 +++++++++++++++++++++++++++
 gtk/gtkmultisorter.h |  4 ++++
 2 files changed, 31 insertions(+)
---
diff --git a/gtk/gtkmultisorter.c b/gtk/gtkmultisorter.c
index 72d686784b..37eb79f59a 100644
--- a/gtk/gtkmultisorter.c
+++ b/gtk/gtkmultisorter.c
@@ -408,6 +408,33 @@ gtk_multi_sorter_append (GtkMultiSorter *self,
                                 gtk_multi_sort_keys_new (self));
 }
 
+/**
+ * gtk_multi_sorter_prepend:
+ * @self: a `GtkMultiSorter`
+ * @sorter: (transfer full): a sorter to add
+ *
+ * Add @sorter to @self to use for sorting at the beginning.
+ *
+ * @self will consult @sorter first before all existing sorters.
+ *
+ * Since: 4.8
+ */
+void
+gtk_multi_sorter_prepend (GtkMultiSorter *self,
+                          GtkSorter      *sorter)
+{
+  g_return_if_fail (GTK_IS_MULTI_SORTER (self));
+  g_return_if_fail (GTK_IS_SORTER (sorter));
+
+  g_signal_connect (sorter, "changed", G_CALLBACK (gtk_multi_sorter_changed_cb), self);
+
+  gtk_sorters_splice (&self->sorters, 0, 0, FALSE, &sorter, 1);
+
+  gtk_sorter_changed_with_keys (GTK_SORTER (self),
+                                GTK_SORTER_CHANGE_DIFFERENT,
+                                gtk_multi_sort_keys_new (self));
+}
+
 /**
  * gtk_multi_sorter_remove:
  * @self: a `GtkMultiSorter`
diff --git a/gtk/gtkmultisorter.h b/gtk/gtkmultisorter.h
index d634711d51..4bc9fb680a 100644
--- a/gtk/gtkmultisorter.h
+++ b/gtk/gtkmultisorter.h
@@ -40,6 +40,10 @@ GDK_AVAILABLE_IN_ALL
 void                    gtk_multi_sorter_append                 (GtkMultiSorter         *self,
                                                                  GtkSorter              *sorter);
 
+GDK_AVAILABLE_IN_4_8
+void                    gtk_multi_sorter_prepend                (GtkMultiSorter         *self,
+                                                                 GtkSorter              *sorter);
+
 GDK_AVAILABLE_IN_ALL
 void                    gtk_multi_sorter_remove                 (GtkMultiSorter         *self,
                                                                  guint                   position);


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