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
This commit is contained in:
parent
e37c2fe935
commit
8cda6025f0
10
ChangeLog
10
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.
|
||||
|
@ -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) {
|
||||
|
16
src/option.c
16
src/option.c
@ -65,6 +65,7 @@ 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;
|
||||
|
@ -81,6 +81,7 @@ typedef struct {
|
||||
gboolean save;
|
||||
gboolean confirm_overwrite;
|
||||
gchar *separator;
|
||||
gchar **filter;
|
||||
} ZenityFileData;
|
||||
|
||||
typedef struct {
|
||||
|
Reference in New Issue
Block a user