Sort files in the browser as well
This commit is contained in:
parent
5fea2245f1
commit
1c57eef05a
@ -768,6 +768,19 @@ fastiv_browser_init(FastivBrowser *self)
|
||||
|
||||
// --- Public interface --------------------------------------------------------
|
||||
|
||||
static gint
|
||||
entry_compare(gconstpointer a, gconstpointer b)
|
||||
{
|
||||
const Entry *entry1 = a;
|
||||
const Entry *entry2 = b;
|
||||
GFile *location1 = g_file_new_for_path(entry1->filename);
|
||||
GFile *location2 = g_file_new_for_path(entry2->filename);
|
||||
gint result = fastiv_io_filecmp(location1, location2);
|
||||
g_object_unref(location1);
|
||||
g_object_unref(location2);
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
fastiv_browser_load(
|
||||
FastivBrowser *self, FastivBrowserFilterCallback cb, const char *path)
|
||||
@ -791,8 +804,6 @@ fastiv_browser_load(
|
||||
break;
|
||||
if (g_file_info_get_file_type(info) == G_FILE_TYPE_DIRECTORY)
|
||||
continue;
|
||||
|
||||
// TODO(p): Support being passed a sort function.
|
||||
if (cb && !cb(g_file_info_get_name(info)))
|
||||
continue;
|
||||
|
||||
@ -801,6 +812,8 @@ fastiv_browser_load(
|
||||
}
|
||||
g_object_unref(enumerator);
|
||||
|
||||
// TODO(p): Sort the entries before.
|
||||
// TODO(p): Support being passed a sort function.
|
||||
g_array_sort(self->entries, entry_compare);
|
||||
|
||||
reload_thumbnails(self);
|
||||
}
|
||||
|
16
fastiv-io.c
16
fastiv-io.c
@ -1048,3 +1048,19 @@ fastiv_io_lookup_thumbnail(const gchar *target, FastivIoThumbnailSize size)
|
||||
g_free(uri);
|
||||
return result;
|
||||
}
|
||||
|
||||
int
|
||||
fastiv_io_filecmp(GFile *location1, GFile *location2)
|
||||
{
|
||||
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);
|
||||
int result = g_utf8_collate(name1, name2);
|
||||
g_free(name1);
|
||||
g_free(name2);
|
||||
return result;
|
||||
}
|
||||
|
@ -57,3 +57,5 @@ cairo_surface_t *fastiv_io_open_from_data(
|
||||
const char *data, size_t len, const gchar *path, GError **error);
|
||||
cairo_surface_t *fastiv_io_lookup_thumbnail(
|
||||
const gchar *target, FastivIoThumbnailSize size);
|
||||
|
||||
int fastiv_io_filecmp(GFile *f1, GFile *f2);
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "fastiv-io.h" // fastiv_io_filecmp
|
||||
#include "fastiv-sidebar.h"
|
||||
|
||||
struct _FastivSidebar {
|
||||
@ -107,24 +108,12 @@ create_row(GFile *file, const char *icon_name)
|
||||
}
|
||||
|
||||
static gint
|
||||
listbox_sort(
|
||||
listbox_compare(
|
||||
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;
|
||||
return fastiv_io_filecmp(
|
||||
g_object_get_qdata(G_OBJECT(row1), fastiv_sidebar_location_quark()),
|
||||
g_object_get_qdata(G_OBJECT(row2), fastiv_sidebar_location_quark()));
|
||||
}
|
||||
|
||||
static void
|
||||
@ -371,7 +360,7 @@ 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);
|
||||
GTK_LIST_BOX(self->listbox), listbox_compare, self, NULL);
|
||||
|
||||
// Fill up what would otherwise be wasted space,
|
||||
// as it is in the examples of Nautilus and Thunar.
|
||||
|
Loading…
Reference in New Issue
Block a user