2019-12-03 04:43:14 +00:00
|
|
|
/*
|
|
|
|
* 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"
|
|
|
|
|
2020-07-15 18:28:45 +00:00
|
|
|
#include "gtksorterprivate.h"
|
2019-12-03 04:43:14 +00:00
|
|
|
#include "gtktypebuiltins.h"
|
|
|
|
|
|
|
|
/**
|
2021-02-28 18:12:20 +00:00
|
|
|
* GtkStringSorter:
|
2019-12-03 04:43:14 +00:00
|
|
|
*
|
2021-02-28 18:12:20 +00:00
|
|
|
* `GtkStringSorter` is a `GtkSorter` that compares strings.
|
2019-12-03 04:43:14 +00:00
|
|
|
*
|
2021-02-28 18:12:20 +00:00
|
|
|
* It does the comparison in a linguistically correct way using the
|
|
|
|
* current locale by normalizing Unicode strings and possibly case-folding
|
|
|
|
* them before performing the comparison.
|
|
|
|
*
|
|
|
|
* To obtain the strings to compare, this sorter evaluates a
|
|
|
|
* [class@Gtk.Expression].
|
2019-12-03 04:43:14 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
struct _GtkStringSorter
|
|
|
|
{
|
|
|
|
GtkSorter parent_instance;
|
|
|
|
|
|
|
|
gboolean ignore_case;
|
2022-10-11 16:57:09 +00:00
|
|
|
GtkCollation collation;
|
2019-12-03 04:43:14 +00:00
|
|
|
|
|
|
|
GtkExpression *expression;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
PROP_0,
|
|
|
|
PROP_EXPRESSION,
|
|
|
|
PROP_IGNORE_CASE,
|
2022-10-11 16:57:09 +00:00
|
|
|
PROP_COLLATION,
|
2019-12-03 04:43:14 +00:00
|
|
|
NUM_PROPERTIES
|
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GtkStringSorter, gtk_string_sorter, GTK_TYPE_SORTER)
|
|
|
|
|
|
|
|
static GParamSpec *properties[NUM_PROPERTIES] = { NULL, };
|
|
|
|
|
2020-07-15 18:28:45 +00:00
|
|
|
static char *
|
|
|
|
gtk_string_sorter_get_key (GtkExpression *expression,
|
|
|
|
gboolean ignore_case,
|
2022-10-11 16:57:09 +00:00
|
|
|
GtkCollation collation,
|
2020-07-15 18:28:45 +00:00
|
|
|
gpointer item1)
|
2019-12-03 04:43:14 +00:00
|
|
|
{
|
2020-07-15 18:28:45 +00:00
|
|
|
GValue value = G_VALUE_INIT;
|
2022-10-11 16:57:09 +00:00
|
|
|
const char *string;
|
2020-07-15 18:28:45 +00:00
|
|
|
char *s;
|
2022-10-11 16:57:09 +00:00
|
|
|
char *key;
|
2019-12-03 04:43:14 +00:00
|
|
|
|
2020-07-15 18:28:45 +00:00
|
|
|
if (expression == NULL)
|
|
|
|
return NULL;
|
2019-12-03 04:43:14 +00:00
|
|
|
|
2020-07-15 18:28:45 +00:00
|
|
|
if (!gtk_expression_evaluate (expression, item1, &value))
|
|
|
|
return NULL;
|
2019-12-03 04:43:14 +00:00
|
|
|
|
2022-10-11 16:57:09 +00:00
|
|
|
string = g_value_get_string (&value);
|
2020-07-15 18:28:45 +00:00
|
|
|
|
2022-10-11 16:57:09 +00:00
|
|
|
if (ignore_case)
|
|
|
|
s = g_utf8_casefold (string, -1);
|
2020-07-15 18:28:45 +00:00
|
|
|
else
|
2022-10-11 16:57:09 +00:00
|
|
|
s = (char *) string;
|
|
|
|
|
|
|
|
switch (collation)
|
2019-12-03 04:43:14 +00:00
|
|
|
{
|
2022-10-11 16:57:09 +00:00
|
|
|
case GTK_COLLATION_NONE:
|
2022-11-18 04:52:35 +00:00
|
|
|
if (ignore_case)
|
|
|
|
key = g_steal_pointer (&s);
|
|
|
|
else
|
|
|
|
key = g_strdup (s);
|
2022-10-11 16:57:09 +00:00
|
|
|
break;
|
2022-11-18 04:52:35 +00:00
|
|
|
|
2022-10-11 16:57:09 +00:00
|
|
|
case GTK_COLLATION_UNICODE:
|
|
|
|
key = g_utf8_collate_key (s, -1);
|
|
|
|
break;
|
2022-11-18 04:52:35 +00:00
|
|
|
|
2022-10-11 16:57:09 +00:00
|
|
|
case GTK_COLLATION_FILENAME:
|
|
|
|
key = g_utf8_collate_key_for_filename (s, -1);
|
|
|
|
break;
|
2022-11-18 04:52:35 +00:00
|
|
|
|
2022-10-11 16:57:09 +00:00
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
break;
|
2019-12-03 04:43:14 +00:00
|
|
|
}
|
|
|
|
|
2022-10-11 16:57:09 +00:00
|
|
|
if (s != string)
|
|
|
|
g_free (s);
|
|
|
|
|
2020-07-15 18:28:45 +00:00
|
|
|
g_value_unset (&value);
|
2019-12-03 04:43:14 +00:00
|
|
|
|
2022-10-11 16:57:09 +00:00
|
|
|
return key;
|
2020-07-15 18:28:45 +00:00
|
|
|
}
|
2019-12-03 04:43:14 +00:00
|
|
|
|
2020-07-15 18:28:45 +00:00
|
|
|
static GtkOrdering
|
|
|
|
gtk_string_sorter_compare (GtkSorter *sorter,
|
|
|
|
gpointer item1,
|
|
|
|
gpointer item2)
|
|
|
|
{
|
|
|
|
GtkStringSorter *self = GTK_STRING_SORTER (sorter);
|
|
|
|
char *s1, *s2;
|
|
|
|
GtkOrdering result;
|
2019-12-03 04:43:14 +00:00
|
|
|
|
2020-07-15 18:28:45 +00:00
|
|
|
if (self->expression == NULL)
|
|
|
|
return GTK_ORDERING_EQUAL;
|
2019-12-03 04:43:14 +00:00
|
|
|
|
2022-10-11 16:57:09 +00:00
|
|
|
s1 = gtk_string_sorter_get_key (self->expression, self->ignore_case, self->collation, item1);
|
|
|
|
s2 = gtk_string_sorter_get_key (self->expression, self->ignore_case, self->collation, item2);
|
2019-12-03 04:43:14 +00:00
|
|
|
|
2020-07-15 18:28:45 +00:00
|
|
|
result = gtk_ordering_from_cmpfunc (g_strcmp0 (s1, s2));
|
2019-12-03 04:43:14 +00:00
|
|
|
|
2020-07-15 18:28:45 +00:00
|
|
|
g_free (s1);
|
|
|
|
g_free (s2);
|
2019-12-03 04:43:14 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkSorterOrder
|
|
|
|
gtk_string_sorter_get_order (GtkSorter *sorter)
|
|
|
|
{
|
|
|
|
GtkStringSorter *self = GTK_STRING_SORTER (sorter);
|
|
|
|
|
|
|
|
if (self->expression == NULL)
|
|
|
|
return GTK_SORTER_ORDER_NONE;
|
|
|
|
|
|
|
|
return GTK_SORTER_ORDER_PARTIAL;
|
|
|
|
}
|
|
|
|
|
2020-07-15 18:28:45 +00:00
|
|
|
typedef struct _GtkStringSortKeys GtkStringSortKeys;
|
|
|
|
struct _GtkStringSortKeys
|
|
|
|
{
|
|
|
|
GtkSortKeys keys;
|
|
|
|
|
|
|
|
GtkExpression *expression;
|
|
|
|
gboolean ignore_case;
|
2022-10-11 16:57:09 +00:00
|
|
|
GtkCollation collation;
|
2020-07-15 18:28:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_string_sort_keys_free (GtkSortKeys *keys)
|
|
|
|
{
|
|
|
|
GtkStringSortKeys *self = (GtkStringSortKeys *) keys;
|
|
|
|
|
|
|
|
gtk_expression_unref (self->expression);
|
|
|
|
g_slice_free (GtkStringSortKeys, self);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
gtk_string_sort_keys_compare (gconstpointer a,
|
|
|
|
gconstpointer b,
|
|
|
|
gpointer unused)
|
|
|
|
{
|
|
|
|
const char *sa = *(const char **) a;
|
|
|
|
const char *sb = *(const char **) b;
|
|
|
|
|
|
|
|
if (sa == NULL)
|
|
|
|
return sb == NULL ? GTK_ORDERING_EQUAL : GTK_ORDERING_LARGER;
|
|
|
|
else if (sb == NULL)
|
|
|
|
return GTK_ORDERING_SMALLER;
|
|
|
|
|
|
|
|
return gtk_ordering_from_cmpfunc (strcmp (sa, sb));
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_string_sort_keys_is_compatible (GtkSortKeys *keys,
|
|
|
|
GtkSortKeys *other)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_string_sort_keys_init_key (GtkSortKeys *keys,
|
|
|
|
gpointer item,
|
|
|
|
gpointer key_memory)
|
|
|
|
{
|
|
|
|
GtkStringSortKeys *self = (GtkStringSortKeys *) keys;
|
|
|
|
char **key = (char **) key_memory;
|
|
|
|
|
2022-10-11 16:57:09 +00:00
|
|
|
*key = gtk_string_sorter_get_key (self->expression, self->ignore_case, self->collation, item);
|
2020-07-15 18:28:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_string_sort_keys_clear_key (GtkSortKeys *keys,
|
|
|
|
gpointer key_memory)
|
|
|
|
{
|
|
|
|
char **key = (char **) key_memory;
|
|
|
|
|
|
|
|
g_free (*key);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const GtkSortKeysClass GTK_STRING_SORT_KEYS_CLASS =
|
|
|
|
{
|
|
|
|
gtk_string_sort_keys_free,
|
|
|
|
gtk_string_sort_keys_compare,
|
|
|
|
gtk_string_sort_keys_is_compatible,
|
|
|
|
gtk_string_sort_keys_init_key,
|
|
|
|
gtk_string_sort_keys_clear_key,
|
|
|
|
};
|
|
|
|
|
|
|
|
static GtkSortKeys *
|
|
|
|
gtk_string_sort_keys_new (GtkStringSorter *self)
|
|
|
|
{
|
|
|
|
GtkStringSortKeys *result;
|
|
|
|
|
|
|
|
if (self->expression == NULL)
|
|
|
|
return gtk_sort_keys_new_equal ();
|
|
|
|
|
|
|
|
result = gtk_sort_keys_new (GtkStringSortKeys,
|
|
|
|
>K_STRING_SORT_KEYS_CLASS,
|
|
|
|
sizeof (char *),
|
|
|
|
sizeof (char *));
|
|
|
|
|
|
|
|
result->expression = gtk_expression_ref (self->expression);
|
|
|
|
result->ignore_case = self->ignore_case;
|
2022-10-11 16:57:09 +00:00
|
|
|
result->collation = self->collation;
|
2020-07-15 18:28:45 +00:00
|
|
|
|
|
|
|
return (GtkSortKeys *) result;
|
|
|
|
}
|
|
|
|
|
2019-12-03 04:43:14 +00:00
|
|
|
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:
|
2020-06-01 20:07:53 +00:00
|
|
|
gtk_string_sorter_set_expression (self, gtk_value_get_expression (value));
|
2019-12-03 04:43:14 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_IGNORE_CASE:
|
|
|
|
gtk_string_sorter_set_ignore_case (self, g_value_get_boolean (value));
|
|
|
|
break;
|
|
|
|
|
2022-10-11 16:57:09 +00:00
|
|
|
case PROP_COLLATION:
|
|
|
|
gtk_string_sorter_set_collation (self, g_value_get_enum (value));
|
|
|
|
break;
|
|
|
|
|
2019-12-03 04:43:14 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-11 16:57:09 +00:00
|
|
|
static void
|
2019-12-03 04:43:14 +00:00
|
|
|
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:
|
2020-06-01 20:07:53 +00:00
|
|
|
gtk_value_set_expression (value, self->expression);
|
2019-12-03 04:43:14 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_IGNORE_CASE:
|
|
|
|
g_value_set_boolean (value, self->ignore_case);
|
|
|
|
break;
|
|
|
|
|
2022-10-11 16:57:09 +00:00
|
|
|
case PROP_COLLATION:
|
|
|
|
g_value_set_enum (value, self->collation);
|
|
|
|
break;
|
|
|
|
|
2019-12-03 04:43:14 +00:00
|
|
|
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;
|
|
|
|
sorter_class->get_order = gtk_string_sorter_get_order;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
/**
|
2021-02-28 18:12:20 +00:00
|
|
|
* GtkStringSorter:expression: (type GtkExpression) (attributes org.gtk.Property.get=gtk_string_sorter_get_expression org.gtk.Property.set=gtk_string_sorter_set_expression)
|
2019-12-03 04:43:14 +00:00
|
|
|
*
|
2021-02-28 18:12:20 +00:00
|
|
|
* The expression to evaluate on item to get a string to compare with.
|
2019-12-03 04:43:14 +00:00
|
|
|
*/
|
|
|
|
properties[PROP_EXPRESSION] =
|
2022-05-11 12:19:39 +00:00
|
|
|
gtk_param_spec_expression ("expression", NULL, NULL,
|
2020-06-01 20:07:53 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
|
2019-12-03 04:43:14 +00:00
|
|
|
|
|
|
|
/**
|
2021-02-28 18:12:20 +00:00
|
|
|
* GtkStringSorter:ignore-case: (attributes org.gtk.Property.get=gtk_string_sorter_get_ignore_case org.gtk.Property.set=gtk_string_sorter_set_ignore_case)
|
2019-12-03 04:43:14 +00:00
|
|
|
*
|
2022-10-11 16:57:09 +00:00
|
|
|
* If sorting is case sensitive.
|
2019-12-03 04:43:14 +00:00
|
|
|
*/
|
|
|
|
properties[PROP_IGNORE_CASE] =
|
2022-05-11 12:19:39 +00:00
|
|
|
g_param_spec_boolean ("ignore-case", NULL, NULL,
|
2019-12-03 04:43:14 +00:00
|
|
|
TRUE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
|
|
|
|
|
2022-10-11 16:57:09 +00:00
|
|
|
/**
|
|
|
|
* GtkStringSorter:collation: (attributes org.gtk.Property.get=gtk_string_sorter_get_collation org.gtk.Property.set=gtk_string_sorter_set_collation)
|
|
|
|
*
|
|
|
|
* The collation method to use for sorting.
|
|
|
|
*
|
2022-10-11 18:03:57 +00:00
|
|
|
* The `GTK_COLLATION_NONE` value is useful when the expression already
|
|
|
|
* returns collation keys, or strings that need to be compared byte-by-byte.
|
|
|
|
*
|
|
|
|
* The default value, `GTK_COLLATION_UNICODE`, compares strings according
|
|
|
|
* to the [Unicode collation algorithm](https://www.unicode.org/reports/tr10/).
|
|
|
|
*
|
2022-10-11 16:57:09 +00:00
|
|
|
* Since: 4.10
|
|
|
|
*/
|
|
|
|
properties[PROP_COLLATION] =
|
2022-10-11 17:53:26 +00:00
|
|
|
g_param_spec_enum ("collation", NULL, NULL,
|
2022-10-11 16:57:09 +00:00
|
|
|
GTK_TYPE_COLLATION,
|
|
|
|
GTK_COLLATION_UNICODE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
|
|
|
|
|
2019-12-03 04:43:14 +00:00
|
|
|
g_object_class_install_properties (object_class, NUM_PROPERTIES, properties);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_string_sorter_init (GtkStringSorter *self)
|
|
|
|
{
|
|
|
|
self->ignore_case = TRUE;
|
2022-10-11 16:57:09 +00:00
|
|
|
self->collation = GTK_COLLATION_UNICODE;
|
2020-07-15 18:28:45 +00:00
|
|
|
|
|
|
|
gtk_sorter_changed_with_keys (GTK_SORTER (self),
|
|
|
|
GTK_SORTER_CHANGE_DIFFERENT,
|
|
|
|
gtk_string_sort_keys_new (self));
|
2019-12-03 04:43:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_string_sorter_new:
|
|
|
|
* @expression: (transfer full) (nullable): The expression to evaluate
|
|
|
|
*
|
|
|
|
* Creates a new string sorter that compares items using the given
|
|
|
|
* @expression.
|
|
|
|
*
|
|
|
|
* Unless an expression is set on it, this sorter will always
|
|
|
|
* compare items as invalid.
|
|
|
|
*
|
2021-02-28 18:12:20 +00:00
|
|
|
* Returns: a new `GtkStringSorter`
|
2019-12-03 04:43:14 +00:00
|
|
|
*/
|
2020-08-03 19:54:42 +00:00
|
|
|
GtkStringSorter *
|
2019-12-03 04:43:14 +00:00
|
|
|
gtk_string_sorter_new (GtkExpression *expression)
|
|
|
|
{
|
2020-08-03 19:54:42 +00:00
|
|
|
GtkStringSorter *result;
|
2019-12-03 04:43:14 +00:00
|
|
|
|
|
|
|
result = g_object_new (GTK_TYPE_STRING_SORTER,
|
|
|
|
"expression", expression,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
g_clear_pointer (&expression, gtk_expression_unref);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-02-28 18:12:20 +00:00
|
|
|
* gtk_string_sorter_get_expression: (attributes org.gtk.Method.get_property=expression)
|
|
|
|
* @self: a `GtkStringSorter`
|
2019-12-03 04:43:14 +00:00
|
|
|
*
|
|
|
|
* Gets the expression that is evaluated to obtain strings from items.
|
|
|
|
*
|
2021-05-21 00:45:06 +00:00
|
|
|
* Returns: (transfer none) (nullable): a `GtkExpression`
|
2019-12-03 04:43:14 +00:00
|
|
|
*/
|
|
|
|
GtkExpression *
|
|
|
|
gtk_string_sorter_get_expression (GtkStringSorter *self)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_STRING_SORTER (self), NULL);
|
|
|
|
|
|
|
|
return self->expression;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-02-28 18:12:20 +00:00
|
|
|
* gtk_string_sorter_set_expression: (attributes org.gtk.Method.set_property=expression)
|
|
|
|
* @self: a `GtkStringSorter`
|
2021-05-21 00:45:06 +00:00
|
|
|
* @expression: (nullable) (transfer none): a `GtkExpression`
|
2019-12-03 04:43:14 +00:00
|
|
|
*
|
|
|
|
* Sets the expression that is evaluated to obtain strings from items.
|
|
|
|
*
|
2021-02-28 18:12:20 +00:00
|
|
|
* The expression must have the type %G_TYPE_STRING.
|
2019-12-03 04:43:14 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_string_sorter_set_expression (GtkStringSorter *self,
|
|
|
|
GtkExpression *expression)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_STRING_SORTER (self));
|
|
|
|
g_return_if_fail (expression == NULL || gtk_expression_get_value_type (expression) == G_TYPE_STRING);
|
|
|
|
|
|
|
|
if (self->expression == expression)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_clear_pointer (&self->expression, gtk_expression_unref);
|
|
|
|
if (expression)
|
|
|
|
self->expression = gtk_expression_ref (expression);
|
|
|
|
|
2020-07-15 18:28:45 +00:00
|
|
|
gtk_sorter_changed_with_keys (GTK_SORTER (self),
|
|
|
|
GTK_SORTER_CHANGE_DIFFERENT,
|
|
|
|
gtk_string_sort_keys_new (self));
|
2019-12-03 04:43:14 +00:00
|
|
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_EXPRESSION]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-02-28 18:12:20 +00:00
|
|
|
* gtk_string_sorter_get_ignore_case: (attributes org.gtk.Method.get_property=ignore-case)
|
|
|
|
* @self: a `GtkStringSorter`
|
2019-12-03 04:43:14 +00:00
|
|
|
*
|
|
|
|
* Gets whether the sorter ignores case differences.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if @self is ignoring case differences
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gtk_string_sorter_get_ignore_case (GtkStringSorter *self)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_STRING_SORTER (self), TRUE);
|
|
|
|
|
|
|
|
return self->ignore_case;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-02-28 18:12:20 +00:00
|
|
|
* gtk_string_sorter_set_ignore_case: (attributes org.gtk.Method.set_property=ignore-case)
|
|
|
|
* @self: a `GtkStringSorter`
|
2020-06-06 01:36:27 +00:00
|
|
|
* @ignore_case: %TRUE to ignore case differences
|
2019-12-03 04:43:14 +00:00
|
|
|
*
|
|
|
|
* Sets whether the sorter will ignore case differences.
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
|
2020-07-15 18:28:45 +00:00
|
|
|
gtk_sorter_changed_with_keys (GTK_SORTER (self),
|
|
|
|
ignore_case ? GTK_SORTER_CHANGE_LESS_STRICT : GTK_SORTER_CHANGE_MORE_STRICT,
|
|
|
|
gtk_string_sort_keys_new (self));
|
2019-12-03 04:43:14 +00:00
|
|
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_IGNORE_CASE]);
|
|
|
|
}
|
2022-10-11 16:57:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_string_sorter_get_collation: (attributes org.gtk.Method.get_property=collation)
|
|
|
|
* @self: a `GtkStringSorter`
|
|
|
|
*
|
|
|
|
* Gets which collation method the sorter uses.
|
|
|
|
*
|
|
|
|
* Returns: The collation method
|
|
|
|
*
|
|
|
|
* Since: 4.10
|
|
|
|
*/
|
|
|
|
GtkCollation
|
|
|
|
gtk_string_sorter_get_collation (GtkStringSorter *self)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_STRING_SORTER (self), GTK_COLLATION_UNICODE);
|
|
|
|
|
|
|
|
return self->collation;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_string_sorter_set_collation: (attributes org.gtk.Method.set_property=collation)
|
|
|
|
* @self: a `GtkStringSorter`
|
|
|
|
* @collation: the collation method
|
|
|
|
*
|
|
|
|
* Sets the collation method to use for sorting.
|
|
|
|
*
|
|
|
|
* Since: 4.10
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_string_sorter_set_collation (GtkStringSorter *self,
|
|
|
|
GtkCollation collation)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_STRING_SORTER (self));
|
|
|
|
|
|
|
|
if (self->collation == collation)
|
|
|
|
return;
|
|
|
|
|
|
|
|
self->collation = collation;
|
|
|
|
|
|
|
|
gtk_sorter_changed_with_keys (GTK_SORTER (self),
|
|
|
|
GTK_SORTER_CHANGE_DIFFERENT,
|
|
|
|
gtk_string_sort_keys_new (self));
|
|
|
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_COLLATION]);
|
|
|
|
}
|