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.
This commit is contained in:
parent
b986224682
commit
ffaed08856
@ -1,3 +1,9 @@
|
|||||||
|
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>
|
2004-07-19 Glynn Foster <glynn.foster@sun.com>
|
||||||
|
|
||||||
* src/main.c: Remove duplicate locale.h include. Patch
|
* src/main.c: Remove duplicate locale.h include. Patch
|
||||||
|
@ -653,6 +653,15 @@
|
|||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</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>
|
</variablelist>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
|
19
src/main.c
19
src/main.c
@ -105,6 +105,7 @@ enum {
|
|||||||
OPTION_PERCENTAGE,
|
OPTION_PERCENTAGE,
|
||||||
OPTION_PULSATE,
|
OPTION_PULSATE,
|
||||||
OPTION_AUTOCLOSE,
|
OPTION_AUTOCLOSE,
|
||||||
|
OPTION_PRINTCOLUMN,
|
||||||
OPTION_QUESTIONTEXT,
|
OPTION_QUESTIONTEXT,
|
||||||
OPTION_WARNINGTEXT,
|
OPTION_WARNINGTEXT,
|
||||||
OPTION_ABOUT,
|
OPTION_ABOUT,
|
||||||
@ -515,6 +516,15 @@ struct poptOption list_options[] = {
|
|||||||
N_("Allow changes to text"),
|
N_("Allow changes to text"),
|
||||||
NULL
|
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
|
POPT_TABLEEND
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -972,6 +982,7 @@ zenity_init_parsing_options (void) {
|
|||||||
results->tree_data->checkbox = FALSE;
|
results->tree_data->checkbox = FALSE;
|
||||||
results->tree_data->radiobox = FALSE;
|
results->tree_data->radiobox = FALSE;
|
||||||
results->tree_data->editable = FALSE;
|
results->tree_data->editable = FALSE;
|
||||||
|
results->tree_data->print_column = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -1020,6 +1031,8 @@ zenity_free_parsing_options (void) {
|
|||||||
g_slist_foreach (results->tree_data->columns, (GFunc) g_free, NULL);
|
g_slist_foreach (results->tree_data->columns, (GFunc) g_free, NULL);
|
||||||
if (results->tree_data->separator)
|
if (results->tree_data->separator)
|
||||||
g_free (results->tree_data->separator);
|
g_free (results->tree_data->separator);
|
||||||
|
if (results->tree_data->print_column)
|
||||||
|
g_free (results->tree_data->print_column);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -1456,6 +1469,12 @@ zenity_parse_options_callback (poptContext ctx,
|
|||||||
|
|
||||||
results->progress_data->autoclose = TRUE;
|
results->progress_data->autoclose = TRUE;
|
||||||
break;
|
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:
|
case OPTION_ABOUT:
|
||||||
if (results->mode != MODE_LAST)
|
if (results->mode != MODE_LAST)
|
||||||
zenity_error (NULL, ERROR_DIALOG);
|
zenity_error (NULL, ERROR_DIALOG);
|
||||||
|
57
src/tree.c
57
src/tree.c
@ -33,6 +33,8 @@
|
|||||||
static GladeXML *glade_dialog;
|
static GladeXML *glade_dialog;
|
||||||
static GSList *selected;
|
static GSList *selected;
|
||||||
static gchar *separator;
|
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);
|
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 (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);
|
gtk_list_store_set (GTK_LIST_STORE (model), &iter, column_count, TRUE, -1);
|
||||||
else
|
else
|
||||||
gtk_list_store_set (GTK_LIST_STORE (model), &iter, column_count, FALSE, -1);
|
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);
|
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) {
|
while (args[i] != NULL) {
|
||||||
gint j;
|
gint j;
|
||||||
|
|
||||||
@ -215,7 +219,7 @@ zenity_tree_fill_entries (GtkTreeView *tree_view,
|
|||||||
for (j = 0; j < n_columns; j++) {
|
for (j = 0; j < n_columns; j++) {
|
||||||
|
|
||||||
if (toggles && j == 0) {
|
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);
|
gtk_list_store_set (GTK_LIST_STORE (model), &iter, j, TRUE, -1);
|
||||||
else
|
else
|
||||||
gtk_list_store_set (GTK_LIST_STORE (model), &iter, j, FALSE, -1);
|
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);
|
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) {
|
if (n_columns == 0) {
|
||||||
g_printerr (_("No column titles specified for List dialog.\n"));
|
g_printerr (_("No column titles specified for List dialog.\n"));
|
||||||
data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR);
|
data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR);
|
||||||
@ -454,28 +465,61 @@ static void
|
|||||||
zenity_tree_dialog_get_selected (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, };
|
GValue value = {0, };
|
||||||
|
gint n_columns, i;
|
||||||
|
|
||||||
gtk_tree_model_get_value (model, iter, 0, &value);
|
n_columns = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tree_view), "n_columns"));
|
||||||
|
|
||||||
|
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)));
|
selected = g_slist_append (selected, g_strdup (g_value_get_string (&value)));
|
||||||
g_value_unset (&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
|
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, };
|
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);
|
gtk_tree_model_get_value (model, iter, 0, &toggle_value);
|
||||||
|
|
||||||
if (g_value_get_boolean (&toggle_value)) {
|
if (g_value_get_boolean (&toggle_value)) {
|
||||||
GValue value = {0, };
|
GValue value = {0, };
|
||||||
gtk_tree_model_get_value (model, iter, 1, &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)));
|
selected = g_slist_append (selected, g_strdup (g_value_get_string (&value)));
|
||||||
g_value_unset (&value);
|
g_value_unset (&value);
|
||||||
}
|
}
|
||||||
g_value_unset (&toggle_value);
|
g_value_unset (&toggle_value);
|
||||||
return FALSE;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -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));
|
model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view));
|
||||||
|
|
||||||
if (gtk_tree_model_get_column_type (model, 0) == G_TYPE_BOOLEAN)
|
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 {
|
else {
|
||||||
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));
|
||||||
gtk_tree_selection_selected_foreach (selection,
|
gtk_tree_selection_selected_foreach (selection,
|
||||||
|
@ -92,6 +92,7 @@ typedef struct {
|
|||||||
gboolean radiobox;
|
gboolean radiobox;
|
||||||
gchar *separator;
|
gchar *separator;
|
||||||
gboolean editable;
|
gboolean editable;
|
||||||
|
gchar *print_column;
|
||||||
const gchar **data;
|
const gchar **data;
|
||||||
} ZenityTreeData;
|
} ZenityTreeData;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user