summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/fileselection.c36
-rw-r--r--src/main.c56
-rw-r--r--src/zenity.h2
3 files changed, 78 insertions, 16 deletions
diff --git a/src/fileselection.c b/src/fileselection.c
index 69fc6583..4e87d043 100644
--- a/src/fileselection.c
+++ b/src/fileselection.c
@@ -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;
diff --git a/src/main.c b/src/main.c
index 23c4721b..32c98a14 100644
--- a/src/main.c
+++ b/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,15 +1388,21 @@ 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;
- break;
+ if (parse_option_separator)
+ 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)
zenity_error ("--percentage", ERROR_SUPPORT);
diff --git a/src/zenity.h b/src/zenity.h
index 97ecee17..b04ff5bb 100644
--- a/src/zenity.h
+++ b/src/zenity.h
@@ -61,6 +61,8 @@ typedef struct {
typedef struct {
gchar *uri;
+ gboolean multi;
+ gchar *separator;
} ZenityFileData;
typedef struct {
bgstack15