In this ui file, GtkSingleSelection is used as GtkSelectionModel.
GtkSingleSelection is an object that implements GtkSelectionModel.
And again, it has "model" property.
It points GtkSortListModel.
This list model supports sorting the list.
It will be explained in the later subsection.
And it also has "model" property.
It points GtkDirectoryList.
Therefore, the chain is: GtkColumnView => GtkSingleSelection => GtkSortListModel => GtkDirectoryList.
- 18-20: GtkDirectoryList.
It is a list of GFileInfo, which holds information of files under a directory.
It has "attributes" property.
It specifies what attributes is kept in each GFileInfo.
"standard::name" is a name of the file.
"standard::size" is the file size.
"time::modified" is the date and time the file was last modified.
- 29-79: The first GtkColumnViewColumn object.
There are four properties, "title", "expand", factory" and "sorter".
- 31: Sets the "title" property with "Name".
This is the title on the header of the column.
- 32: Sets the "expand" property to TRUE to allow the column to expand as much as possible.
(See the image above).
- 33- 69: Sets the "factory" property with GtkBuilderListItemFactory.
The factory has "bytes" property which holds a ui string to define a template to build GtkListItem composite widget.
The CDATA section (line 36-66) is the ui string to put into the "bytes" property.
The contents are the same as the section 24 and 25.
- 70-77: Sets the "sorter" property with GtkStringSorter object.
This object provides a sorter that compares strings.
It has "expression" property which is set with GtkExpression.
A closure tag with a string type function `get_file_name` is used here.
The function is explained later.
- 80-115: The second GtkColumnViewColumn object.
Its "title", "factory" and "sorter" properties are set.
GtkNumericSorter is used.
- 116-151: The third GtkColumnViewColumn object.
Its "title", "factory" and "sorter" properties are set.
GtkNumericSorter is used.
## GtkSortListModel and GtkSorter
GtkSortListModel is a list model that sorts its elements according to a GtkSorter.
It has "sorter" property that is set with GtkSorter.
The property is bound to "sorter" property of GtkColumnView in line 22 to 24.
~~~xml
<objectclass="GtkSortListModel"id="sortlist">
... ... ...
<bindingname="sorter">
<lookupname="sorter">columnview</lookup>
</binding>
~~~
Therefore, `columnview` determines the way how to sort the list model.
The "sorter" property of GtkColumnView is read-only property and it is a special sorter.
It reflects the user's sorting choice.
If a user clicks the header of a column, then the sorter ("sorter" property) of the column is referred to by "sorter" property of the GtkColumnView object.
If the user clicks the header of another column, then the "sorter" property of the GtkColumnView object reflects the newly clicked column's "sorter" property.
The binding above makes a indirect connection between the "sorter" property of GtkSortListModel and the "sorter" property of each column.
GtkSorter has several child objects.
- GtkStringSorter compares strings.
- GtkNumericSorter compares numbers.
- GtkCustomSorter uses a callback to compare.
- GtkMultiSorter combines multiple sorters.
The example uses GtkStringSorter and GtkNumericSorter.
GtkStringSorter uses GtkExpression to get the strings from the objects.
The GtkExpression is stored in the "expression" property of GtkStringSorter.
For example, in the ui file above, the GtkExpression is in the line 73 to 74.