Sort files and directories by name
This commit is contained in:
parent
8376ae9c4a
commit
6dd0414d0a
@ -649,21 +649,30 @@ fastiv_browser_load(FastivBrowser *self, const char *path)
|
|||||||
g_array_set_size(self->entries, 0);
|
g_array_set_size(self->entries, 0);
|
||||||
g_array_set_size(self->layouted_rows, 0);
|
g_array_set_size(self->layouted_rows, 0);
|
||||||
|
|
||||||
// TODO(p): Use opendir(), in order to get file type directly.
|
GFile *file = g_file_new_for_path(path);
|
||||||
GDir *dir = g_dir_open(path, 0, NULL);
|
GFileEnumerator *enumerator = g_file_enumerate_children(file,
|
||||||
if (!dir)
|
G_FILE_ATTRIBUTE_STANDARD_NAME "," G_FILE_ATTRIBUTE_STANDARD_TYPE,
|
||||||
|
G_FILE_QUERY_INFO_NONE, NULL, NULL);
|
||||||
|
g_object_unref(file);
|
||||||
|
if (!enumerator)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const char *filename;
|
while (TRUE) {
|
||||||
while ((filename = g_dir_read_name(dir))) {
|
GFileInfo *info = NULL;
|
||||||
if (!strcmp(filename, ".") || !strcmp(filename, ".."))
|
GFile *child = NULL;
|
||||||
|
if (!g_file_enumerator_iterate(enumerator, &info, &child, NULL, NULL) ||
|
||||||
|
!info)
|
||||||
|
break;
|
||||||
|
if (g_file_info_get_file_type(info) == G_FILE_TYPE_DIRECTORY)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
gchar *subpath = g_build_filename(path, filename, NULL);
|
// TODO(p): Support being passed filter/sort functions.
|
||||||
g_array_append_val(
|
g_file_info_get_name(info);
|
||||||
self->entries, ((Entry) {.thumbnail = NULL, .filename = subpath}));
|
|
||||||
|
g_array_append_val(self->entries,
|
||||||
|
((Entry) {.thumbnail = NULL, .filename = g_file_get_path(child)}));
|
||||||
}
|
}
|
||||||
g_dir_close(dir);
|
g_object_unref(enumerator);
|
||||||
|
|
||||||
GThreadPool *pool = g_thread_pool_new(
|
GThreadPool *pool = g_thread_pool_new(
|
||||||
entry_add_thumbnail, NULL, g_get_num_processors(), FALSE, NULL);
|
entry_add_thumbnail, NULL, g_get_num_processors(), FALSE, NULL);
|
||||||
|
@ -105,6 +105,27 @@ create_row(GFile *file, const char *icon_name)
|
|||||||
return row;
|
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
|
static void
|
||||||
update_location(FastivSidebar *self, GFile *location)
|
update_location(FastivSidebar *self, GFile *location)
|
||||||
{
|
{
|
||||||
@ -143,8 +164,8 @@ update_location(FastivSidebar *self, GFile *location)
|
|||||||
if (!enumerator)
|
if (!enumerator)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// TODO(p): gtk_list_box_set_sort_func(), gtk_list_box_set_filter_func(),
|
// TODO(p): gtk_list_box_set_filter_func(), or even use a model,
|
||||||
// or even use a model.
|
// which could be shared with FastivBrowser.
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
GFileInfo *info = NULL;
|
GFileInfo *info = NULL;
|
||||||
GFile *child = NULL;
|
GFile *child = NULL;
|
||||||
@ -377,6 +398,9 @@ fastiv_sidebar_init(FastivSidebar *self)
|
|||||||
g_signal_connect(self->listbox, "row-activated",
|
g_signal_connect(self->listbox, "row-activated",
|
||||||
G_CALLBACK(on_open_breadcrumb), self);
|
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);
|
GtkWidget *superbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
|
||||||
gtk_container_add(
|
gtk_container_add(
|
||||||
GTK_CONTAINER(superbox), GTK_WIDGET(self->places));
|
GTK_CONTAINER(superbox), GTK_WIDGET(self->places));
|
||||||
|
Loading…
Reference in New Issue
Block a user