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.
This commit is contained in:
Glynn Foster 2003-01-14 01:52:23 +00:00 committed by Glynn Foster
parent 275dafc66e
commit f00eb34c06
4 changed files with 72 additions and 8 deletions

View File

@ -1,3 +1,9 @@
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.
2003-01-13 Glynn Foster <glynn.foster@sun.com>
* src/calendar.c: Re-structure the code to pass in the

View File

@ -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"));

View File

@ -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);
@ -113,6 +115,8 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data)
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,13 +237,37 @@ 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);
return FALSE;
}
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)
{
@ -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;

View File

@ -75,6 +75,7 @@ typedef struct {
GSList *columns;
gboolean checkbox;
gboolean radiobox;
gchar *separator;
const gchar **data;
} ZenityTreeData;