GNOME Bugzilla – Bug 792459
gtk_tree_model_sort_set_sort_column_id() ignores change to sort order
Last modified: 2018-01-17 09:58:25 UTC
Created attachment 366722 [details] [review] Suggested fix The following code snippet fails to change the sort order from the default GTK_SORT_ASCENDING to GTK_SORT_DESCENDING. === Begin === GtkTreeModel *sorted = gtk_tree_model_sort_new_with_model(my_model); gtk_tree_sortable_set_default_sort_func( GTK_TREE_SORTABLE(GTK_TREE_MODEL_SORT(sorted)), my_sort_func, NULL, NULL); gtk_tree_sortable_set_sort_column_id( GTK_TREE_SORTABLE(GTK_TREE_MODEL_SORT(sorted)), GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, GTK_SORT_DESCENDING); === End === This is due to a bug in gtk_tree_model_sort_set_sort_column_id(). The function returns without updating sort order when: 1) there is no change to column ID, and 2) column ID is GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID. A work-around is to call gtk_tree_sortable_set_sort_column_id() twice. First time to set sort order by using a dummy column ID (e.g. the value zero), and then a second time with the values you want applied. Patch with suggested fix is attached. Reviewing the master branch showed the bug is present there too.
Well, it turns out the work-around only works so far as to get the sort order set. However, the GtkTreeModelSort object does not use the sort order, when there is a user supplied sort function as in the example in previous comment. So maybe it is per design? If so, it is different behavior than how GtkListStore behaves. The GtkListStore does not suffer from either issue.
Pushed a slightly different fix and a testcase. Thanks