From d88a32f1f5418e97b5840087a21652f68ac938c8 Mon Sep 17 00:00:00 2001 From: Glynn Foster Date: Mon, 6 Jan 2003 21:58:21 +0000 Subject: Finish off commandline parsing for the list dialog. Wow, this is almost 2003-01-06 Glynn Foster * src/main.c, src/tree.c, src/zenity.h: Finish off commandline parsing for the list dialog. Wow, this is almost approaching usable ;) * TODO: Update accordingly --- ChangeLog | 8 ++++++++ TODO | 1 - src/main.c | 2 ++ src/tree.c | 40 +++++++++++++++++++++++++++------------- src/zenity.h | 1 + 5 files changed, 38 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index cc847cb..b981d01 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2003-01-06 Glynn Foster + + * src/main.c, src/tree.c, src/zenity.h: Finish off + commandline parsing for the list dialog. Wow, this + is almost approaching usable ;) + + * TODO: Update accordingly + 2003-01-06 Glynn Foster * src/main.c, src/msg.c, src/zenity.glade, diff --git a/TODO b/TODO index 51a9c68..52553b0 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,3 @@ -* Finish off commandline support for list dialog * Finish off support for progress dialog * Implement error/return values for all dialogs * Add some accessibility I guess diff --git a/src/main.c b/src/main.c index 334c20d..86f4aaa 100644 --- a/src/main.c +++ b/src/main.c @@ -735,6 +735,7 @@ zenity_free_parsing_options (void) { gint main (gint argc, gchar **argv) { + char **args; poptContext ctx; int nextopt; ZenityData *general; @@ -781,6 +782,7 @@ main (gint argc, gchar **argv) { zenity_fileselection (results->data, results->file_data); break; case MODE_LIST: + results->tree_data->data = poptGetArgs (ctx); zenity_tree (results->data, results->tree_data); break; case MODE_PROGRESS: diff --git a/src/tree.c b/src/tree.c index 6e8709c..9308ab7 100644 --- a/src/tree.c +++ b/src/tree.c @@ -63,21 +63,32 @@ count_rows_foreach (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, g } static void -zenity_tree_fill_entries (GtkTreeView *tree_view, const **argv) +zenity_tree_fill_entries (GtkTreeView *tree_view, gchar **args, gint n_columns, gboolean toggles) { GtkTreeModel *model; GtkTreeIter iter; gint i = 0; model = gtk_tree_view_get_model (tree_view); - gtk_tree_model_foreach (model, count_rows_foreach, &i); + /* gtk_tree_model_foreach (model, count_rows_foreach, &i); */ + + while (args[i] != NULL) { + gint j; - while (i<10) { gtk_list_store_append (GTK_LIST_STORE (model), &iter); - gtk_list_store_set (GTK_LIST_STORE (model), &iter, - 0, "TRUE", - 1, "This is the bar above foobar", -1); + for (j = 0; j < n_columns; j++) { + + if (toggles && j == 0) { + if (strcmp (args[i+j], "TRUE") == 0 || 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); + } + else + gtk_list_store_set (GTK_LIST_STORE (model), &iter, j, args[i+j], -1); + } + if (i == MAX_ELEMENTS_BEFORE_SCROLLING) { GtkWidget *scrolled_window; GtkRequisition rectangle; @@ -88,8 +99,8 @@ zenity_tree_fill_entries (GtkTreeView *tree_view, const **argv) gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); } + i += n_columns; - i++; } } @@ -103,7 +114,7 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) GType *column_types; GSList *tmp; gboolean first_column = FALSE; - gint i, column_index, column_n; + gint i, column_index, n_columns; glade_dialog = zenity_util_load_glade_file ("zenity_tree_dialog"); @@ -124,14 +135,14 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) tree_view = glade_xml_get_widget (glade_dialog, "zenity_tree_view"); - column_n = g_slist_length (tree_data->columns); + n_columns = g_slist_length (tree_data->columns); /* Create an empty list store */ model = g_object_new (GTK_TYPE_LIST_STORE, NULL); - column_types = g_new (GType, column_n); + column_types = g_new (GType, n_columns); - for (i = 0; i < column_n; i++) { + for (i = 0; i < n_columns; i++) { /* Have the limitation that the radioboxes and checkboxes are in the first column */ if (i == 0 && (tree_data->checkbox || tree_data->radiobox)) column_types[i] = G_TYPE_BOOLEAN; @@ -139,7 +150,7 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) column_types[i] = G_TYPE_STRING; } - gtk_list_store_set_column_types (model, column_n, column_types); + gtk_list_store_set_column_types (model, n_columns, column_types); gtk_tree_view_set_model (GTK_TREE_VIEW (tree_view), GTK_TREE_MODEL (model)); @@ -188,7 +199,10 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (tree_view), TRUE); - /* zenity_tree_fill_entries (GTK_TREE_VIEW (tree_view), NULL); */ + if (tree_data->radiobox || tree_data->checkbox) + zenity_tree_fill_entries (GTK_TREE_VIEW (tree_view), tree_data->data, n_columns, TRUE); + else + zenity_tree_fill_entries (GTK_TREE_VIEW (tree_view), tree_data->data, n_columns, FALSE); gtk_widget_show (dialog); gtk_main (); diff --git a/src/zenity.h b/src/zenity.h index 897857f..697a17c 100644 --- a/src/zenity.h +++ b/src/zenity.h @@ -73,6 +73,7 @@ typedef struct { GSList *columns; gboolean checkbox; gboolean radiobox; + gchar **data; } ZenityTreeData; int zenity_calendar (ZenityData *data, -- cgit v1.2.3-2-g168b