Allow multiple file selections.
This commit is contained in:
parent
5bade6fe6a
commit
0e4c879656
26
ChangeLog
26
ChangeLog
@ -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>
|
||||
|
||||
* src/calendar.c: Allow user-defined return values via env vars
|
||||
* src/entry.c: Prefer ZENITY_OK etc, but also check for DIALOG_OK
|
||||
* src/fileselection.c: and fall through to original zenity behaviour.
|
||||
* src/msg.c:
|
||||
* src/progress.c:
|
||||
* src/text.c:
|
||||
* src/tree.c:
|
||||
* src/util.c:
|
||||
* src/util.h:
|
||||
* src/zenity.h:
|
||||
* src/calendar.c, src/entry.c, src/fileselection.c, src/msg.c
|
||||
src/progress.c, src/text.c, src/tree.c, src/util.c, src/util.h
|
||||
src/zenity.h: Allow user-defined return values via env vars.
|
||||
Prefer ZENITY_OK etc, but also check for DIALOG_OK and fall through
|
||||
to original zenity behaviour.
|
||||
|
||||
2003-06-07 Glynn Foster <glynn.foster@sun.com>
|
||||
|
||||
|
@ -113,6 +113,12 @@ File selection options
|
||||
.TP
|
||||
.B \-\-filename=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
|
||||
Info options
|
||||
|
@ -539,6 +539,21 @@
|
||||
</listitem>
|
||||
</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>
|
||||
|
||||
<figure id="zenity-fileselection-screenshot">
|
||||
@ -642,8 +657,8 @@
|
||||
<varlistentry>
|
||||
<term><varname>--seperator</varname>=SEPERATOR</term>
|
||||
<listitem>
|
||||
<para>Specify what seperator character should be used when the List dialog returns the selected entries. The
|
||||
default character is '\'. If you want to specify a newline, use '\n'.
|
||||
<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'.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
@ -25,6 +25,8 @@
|
||||
#include "zenity.h"
|
||||
#include "util.h"
|
||||
|
||||
ZenityData *zen_data;
|
||||
|
||||
static void zenity_fileselection_dialog_response (GtkWidget *widget, int response, gpointer data);
|
||||
|
||||
void zenity_fileselection (ZenityData *data, ZenityFileData *file_data)
|
||||
@ -32,6 +34,8 @@ void zenity_fileselection (ZenityData *data, ZenityFileData *file_data)
|
||||
GladeXML *glade_dialog;
|
||||
GtkWidget *dialog;
|
||||
|
||||
zen_data = data;
|
||||
|
||||
glade_dialog = zenity_util_load_glade_file ("zenity_fileselection_dialog");
|
||||
|
||||
if (glade_dialog == NULL) {
|
||||
@ -47,7 +51,7 @@ void zenity_fileselection (ZenityData *data, ZenityFileData *file_data)
|
||||
g_object_unref (glade_dialog);
|
||||
|
||||
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)
|
||||
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)
|
||||
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_main ();
|
||||
}
|
||||
@ -69,13 +76,32 @@ void zenity_fileselection (ZenityData *data, ZenityFileData *file_data)
|
||||
static void
|
||||
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) {
|
||||
case GTK_RESPONSE_OK:
|
||||
zen_data->exit_code = zenity_util_return_exit_code
|
||||
(ZENITY_OK);
|
||||
g_printerr ("%s\n", gtk_file_selection_get_filename (GTK_FILE_SELECTION (widget)));
|
||||
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK);
|
||||
selections = gtk_file_selection_get_selections (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 ();
|
||||
break;
|
||||
|
||||
|
52
src/main.c
52
src/main.c
@ -89,6 +89,7 @@ enum {
|
||||
OPTION_ERRORTEXT,
|
||||
OPTION_INFOTEXT,
|
||||
OPTION_FILENAME,
|
||||
OPTION_MULTIFILE,
|
||||
OPTION_TEXTFILENAME,
|
||||
OPTION_COLUMN,
|
||||
OPTION_SEPERATOR,
|
||||
@ -424,6 +425,24 @@ struct poptOption file_selection_options[] = {
|
||||
N_("Set the 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
|
||||
};
|
||||
|
||||
@ -471,7 +490,7 @@ struct poptOption list_options[] = {
|
||||
NULL,
|
||||
OPTION_SEPERATOR,
|
||||
N_("Set output separator character"),
|
||||
NULL
|
||||
N_("SEPARATOR")
|
||||
},
|
||||
{
|
||||
"editable",
|
||||
@ -925,8 +944,10 @@ zenity_init_parsing_options (void) {
|
||||
results->calendar_data->month = 0;
|
||||
results->calendar_data->year = 0;
|
||||
results->calendar_data->dialog_text = NULL;
|
||||
results->file_data->multi = FALSE;
|
||||
results->file_data->separator = g_strdup ("|");
|
||||
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->pulsate = FALSE;
|
||||
results->progress_data->autoclose = FALSE;
|
||||
@ -969,6 +990,7 @@ zenity_free_parsing_options (void) {
|
||||
case MODE_FILE:
|
||||
if (results->file_data->uri)
|
||||
g_free (results->file_data->uri);
|
||||
g_free (results->file_data->separator);
|
||||
break;
|
||||
case MODE_TEXTINFO:
|
||||
if (results->text_data->uri)
|
||||
@ -1336,6 +1358,12 @@ zenity_parse_options_callback (poptContext ctx,
|
||||
}
|
||||
parse_option_file++;
|
||||
break;
|
||||
case OPTION_MULTIFILE:
|
||||
if (results->mode != MODE_FILE)
|
||||
zenity_error ("--multiple", ERROR_SUPPORT);
|
||||
|
||||
results->file_data->multi = TRUE;
|
||||
break;
|
||||
case OPTION_COLUMN:
|
||||
if (results->mode != MODE_LIST)
|
||||
zenity_error ("--column", ERROR_SUPPORT);
|
||||
@ -1360,14 +1388,20 @@ zenity_parse_options_callback (poptContext ctx,
|
||||
results->tree_data->radiobox = TRUE;
|
||||
break;
|
||||
case OPTION_SEPERATOR:
|
||||
if (results->mode != MODE_LIST)
|
||||
zenity_error ("--separator", ERROR_SUPPORT);
|
||||
|
||||
if (parse_option_separator)
|
||||
zenity_error ("--separator", ERROR_DUPLICATE);
|
||||
|
||||
results->tree_data->separator = g_strdup (arg);
|
||||
parse_option_separator = TRUE;
|
||||
zenity_error ("--separator", ERROR_DUPLICATE);
|
||||
switch (results->mode) {
|
||||
case MODE_LIST:
|
||||
results->tree_data->separator = g_strdup (arg);
|
||||
parse_option_separator = TRUE;
|
||||
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:
|
||||
if (results->mode != MODE_PROGRESS)
|
||||
|
@ -61,6 +61,8 @@ typedef struct {
|
||||
|
||||
typedef struct {
|
||||
gchar *uri;
|
||||
gboolean multi;
|
||||
gchar *separator;
|
||||
} ZenityFileData;
|
||||
|
||||
typedef struct {
|
||||
|
Reference in New Issue
Block a user