Allow multiple file selections.

This commit is contained in:
Mike Newman 2003-06-09 18:57:01 +00:00
parent 5bade6fe6a
commit 0e4c879656
6 changed files with 117 additions and 28 deletions

View File

@ -1,15 +1,21 @@
2003-06-09 Mike Newman <mikegtn@gnome.org>
* data/zenity.1, help/C/zenity.xml: Update docs for new file selection
options.
2003-06-09 Mike Newman <mikegtn@gnome.org>
* src/fileselection.c, src/main.c, src/zenity.h: Add --multiple
mode to file selection, with --separator to divide returned filenames.
Change default separator for lists and file-sel to '|'.
2003-06-07 Mike Newman <mikegtn@gnome.org> 2003-06-07 Mike Newman <mikegtn@gnome.org>
* src/calendar.c: Allow user-defined return values via env vars * src/calendar.c, src/entry.c, src/fileselection.c, src/msg.c
* src/entry.c: Prefer ZENITY_OK etc, but also check for DIALOG_OK src/progress.c, src/text.c, src/tree.c, src/util.c, src/util.h
* src/fileselection.c: and fall through to original zenity behaviour. src/zenity.h: Allow user-defined return values via env vars.
* src/msg.c: Prefer ZENITY_OK etc, but also check for DIALOG_OK and fall through
* src/progress.c: to original zenity behaviour.
* src/text.c:
* src/tree.c:
* src/util.c:
* src/util.h:
* src/zenity.h:
2003-06-07 Glynn Foster <glynn.foster@sun.com> 2003-06-07 Glynn Foster <glynn.foster@sun.com>

View File

@ -113,6 +113,12 @@ File selection options
.TP .TP
.B \-\-filename=FILENAME .B \-\-filename=FILENAME
Set the filename Set the filename
.TP
.B \-\-multiple
Allow selection of multiple filenames in file selection dialog
.TP
.B \-\-separator=SEPARATOR
Specify separator character when returning multiple filenames
.PP .PP
Info options Info options

View File

@ -539,6 +539,21 @@
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><varname>--multiple</varname></term>
<listitem>
<para>Allow selection of mulitple filename in the File Selection dialog.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>--separator</varname>=SEPARATOR</term>
<listitem>
<para>Specify the character(s) which will divide between entries in the returned list of file names. The
default character is '|'. If you want to specify a newline, use '\n'.</para>
</listitem>
</varlistentry>
</variablelist> </variablelist>
<figure id="zenity-fileselection-screenshot"> <figure id="zenity-fileselection-screenshot">
@ -642,8 +657,8 @@
<varlistentry> <varlistentry>
<term><varname>--seperator</varname>=SEPERATOR</term> <term><varname>--seperator</varname>=SEPERATOR</term>
<listitem> <listitem>
<para>Specify what seperator character should be used when the List dialog returns the selected entries. The <para>Specify what seperator character(s) should be used when the List dialog returns the selected entries. The
default character is '\'. If you want to specify a newline, use '\n'. default character is '|'. If you want to specify a newline, use '\n'.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>

View File

