aboutsummaryrefslogtreecommitdiff
path: root/fastiv-sidebar.c
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2021-11-21 00:21:52 +0100
committerPřemysl Eric Janouch <p@janouch.name>2021-11-21 00:22:29 +0100
commit6dd0414d0a16bc4674985613cef4a8f7ff315825 (patch)
tree3e3e6002c4ce95cc214e49b071b59ce4a2d6dd21 /fastiv-sidebar.c
parent8376ae9c4a6587cb664c353c1649fad666e1fbf2 (diff)
downloadfiv-6dd0414d0a16bc4674985613cef4a8f7ff315825.tar.gz
fiv-6dd0414d0a16bc4674985613cef4a8f7ff315825.tar.xz
fiv-6dd0414d0a16bc4674985613cef4a8f7ff315825.zip
Sort files and directories by name
Diffstat (limited to 'fastiv-sidebar.c')
-rw-r--r--fastiv-sidebar.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/fastiv-sidebar.c b/fastiv-sidebar.c
index 5d78667..279139f 100644
--- a/fastiv-sidebar.c
+++ b/fastiv-sidebar.c
@@ -105,6 +105,27 @@ create_row(GFile *file, const char *icon_name)
return row;
}
+static gint
+listbox_sort(
+ GtkListBoxRow *row1, GtkListBoxRow *row2, G_GNUC_UNUSED gpointer user_data)
+{
+ GFile *location1 =
+ g_object_get_qdata(G_OBJECT(row1), fastiv_sidebar_location_quark());
+ GFile *location2 =
+ g_object_get_qdata(G_OBJECT(row2), fastiv_sidebar_location_quark());
+ if (g_file_has_prefix(location1, location2))
+ return +1;
+ if (g_file_has_prefix(location2, location1))
+ return -1;
+
+ gchar *name1 = g_file_get_parse_name(location1);
+ gchar *name2 = g_file_get_parse_name(location2);
+ gint result = g_utf8_collate(name1, name2);
+ g_free(name1);
+ g_free(name2);
+ return result;
+}
+
static void
update_location(FastivSidebar *self, GFile *location)
{
@@ -143,8 +164,8 @@ update_location(FastivSidebar *self, GFile *location)
if (!enumerator)
return;
- // TODO(p): gtk_list_box_set_sort_func(), gtk_list_box_set_filter_func(),
- // or even use a model.
+ // TODO(p): gtk_list_box_set_filter_func(), or even use a model,
+ // which could be shared with FastivBrowser.
while (TRUE) {
GFileInfo *info = NULL;
GFile *child = NULL;
@@ -377,6 +398,9 @@ fastiv_sidebar_init(FastivSidebar *self)
g_signal_connect(self->listbox, "row-activated",
G_CALLBACK(on_open_breadcrumb), self);
+ gtk_list_box_set_sort_func(
+ GTK_LIST_BOX(self->listbox), listbox_sort, self, NULL);
+
GtkWidget *superbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
gtk_container_add(
GTK_CONTAINER(superbox), GTK_WIDGET(self->places));