[gtk/wip/otte/listview-colors: 13/15] sortlistmodel: Look at order
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/listview-colors: 13/15] sortlistmodel: Look at order
- Date: Sun, 21 Jun 2020 12:19:18 +0000 (UTC)
commit a928ea6c577070cc18ae6701b485f0d26840dc5b
Author: Benjamin Otte <otte redhat com>
Date: Sun Jun 21 06:53:44 2020 +0200
sortlistmodel: Look at order
For now, we just look at SORT_ORDER_NONE to bypass any sorting.
gtk/gtksortlistmodel.c | 54 +++++++++++++++++++++++++++++++++-----------------
1 file changed, 36 insertions(+), 18 deletions(-)
---
diff --git a/gtk/gtksortlistmodel.c b/gtk/gtksortlistmodel.c
index 5444ee74ae..0406d1e86f 100644
--- a/gtk/gtksortlistmodel.c
+++ b/gtk/gtksortlistmodel.c
@@ -308,6 +308,30 @@ gtk_sort_list_model_get_property (GObject *object,
}
}
+static void
+gtk_sort_list_model_clear_sequences (GtkSortListModel *self)
+{
+ g_clear_pointer (&self->unsorted, g_sequence_free);
+ g_clear_pointer (&self->sorted, g_sequence_free);
+}
+
+static void
+gtk_sort_list_model_create_sequences (GtkSortListModel *self)
+{
+ if (self->sorted)
+ return;
+
+ if (self->sorter == NULL ||
+ self->model == NULL ||
+ gtk_sorter_get_order (self->sorter) == GTK_SORTER_ORDER_NONE)
+ return;
+
+ self->sorted = g_sequence_new (gtk_sort_list_entry_free);
+ self->unsorted = g_sequence_new (NULL);
+
+ gtk_sort_list_model_add_items (self, 0, g_list_model_get_n_items (self->model), NULL, NULL);
+}
+
static void gtk_sort_list_model_resort (GtkSortListModel *self);
static void
@@ -315,7 +339,16 @@ gtk_sort_list_model_sorter_changed_cb (GtkSorter *sorter,
int change,
GtkSortListModel *self)
{
- gtk_sort_list_model_resort (self);
+ if (gtk_sorter_get_order (sorter) == GTK_SORTER_ORDER_NONE)
+ gtk_sort_list_model_clear_sequences (self);
+ else if (self->sorted == NULL)
+ {
+ guint n_items = g_list_model_get_n_items (self->model);
+ gtk_sort_list_model_create_sequences (self);
+ g_list_model_items_changed (G_LIST_MODEL (self), 0, n_items, n_items);
+ }
+ else
+ gtk_sort_list_model_resort (self);
}
static void
@@ -326,8 +359,7 @@ gtk_sort_list_model_clear_model (GtkSortListModel *self)
g_signal_handlers_disconnect_by_func (self->model, gtk_sort_list_model_items_changed_cb, self);
g_clear_object (&self->model);
- g_clear_pointer (&self->sorted, g_sequence_free);
- g_clear_pointer (&self->unsorted, g_sequence_free);
+ gtk_sort_list_model_clear_sequences (self);
}
static void
@@ -338,6 +370,7 @@ gtk_sort_list_model_clear_sorter (GtkSortListModel *self)
g_signal_handlers_disconnect_by_func (self->sorter, gtk_sort_list_model_sorter_changed_cb, self);
g_clear_object (&self->sorter);
+ gtk_sort_list_model_clear_sequences (self);
}
static void
@@ -451,18 +484,6 @@ gtk_sort_list_model_new_for_type (GType item_type)
NULL);
}
-static void
-gtk_sort_list_model_create_sequences (GtkSortListModel *self)
-{
- if (self->sorter == NULL || self->model == NULL)
- return;
-
- self->sorted = g_sequence_new (gtk_sort_list_entry_free);
- self->unsorted = g_sequence_new (NULL);
-
- gtk_sort_list_model_add_items (self, 0, g_list_model_get_n_items (self->model), NULL, NULL);
-}
-
/**
* gtk_sort_list_model_set_model:
* @self: a #GtkSortListModel
@@ -566,9 +587,6 @@ gtk_sort_list_model_set_sorter (GtkSortListModel *self,
g_signal_connect (sorter, "changed", G_CALLBACK (gtk_sort_list_model_sorter_changed_cb), self);
}
- g_clear_pointer (&self->unsorted, g_sequence_free);
- g_clear_pointer (&self->sorted, g_sequence_free);
-
gtk_sort_list_model_create_sequences (self);
n_items = g_list_model_get_n_items (G_LIST_MODEL (self));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]