summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGlynn Foster <glynn.foster@sun.com>2003-01-14 01:52:23 +0000
committerGlynn Foster <gman@src.gnome.org>2003-01-14 01:52:23 +0000
commitf00eb34c0604dcf68457ab09278295f647c622b8 (patch)
tree1d4d1058e57a367061b9f8d82603261205c528e8 /src
parentWhitespace hacking. (diff)
downloadzenity-f00eb34c0604dcf68457ab09278295f647c622b8.tar.gz
zenity-f00eb34c0604dcf68457ab09278295f647c622b8.tar.bz2
zenity-f00eb34c0604dcf68457ab09278295f647c622b8.zip
Add support to separate the selected rows output with a character with '/'
2003-01-14 Glynn Foster <glynn.foster@sun.com> * src/tree.c, src/zenity.h, src/main.c: Add support to separate the selected rows output with a character with '/' used by default.
Diffstat (limited to 'src')
-rw-r--r--src/main.c28
-rw-r--r--src/tree.c45
-rw-r--r--src/zenity.h1
3 files changed, 66 insertions, 8 deletions
diff --git a/src/main.c b/src/main.c
index 3e58bd49..26232327 100644
--- a/src/main.c
+++ b/src/main.c
@@ -78,6 +78,7 @@ enum {
OPTION_INFOTEXT,
OPTION_FILENAME,
OPTION_COLUMN,
+ OPTION_SEPERATOR,
OPTION_CHECKLIST,
OPTION_RADIOLIST,
OPTION_PROGRESSTEXT,
@@ -431,6 +432,15 @@ struct poptOption list_options[] = {
N_("Use radio buttons for first column"),
NULL
},
+ {
+ "separator",
+ '\0',
+ POPT_ARG_STRING,
+ NULL,
+ OPTION_SEPERATOR,
+ N_("Set output separator character"),
+ NULL
+ },
POPT_TABLEEND
};
@@ -716,6 +726,7 @@ zenity_init_parsing_options (void) {
results->calendar_data->month = 0;
results->calendar_data->year = 0;
results->calendar_data->dialog_text = NULL;
+ results->tree_data->separator = g_strdup ("/");
results->progress_data->percentage = -1;
results->progress_data->pulsate = FALSE;
results->entry_data->visible = TRUE;
@@ -764,6 +775,8 @@ zenity_free_parsing_options (void) {
case MODE_LIST:
if (results->tree_data->columns)
g_slist_foreach (results->tree_data->columns, (GFunc) g_free, NULL);
+ if (results->tree_data->separator)
+ g_free (results->tree_data->separator);
break;
default:
break;
@@ -856,6 +869,7 @@ void zenity_parse_options_callback (poptContext ctx,
void *data)
{
static gboolean parse_option_dateformat = FALSE;
+ static gboolean parse_option_separator = FALSE;
static gint parse_option_text = 0;
static gint parse_option_file = 0;
@@ -1149,6 +1163,20 @@ void zenity_parse_options_callback (poptContext ctx,
}
results->tree_data->radiobox = TRUE;
break;
+ case OPTION_SEPERATOR:
+ if (results->mode != MODE_LIST) {
+ g_printerr (_("--separator is not supported for this dialog\n"));
+ zenity_free_parsing_options ();
+ exit (-1);
+ }
+ if (parse_option_separator == TRUE) {
+ g_printerr (_("--separator given twice for the same dialog\n"));
+ zenity_free_parsing_options ();
+ exit (-1);
+ }
+ results->tree_data->separator = g_strdup (arg);
+ parse_option_separator = TRUE;
+ break;
case OPTION_PERCENTAGE:
if (results->mode != MODE_PROGRESS) {
g_printerr (_("--percentage is not supported for this dialog\n"));
diff --git a/src/tree.c b/src/tree.c
index 2b310023..29b38c66 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -30,6 +30,8 @@
#define MAX_ELEMENTS_BEFORE_SCROLLING 8
static GladeXML *glade_dialog;
+static GSList *selected;
+static gchar *separator;
static void zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer data);
@@ -70,7 +72,7 @@ zenity_tree_fill_entries (GtkTreeView *tree_view, const gchar **args, gint n_col
for (j = 0; j < n_columns; j++) {
if (toggles && j == 0) {
- if (strcmp (args[i+j], "TRUE") == 0 || strcmp (args[i+j], "true") == 0)
+ if (strcmp (args[i+j], "TRUE") == 0)
gtk_list_store_set (GTK_LIST_STORE (model), &iter, j, TRUE, -1);
else
gtk_list_store_set (GTK_LIST_STORE (model), &iter, j, FALSE, -1);
@@ -112,7 +114,9 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data)
data->exit_code = -1;
return;
}
-
+
+ separator = g_strdup (tree_data->separator);
+
n_columns = g_slist_length (tree_data->columns);
if (n_columns == 0) {
@@ -213,18 +217,18 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data)
}
static void
-zenity_tree_dialog_output (GtkTreeModel *model, GtkTreePath *path_buf, GtkTreeIter *iter, GtkTreeView *tree_view)
+zenity_tree_dialog_get_selected (GtkTreeModel *model, GtkTreePath *path_buf, GtkTreeIter *iter, GtkTreeView *tree_view)
{
GValue value = {0, };
gtk_tree_model_get_value (model, iter, 0, &value);
- g_printerr ("%s", g_value_get_string (&value));
+ selected = g_slist_append (selected, g_strdup (g_value_get_string (&value)));
g_value_unset (&value);
}
static gboolean
-zenity_tree_dialog_toggle_output (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
+zenity_tree_dialog_toggle_get_selected (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
{
GValue toggle_value = {0, };
@@ -233,7 +237,7 @@ zenity_tree_dialog_toggle_output (GtkTreeModel *model, GtkTreePath *path, GtkTre
if (g_value_get_boolean (&toggle_value) == TRUE) {
GValue value = {0, };
gtk_tree_model_get_value (model, iter, 1, &value);
- g_printerr ("%s", g_value_get_string (&value));
+ selected = g_slist_append (selected, g_strdup (g_value_get_string (&value)));
g_value_unset (&value);
}
g_value_unset (&toggle_value);
@@ -241,6 +245,30 @@ zenity_tree_dialog_toggle_output (GtkTreeModel *model, GtkTreePath *path, GtkTre
}
static void
+zenity_tree_dialog_output (void)
+{
+ GSList *tmp;
+
+ for (tmp = selected; tmp; tmp = tmp->next) {
+ if (tmp->next != NULL) {
+ /* FIXME: There must be a nicer way to do this. This is just arse */
+ if (strstr (separator, "\\n") != NULL)
+ g_printerr ("%s\n", tmp->data);
+ else if (strstr (separator, "\\t") != NULL)
+ g_printerr ("%s\t", tmp->data);
+ else
+ g_printerr ("%s%s", tmp->data, separator);
+ }
+ else
+ g_printerr ("%s\n", tmp->data);
+ }
+
+ g_free (separator);
+ g_slist_foreach (selected, (GFunc) g_free, NULL);
+ selected = NULL;
+}
+
+static void
zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer data)
{
ZenityData *zen_data = data;
@@ -255,15 +283,16 @@ zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer data)
if (gtk_tree_model_get_column_type (model, 0) == G_TYPE_BOOLEAN) {
gtk_tree_model_foreach (model,
- (GtkTreeModelForeachFunc) zenity_tree_dialog_toggle_output,
+ (GtkTreeModelForeachFunc) zenity_tree_dialog_toggle_get_selected,
NULL);
}
else {
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));
gtk_tree_selection_selected_foreach (selection,
- (GtkTreeSelectionForeachFunc) zenity_tree_dialog_output,
+ (GtkTreeSelectionForeachFunc) zenity_tree_dialog_get_selected,
GTK_TREE_VIEW (tree_view));
}
+ zenity_tree_dialog_output ();
zen_data->exit_code = 0;
gtk_main_quit ();
break;
diff --git a/src/zenity.h b/src/zenity.h
index bedec33a..94311383 100644
--- a/src/zenity.h
+++ b/src/zenity.h
@@ -75,6 +75,7 @@ typedef struct {
GSList *columns;
gboolean checkbox;
gboolean radiobox;
+ gchar *separator;
const gchar **data;
} ZenityTreeData;
bgstack15