diff options
author | Lucas Rocha <lucasr@gnome.org> | 2008-04-21 20:47:38 +0000 |
---|---|---|
committer | Lucas Almeida Rocha <lucasr@src.gnome.org> | 2008-04-21 20:47:38 +0000 |
commit | 8cda6025f0a11278c8d2f01482ad1656a2b5e5b1 (patch) | |
tree | a01e78077752c80eb0e6a640d13087934bb9806d /src/fileselection.c | |
parent | Updated Norwegian bokmål translation. (diff) | |
download | zenity-8cda6025f0a11278c8d2f01482ad1656a2b5e5b1.tar.gz zenity-8cda6025f0a11278c8d2f01482ad1656a2b5e5b1.tar.bz2 zenity-8cda6025f0a11278c8d2f01482ad1656a2b5e5b1.zip |
Add support for file filter in file selection dialog through the new
2008-04-21 Lucas Rocha <lucasr@gnome.org>
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
Diffstat (limited to 'src/fileselection.c')
-rw-r--r-- | src/fileselection.c | 46 |
1 files changed, 46 insertions, 0 deletions
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) { |