diff options
author | Glynn Foster <glynn.foster@sun.com> | 2004-07-19 01:01:28 +0000 |
---|---|---|
committer | Glynn Foster <gman@src.gnome.org> | 2004-07-19 01:01:28 +0000 |
commit | ffaed088561e8c0a085fd2797543aaef65419f0c (patch) | |
tree | f1b9c6773cb568195fd5c9b2384dc20f08b1a2e0 | |
parent | Remove duplicate locale.h include. Patch from Leonardo Boshell. Partly (diff) | |
download | zenity-ffaed088561e8c0a085fd2797543aaef65419f0c.tar.gz zenity-ffaed088561e8c0a085fd2797543aaef65419f0c.tar.bz2 zenity-ffaed088561e8c0a085fd2797543aaef65419f0c.zip |
Add new option for --print-column, based on a patch by Paul Bolle. Fixes
2004-07-19 Glynn Foster <glynn.foster@sun.com>
* src/main.c, src/tree.c, src/zenity.h,
help/C/zenity.xml: Add new option for --print-column, based
on a patch by Paul Bolle. Fixes #144496.
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | help/C/zenity.xml | 9 | ||||
-rw-r--r-- | src/main.c | 27 | ||||
-rw-r--r-- | src/tree.c | 65 | ||||
-rw-r--r-- | src/zenity.h | 1 |
5 files changed, 94 insertions, 14 deletions
@@ -1,5 +1,11 @@ 2004-07-19 Glynn Foster <glynn.foster@sun.com> + * src/main.c, src/tree.c, src/zenity.h, + help/C/zenity.xml: Add new option for --print-column, based + on a patch by Paul Bolle. Fixes #144496. + +2004-07-19 Glynn Foster <glynn.foster@sun.com> + * src/main.c: Remove duplicate locale.h include. Patch from Leonardo Boshell. Partly fixes #137993. diff --git a/help/C/zenity.xml b/help/C/zenity.xml index f65de69b..4dc745d6 100644 --- a/help/C/zenity.xml +++ b/help/C/zenity.xml @@ -653,6 +653,15 @@ </listitem> </varlistentry> + <varlistentry> + <term><varname>--print-column</varname>=COLUMN</term> + <listitem> + <para>Specifies what column should be printed to standard output. The default is to return + the first column. 'ALL' may be specified to print out all columns. + </para> + </listitem> + </varlistentry> + </variablelist> <para> @@ -105,6 +105,7 @@ enum { OPTION_PERCENTAGE, OPTION_PULSATE, OPTION_AUTOCLOSE, + OPTION_PRINTCOLUMN, OPTION_QUESTIONTEXT, OPTION_WARNINGTEXT, OPTION_ABOUT, @@ -113,10 +114,10 @@ enum { }; static void zenity_parse_options_callback (poptContext ctx, - enum poptCallbackReason reason, - const struct poptOption *opt, - const char *arg, - void *data); + enum poptCallbackReason reason, + const struct poptOption *opt, + const char *arg, + void *data); struct poptOption options[] = { { @@ -515,6 +516,15 @@ struct poptOption list_options[] = { N_("Allow changes to text"), NULL }, + { + "print-column", + '\0', + POPT_ARG_STRING, + NULL, + OPTION_PRINTCOLUMN, + N_("Print a specific column (Default is 1. 'ALL' can be used to print all columns)"), + NULL + }, POPT_TABLEEND }; @@ -972,6 +982,7 @@ zenity_init_parsing_options (void) { results->tree_data->checkbox = FALSE; results->tree_data->radiobox = FALSE; results->tree_data->editable = FALSE; + results->tree_data->print_column = NULL; } static void @@ -1020,6 +1031,8 @@ zenity_free_parsing_options (void) { g_slist_foreach (results->tree_data->columns, (GFunc) g_free, NULL); if (results->tree_data->separator) g_free (results->tree_data->separator); + if (results->tree_data->print_column) + g_free (results->tree_data->print_column); break; default: break; @@ -1456,6 +1469,12 @@ zenity_parse_options_callback (poptContext ctx, results->progress_data->autoclose = TRUE; break; + case OPTION_PRINTCOLUMN: + if (results->mode != MODE_LIST) + zenity_error ("--print-column", ERROR_SUPPORT); + + results->tree_data->print_column = g_strdup (arg); + break; case OPTION_ABOUT: if (results->mode != MODE_LAST) zenity_error (NULL, ERROR_DIALOG); @@ -33,6 +33,8 @@ static GladeXML *glade_dialog; static GSList *selected; static gchar *separator; +static gboolean print_all_columns = FALSE; +static gint print_column_n = 1; static void zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer data); @@ -139,7 +141,7 @@ zenity_tree_handle_stdin (GIOChannel *channel, } if (toggles && column_count == 0) { - if (strcmp (zenity_util_strip_newline (string->str), "TRUE") == 0) + if (strcmp (g_strdown (zenity_util_strip_newline (string->str)), "true") == 0) gtk_list_store_set (GTK_LIST_STORE (model), &iter, column_count, TRUE, -1); else gtk_list_store_set (GTK_LIST_STORE (model), &iter, column_count, FALSE, -1); @@ -207,6 +209,8 @@ zenity_tree_fill_entries (GtkTreeView *tree_view, model = gtk_tree_view_get_model (tree_view); + g_object_set_data (G_OBJECT (tree_view), "n_columns", (gint *) n_columns); + while (args[i] != NULL) { gint j; @@ -215,7 +219,7 @@ zenity_tree_fill_entries (GtkTreeView *tree_view, for (j = 0; j < n_columns; j++) { if (toggles && j == 0) { - if (strcmp (args[i+j], "TRUE") == 0) + if (strcmp (g_strdown ((gchar *) 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); @@ -288,6 +292,13 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) n_columns = g_slist_length (tree_data->columns); + if (tree_data->print_column) { + if (strcmp (g_strdown (tree_data->print_column), "all") == 0) + print_all_columns = TRUE; + else + print_column_n = atoi (tree_data->print_column); + } + if (n_columns == 0) { g_printerr (_("No column titles specified for List dialog.\n")); data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR); @@ -454,25 +465,58 @@ static void zenity_tree_dialog_get_selected (GtkTreeModel *model, GtkTreePath *path_buf, GtkTreeIter *iter, GtkTreeView *tree_view) { GValue value = {0, }; + gint n_columns, i; + + n_columns = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tree_view), "n_columns")); - gtk_tree_model_get_value (model, iter, 0, &value); + if (print_all_columns) { + for (i = 0; i < n_columns; i++) { + gtk_tree_model_get_value (model, iter, i, &value); - selected = g_slist_append (selected, g_strdup (g_value_get_string (&value))); - g_value_unset (&value); + selected = g_slist_append (selected, g_strdup (g_value_get_string (&value))); + g_value_unset (&value); + } + return; + } + + if (print_column_n > 0 && print_column_n <= n_columns) { + gtk_tree_model_get_value (model, iter, print_column_n - 1, &value); + + selected = g_slist_append (selected, g_strdup (g_value_get_string (&value))); + g_value_unset (&value); + } } static gboolean -zenity_tree_dialog_toggle_get_selected (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data) +zenity_tree_dialog_toggle_get_selected (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, GtkTreeView *tree_view) { GValue toggle_value = {0, }; + gint n_columns, i; + + n_columns = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tree_view), "n_columns")); gtk_tree_model_get_value (model, iter, 0, &toggle_value); if (g_value_get_boolean (&toggle_value)) { GValue value = {0, }; - gtk_tree_model_get_value (model, iter, 1, &value); - selected = g_slist_append (selected, g_strdup (g_value_get_string (&value))); - g_value_unset (&value); + + if (print_all_columns) { + for (i = 1; i < n_columns; i++) { + gtk_tree_model_get_value (model, iter, i, &value); + + selected = g_slist_append (selected, g_strdup (g_value_get_string (&value))); + g_value_unset (&value); + } + g_value_unset (&toggle_value); + return FALSE; + } + + if (print_column_n > 0 && print_column_n <= n_columns) { + gtk_tree_model_get_value (model, iter, print_column_n, &value); + + selected = g_slist_append (selected, g_strdup (g_value_get_string (&value))); + g_value_unset (&value); + } } g_value_unset (&toggle_value); return FALSE; @@ -510,7 +554,8 @@ zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer data) model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view)); if (gtk_tree_model_get_column_type (model, 0) == G_TYPE_BOOLEAN) - gtk_tree_model_foreach (model, (GtkTreeModelForeachFunc) zenity_tree_dialog_toggle_get_selected, NULL); + gtk_tree_model_foreach (model, (GtkTreeModelForeachFunc) zenity_tree_dialog_toggle_get_selected, + GTK_TREE_VIEW (tree_view)); else { selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)); gtk_tree_selection_selected_foreach (selection, diff --git a/src/zenity.h b/src/zenity.h index b04ff5bb..36cf52e2 100644 --- a/src/zenity.h +++ b/src/zenity.h @@ -92,6 +92,7 @@ typedef struct { gboolean radiobox; gchar *separator; gboolean editable; + gchar *print_column; const gchar **data; } ZenityTreeData; |