From 8cda6025f0a11278c8d2f01482ad1656a2b5e5b1 Mon Sep 17 00:00:00 2001 From: Lucas Rocha Date: Mon, 21 Apr 2008 20:47:38 +0000 Subject: Add support for file filter in file selection dialog through the new 2008-04-21 Lucas Rocha Add support for file filter in file selection dialog through the new --file-filter command line option (Fixes bug #409843). * src/option.c, src/zenity.h: added supporting variable and new GOptionEntry entry for the new command line option. * src/fileselection.c (zenity_fileselection): add file filters based on command line input. svn path=/trunk/; revision=1362 --- src/fileselection.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'src/fileselection.c') diff --git a/src/fileselection.c b/src/fileselection.c index c91c816a..46d1941d 100644 --- a/src/fileselection.c +++ b/src/fileselection.c @@ -85,6 +85,52 @@ void zenity_fileselection (ZenityData *data, ZenityFileData *file_data) if (file_data->multi) gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (dialog), TRUE); + if (file_data->filter) { + /* Filter format: Executables | *.exe *.bat *.com */ + gint filter_i; + + for (filter_i = 0; file_data->filter [filter_i]; filter_i++) { + GtkFileFilter *filter = gtk_file_filter_new(); + gchar *filter_str = file_data->filter [filter_i]; + gchar **pattern, **patterns; + gchar *name = NULL; + gint i; + + /* Set name */ + for (i = 0; filter_str[i] != '\0'; i++) + if (filter_str[i] == '|') + break; + + if (filter_str[i] == '|') { + name = g_strndup (filter_str, i); + g_strstrip (name); + } + + if (name) { + gtk_file_filter_set_name (filter, name); + + /* Point i to the right position for split */ + for (++i; filter_str[i] == ' '; i++); + } else { + gtk_file_filter_set_name (filter, filter_str); + i = 0; + } + + /* Get patterns */ + patterns = g_strsplit_set (filter_str + i, " ", -1); + + for (pattern = patterns; *pattern; pattern++) + gtk_file_filter_add_pattern (filter, *pattern); + + if (name) + g_free (name); + + g_strfreev (patterns); + + gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter); + } + } + zenity_util_show_dialog (dialog); if(data->timeout_delay > 0) { -- cgit