@ -25,6 +25,8 @@
#include "zenity.h" #include "zenity.h"
#include "util.h" #include "util.h"
ZenityData *zen_data;
static void zenity_fileselection_dialog_response (GtkWidget *widget, int response, gpointer data); static void zenity_fileselection_dialog_response (GtkWidget *widget, int response, gpointer data);
void zenity_fileselection (ZenityData *data, ZenityFileData *file_data) void zenity_fileselection (ZenityData *data, ZenityFileData *file_data)
@ -32,6 +34,8 @@ void zenity_fileselection (ZenityData *data, ZenityFileData *file_data)
GladeXML *glade_dialog; GladeXML *glade_dialog;
GtkWidget *dialog; GtkWidget *dialog;
zen_data = data;
glade_dialog = zenity_util_load_glade_file ("zenity_fileselection_dialog"); glade_dialog = zenity_util_load_glade_file ("zenity_fileselection_dialog");
if (glade_dialog == NULL) { if (glade_dialog == NULL) {
@ -47,7 +51,7 @@ void zenity_fileselection (ZenityData *data, ZenityFileData *file_data)
g_object_unref (glade_dialog); g_object_unref (glade_dialog);
g_signal_connect (G_OBJECT (dialog), "response", g_signal_connect (G_OBJECT (dialog), "response",
G_CALLBACK (zenity_fileselection_dialog_response), data); G_CALLBACK (zenity_fileselection_dialog_response), file_data);
if (data->dialog_title) if (data->dialog_title)
gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title); gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title);
@ -62,6 +66,9 @@ void zenity_fileselection (ZenityData *data, ZenityFileData *file_data)
if (file_data->uri) if (file_data->uri)
gtk_file_selection_set_filename (GTK_FILE_SELECTION (dialog), file_data->uri); gtk_file_selection_set_filename (GTK_FILE_SELECTION (dialog), file_data->uri);
if (file_data->multi)
gtk_file_selection_set_select_multiple (GTK_FILE_SELECTION (dialog), TRUE);
gtk_widget_show (dialog); gtk_widget_show (dialog);
gtk_main (); gtk_main ();
} }
@ -69,13 +76,32 @@ void zenity_fileselection (ZenityData *data, ZenityFileData *file_data)
static void static void
zenity_fileselection_dialog_response (GtkWidget *widget, int response, gpointer data) zenity_fileselection_dialog_response (GtkWidget *widget, int response, gpointer data)
{ {
ZenityData *zen_data = data; ZenityFileData *file_data = data;
gchar **selections;
gchar *separator = g_strdup(file_data->separator);
int i;
switch (response) { switch (response) {
case GTK_RESPONSE_OK: case GTK_RESPONSE_OK:
zen_data->exit_code = zenity_util_return_exit_code zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK);
(ZENITY_OK); selections = gtk_file_selection_get_selections (GTK_FILE_SELECTION (widget));
g_printerr ("%s\n", gtk_file_selection_get_filename (GTK_FILE_SELECTION (widget))); for (i=0;selections[i] != NULL; i++) {
g_printerr ("%s", g_filename_to_utf8 ((gchar*)selections[i], -1, NULL, NULL, NULL));
if (selections[i+1] != NULL) {
/* FIXME: This is a blatant copy of Gman's arse in tree.c */
if (strstr ((const gchar *) separator, (const gchar *) "\\n") != NULL)
g_printerr ("\n");
else if (strstr ((const gchar *) separator, (const gchar *) "\\t") != NULL)
g_printerr ("\t");
else
g_printerr ("%s",separator);
} else {
g_printerr ("\n");
}
}
g_strfreev(selections);
g_free(separator);
gtk_main_quit (); gtk_main_quit ();
break; break;

View File

@ -89,6 +89,7 @@ enum {
OPTION_ERRORTEXT, OPTION_ERRORTEXT,
OPTION_INFOTEXT, OPTION_INFOTEXT,
OPTION_FILENAME, OPTION_FILENAME,
OPTION_MULTIFILE,
OPTION_TEXTFILENAME, OPTION_TEXTFILENAME,
OPTION_COLUMN, OPTION_COLUMN,
OPTION_SEPERATOR, OPTION_SEPERATOR,
@ -424,6 +425,24 @@ struct poptOption file_selection_options[] = {
N_("Set the filename"), N_("Set the filename"),
N_("FILENAME") N_("FILENAME")
}, },
{
"multiple",
'\0',
POPT_ARG_NONE,
NULL,
OPTION_MULTIFILE,
N_("Allow multiple files to be selected"),
NULL
},
{
"separator",
'\0',
POPT_ARG_STRING,
NULL,
OPTION_SEPERATOR,
N_("Set output separator character."),
N_("SEPARATOR")
},
POPT_TABLEEND POPT_TABLEEND
}; };
@ -471,7 +490,7 @@ struct poptOption list_options[] = {
NULL, NULL,
OPTION_SEPERATOR, OPTION_SEPERATOR,
N_("Set output separator character"), N_("Set output separator character"),
NULL N_("SEPARATOR")
}, },
{ {
"editable", "editable",
@ -925,8 +944,10 @@ zenity_init_parsing_options (void) {
results->calendar_data->month = 0; results->calendar_data->month = 0;
results->calendar_data->year = 0; results->calendar_data->year = 0;
results->calendar_data->dialog_text = NULL; results->calendar_data->dialog_text = NULL;
results->file_data->multi = FALSE;
results->file_data->separator = g_strdup ("|");
results->text_data->editable = FALSE; results->text_data->editable = FALSE;
results->tree_data->separator = g_strdup ("/"); results->tree_data->separator = g_strdup ("|");
results->progress_data->percentage = -1; results->progress_data->percentage = -1;
results->progress_data->pulsate = FALSE; results->progress_data->pulsate = FALSE;
results->progress_data->autoclose = FALSE; results->progress_data->autoclose = FALSE;
@ -969,6 +990,7 @@ zenity_free_parsing_options (void) {
case MODE_FILE: case MODE_FILE:
if (results->file_data->uri) if (results->file_data->uri)
g_free (results->file_data->uri); g_free (results->file_data->uri);
g_free (results->file_data->separator);
break; break;
case MODE_TEXTINFO: case MODE_TEXTINFO:
if (results->text_data->uri) if (results->text_data->uri)
@ -1336,6 +1358,12 @@ zenity_parse_options_callback (poptContext ctx,
} }
parse_option_file++; parse_option_file++;
break; break;
case OPTION_MULTIFILE:
if (results->mode != MODE_FILE)
zenity_error ("--multiple", ERROR_SUPPORT);
results->file_data->multi = TRUE;
break;
case OPTION_COLUMN: case OPTION_COLUMN:
if (results->mode != MODE_LIST) if (results->mode != MODE_LIST)
zenity_error ("--column", ERROR_SUPPORT); zenity_error ("--column", ERROR_SUPPORT);
@ -1360,15 +1388,21 @@ zenity_parse_options_callback (poptContext ctx,
results->tree_data->radiobox = TRUE; results->tree_data->radiobox = TRUE;
break; break;
case OPTION_SEPERATOR: case OPTION_SEPERATOR:
if (results->mode != MODE_LIST)
zenity_error ("--separator", ERROR_SUPPORT);
if (parse_option_separator) if (parse_option_separator)
zenity_error ("--separator", ERROR_DUPLICATE); zenity_error ("--separator", ERROR_DUPLICATE);
switch (results->mode) {
case MODE_LIST:
results->tree_data->separator = g_strdup (arg); results->tree_data->separator = g_strdup (arg);
parse_option_separator = TRUE; parse_option_separator = TRUE;
break; break;
case MODE_FILE:
results->file_data->separator = g_strdup (arg);
parse_option_separator = TRUE;
break;
default:
zenity_error ("--separator", ERROR_SUPPORT);
}
break;
case OPTION_PERCENTAGE: case OPTION_PERCENTAGE:
if (results->mode != MODE_PROGRESS) if (results->mode != MODE_PROGRESS)
zenity_error ("--percentage", ERROR_SUPPORT); zenity_error ("--percentage", ERROR_SUPPORT);

View File

@ -61,6 +61,8 @@ typedef struct {
typedef struct { typedef struct {
gchar *uri; gchar *uri;
gboolean multi;
gchar *separator;
} ZenityFileData; } ZenityFileData;
typedef struct { typedef struct {