summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog10
-rw-r--r--src/fileselection.c46
-rw-r--r--src/option.c24
-rw-r--r--src/zenity.h1
4 files changed, 77 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 40293a5b..5423f326 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+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.
+
2008-04-12 Karsten Braeckelmann <guenther@rudersport.de>
* HACKING: Fix typo and remove obsolete freeze note.
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) {
diff --git a/src/option.c b/src/option.c
index b56d5f09..9cbf490c 100644
--- a/src/option.c
+++ b/src/option.c
@@ -61,10 +61,11 @@ static gboolean zenity_error_active;
static gboolean zenity_info_active;
/* File Selection Dialog Options */
-static gboolean zenity_file_active;
-static gboolean zenity_file_directory;
-static gboolean zenity_file_save;
-static gboolean zenity_file_confirm_overwrite;
+static gboolean zenity_file_active;
+static gboolean zenity_file_directory;
+static gboolean zenity_file_save;
+static gboolean zenity_file_confirm_overwrite;
+static GtkFileFilter *zenity_file_filter;
/* List Dialog Options */
static gboolean zenity_list_active;
@@ -394,6 +395,15 @@ static GOptionEntry file_selection_options[] = {
N_("Confirm file selection if filename already exists"),
NULL
},
+ {
+ "file-filter",
+ '\0',
+ 0,
+ G_OPTION_ARG_STRING_ARRAY,
+ &zenity_file_filter,
+ N_("Sets a filename filter"),
+ N_("NAME | PATTERN1 PATTERN2 ..."),
+ },
{
NULL
}
@@ -981,6 +991,7 @@ zenity_file_pre_callback (GOptionContext *context,
zenity_file_directory = FALSE;
zenity_file_save = FALSE;
zenity_file_confirm_overwrite = FALSE;
+ zenity_file_filter = NULL;
return TRUE;
}
@@ -1233,6 +1244,7 @@ zenity_file_post_callback (GOptionContext *context,
results->file_data->save = zenity_file_save;
results->file_data->confirm_overwrite = zenity_file_confirm_overwrite;
results->file_data->separator = zenity_general_separator;
+ results->file_data->filter = zenity_file_filter;
} else {
if (zenity_file_directory)
zenity_option_error (zenity_option_get_name (file_selection_options, &zenity_file_directory),
@@ -1241,6 +1253,10 @@ zenity_file_post_callback (GOptionContext *context,
if (zenity_file_save)
zenity_option_error (zenity_option_get_name (file_selection_options, &zenity_file_save),
ERROR_SUPPORT);
+
+ if (zenity_file_filter)
+ zenity_option_error (zenity_option_get_name (file_selection_options, &zenity_file_filter),
+ ERROR_SUPPORT);
}
return TRUE;
diff --git a/src/zenity.h b/src/zenity.h
index 8865cd9b..511ee84d 100644
--- a/src/zenity.h
+++ b/src/zenity.h
@@ -81,6 +81,7 @@ typedef struct {
gboolean save;
gboolean confirm_overwrite;
gchar *separator;
+ gchar **filter;
} ZenityFileData;
typedef struct {
bgstack15