aboutsummaryrefslogtreecommitdiff
path: root/fastiv.c
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2021-10-23 23:56:59 +0200
committerPřemysl Eric Janouch <p@janouch.name>2021-10-23 23:57:43 +0200
commitbefa7df4810f8af21308b9d00cdebf00e63cdaa3 (patch)
tree769ca11d08844d1d086821a8b73e18f1b1edce33 /fastiv.c
parentde9e91e9a509d4e14f845f255c7f8331d35b45b1 (diff)
downloadfiv-befa7df4810f8af21308b9d00cdebf00e63cdaa3.tar.gz
fiv-befa7df4810f8af21308b9d00cdebf00e63cdaa3.tar.xz
fiv-befa7df4810f8af21308b9d00cdebf00e63cdaa3.zip
Add file type filters to the file open dialog
FWIW, since I've had to do this in another project already.
Diffstat (limited to 'fastiv.c')
-rw-r--r--fastiv.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/fastiv.c b/fastiv.c
index 0d05852..3f622c3 100644
--- a/fastiv.c
+++ b/fastiv.c
@@ -356,13 +356,23 @@ open(const gchar *path)
static void
on_open(void)
{
- // TODO(p): Populate and pass a GtkFileFilter.
- // If we want to keep this functionality, that is.
GtkWidget *dialog = gtk_file_chooser_dialog_new("Open file",
GTK_WINDOW(g.window), GTK_FILE_CHOOSER_ACTION_OPEN,
"_Cancel", GTK_RESPONSE_CANCEL,
"_Open", GTK_RESPONSE_ACCEPT, NULL);
+ // NOTE: gdk-pixbuf has gtk_file_filter_add_pixbuf_formats().
+ GtkFileFilter *filter = gtk_file_filter_new();
+ for (gsize i = 0; i < G_N_ELEMENTS(supported_media_types); i++)
+ gtk_file_filter_add_mime_type(filter, supported_media_types[i]);
+ gtk_file_filter_set_name(filter, "Supported images");
+ gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
+
+ GtkFileFilter *all_files = gtk_file_filter_new();
+ gtk_file_filter_set_name(all_files, "All files");
+ gtk_file_filter_add_pattern(all_files, "*");
+ gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), all_files);
+
// The default is local-only, single item. Paths are returned absolute.
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
gchar *path = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));