column view: Add a sort-by api

This commit is contained in:
Matthias Clasen
2019-12-03 21:31:57 -05:00
parent 27f19ca2a7
commit 4bfc653311
5 changed files with 75 additions and 0 deletions

View File

@@ -565,6 +565,7 @@ gtk_column_view_set_model
gtk_column_view_get_sorter
gtk_column_view_get_show_separators
gtk_column_view_set_show_separators
gtk_column_view_sort_by_column
<SUBSECTION Standard>
GTK_COLUMN_VIEW
GTK_COLUMN_VIEW_CLASS

View File

@@ -744,3 +744,38 @@ gtk_column_view_active_sorter_changed (GtkColumnView *self)
g_object_unref (column);
}
}
/**
* gtk_column_view_sort_by_column:
* @self: a #GtkColumnView
* @column: (allow-none): the #GtkColumnViewColumn to sort by, or %NULL
* @direction: the direction to sort in
*
* Sets the sorting of the view.
*
* This function should be used to set up the initial sorting. At runtime,
* users can change the sorting of a column view by clicking on the list headers.
*
* This call only has an effect if gtk_column_view_set_sort_model() has
* been called to inform the view about the underlying sort model, and
* if gtk_column_view_set_sorter() has been called on @column to associate
* a sorter with the column.
*
* If @column is %NULL, the view will be unsorted.
*/
void
gtk_column_view_sort_by_column (GtkColumnView *self,
GtkColumnViewColumn *column,
GtkSortType direction)
{
g_return_if_fail (GTK_IS_COLUMN_VIEW (self));
g_return_if_fail (column == NULL || GTK_IS_COLUMN_VIEW_COLUMN (column));
g_return_if_fail (column == NULL || gtk_column_view_column_get_column_view (column) == self);
if (column == NULL)
gtk_column_view_sorter_reset (GTK_COLUMN_VIEW_SORTER (self->sorter));
else
gtk_column_view_sorter_set_column (GTK_COLUMN_VIEW_SORTER (self->sorter),
column,
direction == GTK_SORT_DESCENDING);
}

View File

@@ -77,6 +77,11 @@ void gtk_column_view_set_show_separators (GtkColumnView
GDK_AVAILABLE_IN_ALL
GtkSorter * gtk_column_view_get_sorter (GtkColumnView *self);
GDK_AVAILABLE_IN_ALL
void gtk_column_view_sort_by_column (GtkColumnView *self,
GtkColumnViewColumn *column,
GtkSortType direction);
G_END_DECLS
#endif /* __GTK_COLUMN_VIEW_H__ */

View File

@@ -195,6 +195,36 @@ gtk_column_view_sorter_remove_column (GtkColumnViewSorter *self,
return FALSE;
}
gboolean
gtk_column_view_sorter_set_column (GtkColumnViewSorter *self,
GtkColumnViewColumn *column,
gboolean inverted)
{
GtkSorter *sorter;
Sorter *s;
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;
g_list_free_full (self->sorters, free_sorter);
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 (changed_cb), self);
s->inverted = inverted;
self->sorters = g_list_prepend (self->sorters, s);
gtk_sorter_changed (GTK_SORTER (self), GTK_SORTER_CHANGE_DIFFERENT);
return TRUE;
}
void
gtk_column_view_sorter_reset (GtkColumnViewSorter *self)
{

View File

@@ -47,6 +47,10 @@ GtkColumnViewColumn *
gtk_column_view_sorter_get_active (GtkColumnViewSorter *self,
gboolean *inverted);
gboolean gtk_column_view_sorter_set_column (GtkColumnViewSorter *self,
GtkColumnViewColumn *column,
gboolean inverted);
G_END_DECLS