Compare commits

...

2 Commits

Author SHA1 Message Date
6c748439ed
Use natural sort order
This is exposed in GLib through collate key construction.
2022-02-20 12:07:41 +01:00
fbf26a7d66
Show application icons in context menu items 2022-02-20 12:07:40 +01:00
2 changed files with 29 additions and 14 deletions

View File

@ -683,11 +683,29 @@ append_opener(GtkWidget *menu, GAppInfo *opener, const OpenContext *template)
ctx->content_type = g_strdup(template->content_type);
ctx->app_info = opener;
// It's documented that we can touch the child, if we want formatting:
// https://docs.gtk.org/gtk3/class.MenuItem.html
// XXX: Would g_app_info_get_display_name() be any better?
gchar *name = g_strdup_printf("Open With %s", g_app_info_get_name(opener));
// It's documented that we can touch the child, if we want to use markup.
#if 0
GtkWidget *item = gtk_menu_item_new_with_label(name);
#else
// GtkImageMenuItem overrides the toggle_size_request class method
// to get the image shown in the "margin"--too much work to duplicate.
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
GtkWidget *item = gtk_image_menu_item_new_with_label(name);
GIcon *icon = g_app_info_get_icon(opener);
if (icon) {
GtkWidget *image = gtk_image_new_from_gicon(icon, GTK_ICON_SIZE_MENU);
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image);
gtk_image_menu_item_set_always_show_image(
GTK_IMAGE_MENU_ITEM(item), TRUE);
}
G_GNUC_END_IGNORE_DEPRECATIONS;
#endif
g_free(name);
g_signal_connect_data(item, "activate", G_CALLBACK(open_context_launch),
ctx, open_context_notify, 0);

View File

@ -2711,6 +2711,7 @@ fiv_io_open_from_data(
typedef struct _ModelEntry {
gchar *uri; ///< GIO URI
gchar *collate_key; ///< Collate key for the filename
gint64 mtime_msec; ///< Modification time in milliseconds
} ModelEntry;
@ -2718,6 +2719,7 @@ static void
model_entry_finalize(ModelEntry *entry)
{
g_free(entry->uri);
g_free(entry->collate_key);
}
struct _FivIoModel {
@ -2778,17 +2780,6 @@ model_supports(FivIoModel *self, const gchar *filename)
return FALSE;
}
static inline int
model_compare_name(GFile *location1, GFile *location2)
{
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;
}
static inline int
model_compare_entries(FivIoModel *self, const ModelEntry *entry1, GFile *file1,
const ModelEntry *entry2, GFile *file2)
@ -2809,7 +2800,7 @@ model_compare_entries(FivIoModel *self, const ModelEntry *entry1, GFile *file1,
// Fall-through
case FIV_IO_MODEL_SORT_NAME:
case FIV_IO_MODEL_SORT_COUNT:
result = model_compare_name(file1, file2);
result = strcmp(entry1->collate_key, entry2->collate_key);
}
return self->sort_descending ? -result : +result;
}
@ -2870,6 +2861,12 @@ model_reload(FivIoModel *self, GError **error)
g_date_time_unref(mtime);
}
gchar *parse_name = g_file_get_parse_name(child);
// TODO(p): Make it possible to use g_utf8_collate_key() instead,
// which does not use natural sorting.
entry.collate_key = g_utf8_collate_key_for_filename(parse_name, -1);
g_free(parse_name);
const char *name = g_file_info_get_name(info);
if (g_file_info_get_file_type(info) == G_FILE_TYPE_DIRECTORY) {
entry.uri = g_file_get_uri(child);