New --print-column syntax. Now it's possible to pass a comma-separated list of column indexes.

This commit is contained in:
Lucas Almeida Rocha 2005-06-28 11:11:50 +00:00
parent cc3fc2be3e
commit c9be8d0579
2 changed files with 44 additions and 22 deletions

View File

@ -1,3 +1,9 @@
2005-06-28 Lucas Rocha <lucasr@cvs.gnome.org>
* src/tree.c: new --print-column option syntax.
Now it's possible to pass a comma-separated list
of column indexes (i.e. --print-column=1,3,4)
2005-06-28 Lucas Rocha <lucasr@cvs.gnome.org> 2005-06-28 Lucas Rocha <lucasr@cvs.gnome.org>
* src/tree.c: error handling when trying to * src/tree.c: error handling when trying to

View File

@ -30,12 +30,13 @@
#include "util.h" #include "util.h"
#define MAX_ELEMENTS_BEFORE_SCROLLING 5 #define MAX_ELEMENTS_BEFORE_SCROLLING 5
#define PRINT_HIDE_COLUMN_SEPARATOR ","
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 gboolean print_all_columns = FALSE;
static gint print_column_n = 1; static char **print_columns = NULL;
static void zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer data); static void zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer data);
static void zenity_tree_row_activated (GtkTreeView *tree_view, GtkTreePath *tree_path, static void zenity_tree_row_activated (GtkTreeView *tree_view, GtkTreePath *tree_path,
@ -299,7 +300,13 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data)
if (strcmp (g_strdown (tree_data->print_column), "all") == 0) if (strcmp (g_strdown (tree_data->print_column), "all") == 0)
print_all_columns = TRUE; print_all_columns = TRUE;
else else
print_column_n = atoi (tree_data->print_column); print_columns = g_strsplit (tree_data->print_column,
PRINT_HIDE_COLUMN_SEPARATOR, 0);
}
else {
print_columns = (char **) g_new (char**, 2);
print_columns[0] = g_strdup ("1");
print_columns[1] = NULL;
} }
if (n_columns == 0) { if (n_columns == 0) {
@ -484,7 +491,7 @@ 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; gint n_columns, print_column, i;
n_columns = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tree_view), "n_columns")); n_columns = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tree_view), "n_columns"));
@ -498,19 +505,23 @@ zenity_tree_dialog_get_selected (GtkTreeModel *model, GtkTreePath *path_buf, Gtk
return; return;
} }
if (print_column_n > 0 && print_column_n <= n_columns) { for (i = 0; print_columns[i] != NULL; i++) {
gtk_tree_model_get_value (model, iter, print_column_n - 1, &value); print_column = atoi (print_columns[i]);
if (print_column > 0 && print_column <= n_columns) {
gtk_tree_model_get_value (model, iter, print_column - 1, &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);
} }
}
} }
static gboolean static gboolean
zenity_tree_dialog_toggle_get_selected (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, GtkTreeView *tree_view) 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; gint n_columns, print_column, i;
n_columns = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tree_view), "n_columns")); n_columns = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tree_view), "n_columns"));
@ -530,13 +541,17 @@ zenity_tree_dialog_toggle_get_selected (GtkTreeModel *model, GtkTreePath *path,
return FALSE; return FALSE;
} }
if (print_column_n > 0 && print_column_n <= n_columns) { for (i = 0; print_columns[i] != NULL; i++) {
gtk_tree_model_get_value (model, iter, print_column_n, &value); print_column = atoi (print_columns[i]);
if (print_column > 0 && print_column <= n_columns) {
gtk_tree_model_get_value (model, iter, print_column, &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;
} }
@ -554,6 +569,7 @@ zenity_tree_dialog_output (void)
g_print ("%s\n", (gchar *) tmp->data); g_print ("%s\n", (gchar *) tmp->data);
} }
g_strfreev (print_columns);
g_free (separator); g_free (separator);
g_slist_foreach (selected, (GFunc) g_free, NULL); g_slist_foreach (selected, (GFunc) g_free, NULL);
selected = NULL; selected = NULL;