[gtk/prop-list] Add GtkSorter
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/prop-list] Add GtkSorter
- Date: Tue, 3 Dec 2019 05:28:10 +0000 (UTC)
commit 081fe4c2cf3d81d115cd33c5500225b077fc5bd3
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Dec 2 23:43:14 2019 -0500
Add GtkSorter
This is a helper object for sorting. Also add
two implementations, GtkStringSorter for collating
strings, and GtkCustomSorter, which uses a GCompareDataFunc.
gtk/gtk.h | 3 +
gtk/gtkcustomsorter.c | 90 ++++++++++++++++++
gtk/gtkcustomsorter.h | 43 +++++++++
gtk/gtksorter.c | 190 ++++++++++++++++++++++++++++++++++++++
gtk/gtksorter.h | 75 +++++++++++++++
gtk/gtkstringsorter.c | 251 ++++++++++++++++++++++++++++++++++++++++++++++++++
gtk/gtkstringsorter.h | 52 +++++++++++
gtk/meson.build | 3 +
8 files changed, 707 insertions(+)
---
diff --git a/gtk/gtk.h b/gtk/gtk.h
index d2e9b8b079..1e7652d612 100644
--- a/gtk/gtk.h
+++ b/gtk/gtk.h
@@ -93,6 +93,7 @@
#include <gtk/gtkcoverflow.h>
#include <gtk/gtkcssprovider.h>
#include <gtk/gtkcustomlayout.h>
+#include <gtk/gtkcustomsorter.h>
#include <gtk/gtkdebug.h>
#include <gtk/gtkdialog.h>
#include <gtk/gtkdirectorylist.h>
@@ -230,6 +231,7 @@
#include <gtk/gtksingleselection.h>
#include <gtk/gtkslicelistmodel.h>
#include <gtk/gtksnapshot.h>
+#include <gtk/gtksorter.h>
#include <gtk/gtksortlistmodel.h>
#include <gtk/gtkstacksidebar.h>
#include <gtk/gtksizegroup.h>
@@ -240,6 +242,7 @@
#include <gtk/gtkstackswitcher.h>
#include <gtk/gtkstatusbar.h>
#include <gtk/gtkstringfilter.h>
+#include <gtk/gtkstringsorter.h>
#include <gtk/gtkstylecontext.h>
#include <gtk/gtkstyleprovider.h>
#include <gtk/gtkswitch.h>
diff --git a/gtk/gtkcustomsorter.c b/gtk/gtkcustomsorter.c
new file mode 100644
index 0000000000..2f62122769
--- /dev/null
+++ b/gtk/gtkcustomsorter.c
@@ -0,0 +1,90 @@
+/*
+ * Copyright © 2019 Matthias Clasen
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Matthias Clasen <mclasen redhat com>
+ */
+
+#include "config.h"
+
+#include "gtkcustomsorter.h"
+
+#include "gtkintl.h"
+#include "gtktypebuiltins.h"
+
+struct _GtkCustomSorter
+{
+ GtkSorter parent_instance;
+
+ GCompareDataFunc sort_func;
+ gpointer user_data;
+ GDestroyNotify user_destroy;
+};
+
+G_DEFINE_TYPE (GtkCustomSorter, gtk_custom_sorter, GTK_TYPE_SORTER)
+
+static int
+gtk_custom_sorter_compare (GtkSorter *sorter,
+ gpointer item1,
+ gpointer item2)
+{
+ GtkCustomSorter *self = GTK_CUSTOM_SORTER (sorter);
+
+ return self->sort_func (item1, item2, self->user_data);
+}
+
+static void
+gtk_custom_sorter_dispose (GObject *object)
+{
+ GtkCustomSorter *self = GTK_CUSTOM_SORTER (object);
+
+ if (self->user_destroy)
+ self->user_destroy (self->user_data);
+
+ G_OBJECT_CLASS (gtk_custom_sorter_parent_class)->dispose (object);
+}
+
+static void
+gtk_custom_sorter_class_init (GtkCustomSorterClass *class)
+{
+ GtkSorterClass *sorter_class = GTK_SORTER_CLASS (class);
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+ sorter_class->compare = gtk_custom_sorter_compare;
+
+ object_class->dispose = gtk_custom_sorter_dispose;
+}
+
+static void
+gtk_custom_sorter_init (GtkCustomSorter *self)
+{
+ gtk_sorter_changed (GTK_SORTER (self));
+}
+
+GtkSorter *
+gtk_custom_sorter_new (GCompareDataFunc sort_func,
+ gpointer user_data,
+ GDestroyNotify user_destroy)
+{
+ GtkCustomSorter *sorter;
+
+ sorter = g_object_new (GTK_TYPE_CUSTOM_SORTER, NULL);
+
+ sorter->sort_func = sort_func;
+ sorter->user_data = user_data;
+ sorter->user_destroy = user_destroy;
+
+ return GTK_SORTER (sorter);
+}
diff --git a/gtk/gtkcustomsorter.h b/gtk/gtkcustomsorter.h
new file mode 100644
index 0000000000..3cfadef152
--- /dev/null
+++ b/gtk/gtkcustomsorter.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright © 2019 Matthias Clasen
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Matthias Clasen <mclasen redhat com>
+ */
+
+#ifndef __GTK_CUSTOM_SORTER_H__
+#define __GTK_CUSTOM_SORTER_H__
+
+#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
+#error "Only <gtk/gtk.h> can be included directly."
+#endif
+
+#include <gtk/gtkexpression.h>
+#include <gtk/gtksorter.h>
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_CUSTOM_SORTER (gtk_custom_sorter_get_type ())
+GDK_AVAILABLE_IN_ALL
+G_DECLARE_FINAL_TYPE (GtkCustomSorter, gtk_custom_sorter, GTK, CUSTOM_SORTER, GtkSorter)
+
+GDK_AVAILABLE_IN_ALL
+GtkSorter * gtk_custom_sorter_new (GCompareDataFunc sort_func,
+ gpointer user_data,
+ GDestroyNotify user_destroy);
+
+G_END_DECLS
+
+#endif /* __GTK_CUSTOM_SORTER_H__ */
diff --git a/gtk/gtksorter.c b/gtk/gtksorter.c
new file mode 100644
index 0000000000..1231fa6ef8
--- /dev/null
+++ b/gtk/gtksorter.c
@@ -0,0 +1,190 @@
+/*
+ * Copyright © 2019 Matthias Clasen
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Matthias Clasen <mclasen redhat com>
+ */
+
+#include "config.h"
+
+#include "gtksorter.h"
+
+#include "gtkintl.h"
+#include "gtktypebuiltins.h"
+
+typedef struct _GtkSorterPrivate GtkSorterPrivate;
+struct _GtkSorterPrivate
+{
+ GtkSortType sort_direction;
+};
+
+enum {
+ CHANGED,
+ LAST_SIGNAL
+};
+
+enum {
+ PROP_SORT_DIRECTION = 1,
+ NUM_PROPERTIES
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (GtkSorter, gtk_sorter, G_TYPE_OBJECT)
+
+static guint signals[LAST_SIGNAL] = { 0 };
+static GParamSpec *props[NUM_PROPERTIES];
+
+static int
+gtk_sorter_default_compare (GtkSorter *self,
+ gpointer item1,
+ gpointer item2)
+{
+ g_critical ("Sorter of type '%s' does not implement GtkSorter::compare", G_OBJECT_TYPE_NAME (self));
+
+ return 0;
+}
+
+static void
+gtk_sorter_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GtkSorter *sorter = GTK_SORTER (object);
+
+ switch (prop_id)
+ {
+ case PROP_SORT_DIRECTION:
+ gtk_sorter_set_sort_direction (sorter, g_value_get_enum (value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gtk_sorter_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GtkSorter *sorter = GTK_SORTER (object);
+
+ switch (prop_id)
+ {
+ case PROP_SORT_DIRECTION:
+ g_value_set_enum (value, gtk_sorter_get_sort_direction (sorter));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+
+static void
+gtk_sorter_class_init (GtkSorterClass *class)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (class);
+
+ gobject_class->set_property = gtk_sorter_set_property;
+ gobject_class->get_property = gtk_sorter_get_property;
+
+ class->compare = gtk_sorter_default_compare;
+
+ props[PROP_SORT_DIRECTION] =
+ g_param_spec_enum ("sort-direction",
+ P_("Sort direction"),
+ P_("Whether to sort ascending or descending"),
+ GTK_TYPE_SORT_TYPE,
+ GTK_SORT_ASCENDING,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
+
+ g_object_class_install_properties (gobject_class, NUM_PROPERTIES, props);
+
+ /**
+ * GtkSearch:changed:
+ * @self: The #GtkSorter
+ *
+ * This signal is emitted whenever the sorter changed. Users of the sorter
+ * should then check items again via gtk_sorter_compare().
+ */
+ signals[CHANGED] =
+ g_signal_new (I_("changed"),
+ G_TYPE_FROM_CLASS (gobject_class),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+ g_signal_set_va_marshaller (signals[CHANGED],
+ G_TYPE_FROM_CLASS (gobject_class),
+ g_cclosure_marshal_VOID__VOIDv);
+}
+
+static void
+gtk_sorter_init (GtkSorter *self)
+{
+}
+
+int
+gtk_sorter_compare (GtkSorter *self,
+ gpointer item1,
+ gpointer item2)
+{
+ GtkSorterPrivate *priv = gtk_sorter_get_instance_private (self);
+
+ g_return_val_if_fail (GTK_IS_SORTER (self), 0);
+ g_return_val_if_fail (item1 && item2, 0);
+
+ if (priv->sort_direction == GTK_SORT_ASCENDING)
+ return GTK_SORTER_GET_CLASS (self)->compare (self, item1, item2);
+ else
+ return - GTK_SORTER_GET_CLASS (self)->compare (self, item1, item2);
+}
+
+void
+gtk_sorter_set_sort_direction (GtkSorter *self,
+ GtkSortType direction)
+{
+ GtkSorterPrivate *priv = gtk_sorter_get_instance_private (self);
+
+ g_return_if_fail (GTK_IS_SORTER (self));
+
+ if (priv->sort_direction == direction)
+ return;
+
+ priv->sort_direction = direction;
+
+ g_object_notify_by_pspec (G_OBJECT (self), props[PROP_SORT_DIRECTION]);
+
+ g_signal_emit (self, signals[CHANGED], 0);
+}
+
+GtkSortType
+gtk_sorter_get_sort_direction (GtkSorter *self)
+{
+ GtkSorterPrivate *priv = gtk_sorter_get_instance_private (self);
+
+ g_return_val_if_fail (GTK_IS_SORTER (self), GTK_SORT_ASCENDING);
+
+ return priv->sort_direction;
+}
+
+void
+gtk_sorter_changed (GtkSorter *self)
+{
+ g_signal_emit (self, signals[CHANGED], 0);
+}
diff --git a/gtk/gtksorter.h b/gtk/gtksorter.h
new file mode 100644
index 0000000000..3579684b08
--- /dev/null
+++ b/gtk/gtksorter.h
@@ -0,0 +1,75 @@
+/*
+ * Copyright © 2019 Matthias Clasen
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Matthias Clasen <mclasen redhat com>
+ */
+
+#ifndef __GTK_SORTER_H__
+#define __GTK_SORTER_H__
+
+#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
+#error "Only <gtk/gtk.h> can be included directly."
+#endif
+
+#include <gdk/gdk.h>
+#include <gtk/gtkenums.h>
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_SORTER (gtk_sorter_get_type ())
+
+GDK_AVAILABLE_IN_ALL
+G_DECLARE_DERIVABLE_TYPE (GtkSorter, gtk_sorter, GTK, SORTER, GObject)
+
+struct _GtkSorterClass
+{
+ GObjectClass parent_class;
+
+ int (* compare) (GtkSorter *self,
+ gpointer item1,
+ gpointer item2);
+
+ /* Padding for future expansion */
+ void (*_gtk_reserved1) (void);
+ void (*_gtk_reserved2) (void);
+ void (*_gtk_reserved3) (void);
+ void (*_gtk_reserved4) (void);
+ void (*_gtk_reserved5) (void);
+ void (*_gtk_reserved6) (void);
+ void (*_gtk_reserved7) (void);
+ void (*_gtk_reserved8) (void);
+};
+
+GDK_AVAILABLE_IN_ALL
+int gtk_sorter_compare (GtkSorter *self,
+ gpointer item1,
+ gpointer item2);
+
+
+GDK_AVAILABLE_IN_ALL
+void gtk_sorter_set_sort_direction (GtkSorter *self,
+ GtkSortType direction);
+
+GDK_AVAILABLE_IN_ALL
+GtkSortType gtk_sorter_get_sort_direction (GtkSorter *self);
+
+GDK_AVAILABLE_IN_ALL
+void gtk_sorter_changed (GtkSorter *self);
+
+G_END_DECLS
+
+#endif /* __GTK_SORTER_H__ */
+
diff --git a/gtk/gtkstringsorter.c b/gtk/gtkstringsorter.c
new file mode 100644
index 0000000000..998c4a5005
--- /dev/null
+++ b/gtk/gtkstringsorter.c
@@ -0,0 +1,251 @@
+/*
+ * Copyright © 2019 Matthias Clasen
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Matthias Clasen <mclasen redhat com>
+ */
+
+#include "config.h"
+
+#include "gtkstringsorter.h"
+
+#include "gtkintl.h"
+#include "gtktypebuiltins.h"
+
+struct _GtkStringSorter
+{
+ GtkSorter parent_instance;
+
+ gboolean ignore_case;
+
+ GtkExpression *expression;
+};
+
+enum {
+ PROP_0,
+ PROP_EXPRESSION,
+ PROP_IGNORE_CASE,
+ NUM_PROPERTIES
+};
+
+G_DEFINE_TYPE (GtkStringSorter, gtk_string_sorter, GTK_TYPE_SORTER)
+
+static GParamSpec *properties[NUM_PROPERTIES] = { NULL, };
+
+static int
+gtk_string_sorter_compare (GtkSorter *sorter,
+ gpointer item1,
+ gpointer item2)
+{
+ GtkStringSorter *self = GTK_STRING_SORTER (sorter);
+ GValue value1 = G_VALUE_INIT;
+ GValue value2 = G_VALUE_INIT;
+ const char *s1, *s2;
+ int result;
+
+ if (self->expression == NULL ||
+ !gtk_expression_evaluate (self->expression, item1, &value1) ||
+ !gtk_expression_evaluate (self->expression, item2, &value2))
+ return FALSE;
+
+ s1 = g_value_get_string (&value1);
+ s2 = g_value_get_string (&value2);
+
+ if (s1 == NULL || s2 == NULL)
+ return FALSE;
+
+ if (self->ignore_case)
+ {
+ char *t1, *t2;
+
+ t1 = g_utf8_casefold (s1, -1);
+ t2 = g_utf8_casefold (s2, -1);
+
+ result = g_utf8_collate (t1, t2);
+
+ g_free (t1);
+ g_free (t2);
+ }
+ else
+ result = g_utf8_collate (s1, s2);
+
+ g_value_unset (&value1);
+ g_value_unset (&value2);
+
+ return result;
+}
+
+static void
+gtk_string_sorter_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GtkStringSorter *self = GTK_STRING_SORTER (object);
+
+ switch (prop_id)
+ {
+ case PROP_EXPRESSION:
+ gtk_string_sorter_set_expression (self, g_value_get_boxed (value));
+ break;
+
+ case PROP_IGNORE_CASE:
+ gtk_string_sorter_set_ignore_case (self, g_value_get_boolean (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gtk_string_sorter_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GtkStringSorter *self = GTK_STRING_SORTER (object);
+
+ switch (prop_id)
+ {
+ case PROP_EXPRESSION:
+ g_value_set_boxed (value, self->expression);
+ break;
+
+ case PROP_IGNORE_CASE:
+ g_value_set_boolean (value, self->ignore_case);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gtk_string_sorter_dispose (GObject *object)
+{
+ GtkStringSorter *self = GTK_STRING_SORTER (object);
+
+ g_clear_pointer (&self->expression, gtk_expression_unref);
+
+ G_OBJECT_CLASS (gtk_string_sorter_parent_class)->dispose (object);
+}
+
+static void
+gtk_string_sorter_class_init (GtkStringSorterClass *class)
+{
+ GtkSorterClass *sorter_class = GTK_SORTER_CLASS (class);
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+ sorter_class->compare = gtk_string_sorter_compare;
+
+ object_class->get_property = gtk_string_sorter_get_property;
+ object_class->set_property = gtk_string_sorter_set_property;
+ object_class->dispose = gtk_string_sorter_dispose;
+
+ /**
+ * GtkStringSorter:expression:
+ *
+ * The expression to evalute on item to get a string to compare with
+ */
+ properties[PROP_EXPRESSION] =
+ g_param_spec_boxed ("expression",
+ P_("Expression"),
+ P_("Expression to compare with"),
+ GTK_TYPE_EXPRESSION,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
+
+ /**
+ * GtkStringSorter:ignore-case:
+ *
+ * If matching is case sensitive
+ */
+ properties[PROP_IGNORE_CASE] =
+ g_param_spec_boolean ("ignore-case",
+ P_("Ignore case"),
+ P_("If matching is case sensitive"),
+ TRUE,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
+
+ g_object_class_install_properties (object_class, NUM_PROPERTIES, properties);
+
+}
+
+static void
+gtk_string_sorter_init (GtkStringSorter *self)
+{
+ self->ignore_case = TRUE;
+
+ gtk_sorter_changed (GTK_SORTER (self));
+}
+
+GtkSorter *
+gtk_string_sorter_new (void)
+{
+ return g_object_new (GTK_TYPE_STRING_SORTER, NULL);
+}
+
+GtkExpression *
+gtk_string_sorter_get_expression (GtkStringSorter *self)
+{
+ g_return_val_if_fail (GTK_IS_STRING_SORTER (self), NULL);
+
+ return self->expression;
+}
+
+void
+gtk_string_sorter_set_expression (GtkStringSorter *self,
+ GtkExpression *expression)
+{
+ g_return_if_fail (GTK_IS_STRING_SORTER (self));
+ if (expression)
+ g_return_if_fail (gtk_expression_get_value_type (expression) == G_TYPE_STRING);
+
+ if (self->expression == expression)
+ return;
+
+ g_clear_pointer (&self->expression, gtk_expression_unref);
+ self->expression = gtk_expression_ref (expression);
+
+ gtk_sorter_changed (GTK_SORTER (self));
+
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_EXPRESSION]);
+}
+
+gboolean
+gtk_string_sorter_get_ignore_case (GtkStringSorter *self)
+{
+ g_return_val_if_fail (GTK_IS_STRING_SORTER (self), TRUE);
+
+ return self->ignore_case;
+}
+
+void
+gtk_string_sorter_set_ignore_case (GtkStringSorter *self,
+ gboolean ignore_case)
+{
+ g_return_if_fail (GTK_IS_STRING_SORTER (self));
+
+ if (self->ignore_case == ignore_case)
+ return;
+
+ self->ignore_case = ignore_case;
+
+ gtk_sorter_changed (GTK_SORTER (self));
+
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_IGNORE_CASE]);
+}
diff --git a/gtk/gtkstringsorter.h b/gtk/gtkstringsorter.h
new file mode 100644
index 0000000000..d0c749c020
--- /dev/null
+++ b/gtk/gtkstringsorter.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright © 2019 Matthias Clasen
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Matthias Clasen <mclasen redhat com>
+ */
+
+#ifndef __GTK_STRING_SORTER_H__
+#define __GTK_STRING_SORTER_H__
+
+#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
+#error "Only <gtk/gtk.h> can be included directly."
+#endif
+
+#include <gtk/gtkexpression.h>
+#include <gtk/gtksorter.h>
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_STRING_SORTER (gtk_string_sorter_get_type ())
+GDK_AVAILABLE_IN_ALL
+G_DECLARE_FINAL_TYPE (GtkStringSorter, gtk_string_sorter, GTK, STRING_SORTER, GtkSorter)
+
+GDK_AVAILABLE_IN_ALL
+GtkSorter * gtk_string_sorter_new (void);
+
+GDK_AVAILABLE_IN_ALL
+GtkExpression * gtk_string_sorter_get_expression (GtkStringSorter *self);
+GDK_AVAILABLE_IN_ALL
+void gtk_string_sorter_set_expression (GtkStringSorter *self,
+ GtkExpression *expression);
+GDK_AVAILABLE_IN_ALL
+gboolean gtk_string_sorter_get_ignore_case (GtkStringSorter *self);
+GDK_AVAILABLE_IN_ALL
+void gtk_string_sorter_set_ignore_case (GtkStringSorter *self,
+ gboolean ignore_case);
+
+G_END_DECLS
+
+#endif /* __GTK_STRING_SORTER_H__ */
diff --git a/gtk/meson.build b/gtk/meson.build
index e887d3e464..0935329c19 100644
--- a/gtk/meson.build
+++ b/gtk/meson.build
@@ -220,6 +220,7 @@ gtk_public_sources = files([
'gtkconstraint.c',
'gtkcontainer.c',
'gtkcoverflow.c',
+ 'gtkcustomsorter.c',
'gtkcssprovider.c',
'gtkdialog.c',
'gtkdirectorylist.c',
@@ -379,6 +380,7 @@ gtk_public_sources = files([
'gtksizerequest.c',
'gtkslicelistmodel.c',
'gtksnapshot.c',
+ 'gtksorter.c',
'gtksortlistmodel.c',
'gtkspinbutton.c',
'gtkspinner.c',
@@ -387,6 +389,7 @@ gtk_public_sources = files([
'gtkstackswitcher.c',
'gtkstatusbar.c',
'gtkstringfilter.c',
+ 'gtkstringsorter.c',
'gtkstylecontext.c',
'gtkstyleprovider.c',
'gtkswitch.c',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]