From 48c1564ac5ef431e9111606e40488d04a96f3059 Mon Sep 17 00:00:00 2001 From: Glynn Foster Date: Fri, 3 Jan 2003 13:26:04 +0000 Subject: Initial revision --- src/tree.c | 208 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 208 insertions(+) create mode 100644 src/tree.c (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c new file mode 100644 index 00000000..c5eef5a4 --- /dev/null +++ b/src/tree.c @@ -0,0 +1,208 @@ +/* + * tree.c + * + * Copyright (C) 2002 Sun Microsystems, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Authors: Glynn Foster + * Jonathan Blanford + * Kristian Rietveld + */ + +#include +#include "zenity.h" +#include "util.h" + +#define MAX_ELEMENTS_BEFORE_SCROLLING 8 + +static GladeXML *glade_dialog; + +enum +{ + NAME_COLUMN, + DESCRIPTION_COLUMN, + N_COLUMNS +}; + +void zenity_tree_dialog_response (GtkWindow *window, int button, gpointer data); + +static void +zenity_tree_toggled_callback (GtkCellRendererToggle *cell, gchar *path_string, gpointer data) +{ + GtkTreeModel *model; + GtkTreeIter iter; + GtkTreePath *path; + gboolean value; + + model = GTK_TREE_MODEL (data); + path = gtk_tree_path_new_from_string (path_string); + + gtk_tree_model_get_iter (model, &iter, path); + gtk_tree_model_get (model, &iter, NAME_COLUMN, &value, -1); + + value = !value; + gtk_list_store_set (GTK_LIST_STORE (model), &iter, NAME_COLUMN, value, -1); + + gtk_tree_path_free (path); +} + +static gboolean +count_rows_foreach (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data) +{ + gint *rows = data; + + (*rows)++; + return FALSE; +} + +static void +zenity_tree_fill_entries (GtkTreeView *tree_view, const **argv) +{ + GtkTreeModel *model; + GtkTreeIter iter; + gint i = 0; + + model = gtk_tree_view_get_model (tree_view); + gtk_tree_model_foreach (model, count_rows_foreach, &i); + + while (i<10) { + gtk_list_store_append (GTK_LIST_STORE (model), &iter); + gtk_list_store_set (GTK_LIST_STORE (model), &iter, + NAME_COLUMN, "TRUE", + DESCRIPTION_COLUMN, "This is the bar above foobar", + -1); + + if (i == MAX_ELEMENTS_BEFORE_SCROLLING) { + GtkWidget *scrolled_window; + GtkRequisition rectangle; + + gtk_widget_size_request (GTK_WIDGET (tree_view), &rectangle); + scrolled_window = glade_xml_get_widget (glade_dialog, "zenity_tree_window"); + gtk_widget_set_size_request (scrolled_window, -1, rectangle.height); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), + GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); + } + i++; + } +} + +int +zenity_tree (ZenityData *data, ZenityTreeData *tree_data) +{ + GtkWidget *dialog; + GtkWidget *tree_view; + GtkTreeViewColumn *column; + GtkListStore *model; + + glade_dialog = zenity_util_load_glade_file ("zenity_tree_dialog"); + + if (glade_dialog == NULL) + return FALSE; + + glade_xml_signal_autoconnect (glade_dialog); + + dialog = glade_xml_get_widget (glade_dialog, "zenity_tree_dialog"); + + if (data->dialog_title) + gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title); + + if (data->window_icon) + zenity_util_set_window_icon (dialog, data->window_icon); + else + zenity_util_set_window_icon (dialog, ZENITY_IMAGE_FULLPATH ("zenity-list.png")); + + tree_view = glade_xml_get_widget (glade_dialog, "zenity_tree_view"); + + if (tree_data->checkbox || tree_data->radiobox) + model = gtk_list_store_new (N_COLUMNS, G_TYPE_BOOLEAN, G_TYPE_STRING); + else + model = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING); + + gtk_tree_view_set_model (GTK_TREE_VIEW (tree_view), GTK_TREE_MODEL (model)); + + if (tree_data->checkbox) { + GtkCellRenderer *cell_renderer; + + cell_renderer = gtk_cell_renderer_toggle_new (); + g_signal_connect (cell_renderer, "toggled", + G_CALLBACK (zenity_tree_toggled_callback), model); + + column = gtk_tree_view_column_new_with_attributes (NULL, + cell_renderer, + "active", NAME_COLUMN, NULL); + } + else if (tree_data->radiobox) { + GtkCellRenderer *cell_renderer; + + cell_renderer = gtk_cell_renderer_toggle_new (); + g_object_set (G_OBJECT (cell_renderer), "radio", TRUE, NULL); + g_signal_connect (cell_renderer, "toggled", + G_CALLBACK (zenity_tree_toggled_callback), model); + + column = gtk_tree_view_column_new_with_attributes (NULL, + cell_renderer, + "active", NAME_COLUMN, NULL); + + } + else { + column = gtk_tree_view_column_new_with_attributes (tree_data->column_one_header, + gtk_cell_renderer_text_new (), + "text", NAME_COLUMN, NULL); + gtk_tree_view_column_set_sort_column_id (column, NAME_COLUMN); + } + + gtk_tree_view_column_set_resizable (column, TRUE); + gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column); + + column = gtk_tree_view_column_new_with_attributes (tree_data->column_two_header, + gtk_cell_renderer_text_new (), + "text", DESCRIPTION_COLUMN, NULL); + gtk_tree_view_column_set_sort_column_id (column, DESCRIPTION_COLUMN); + gtk_tree_view_column_set_resizable (column, TRUE); + gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column); + + gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (tree_view), TRUE); + + zenity_tree_fill_entries (GTK_TREE_VIEW (tree_view), NULL); + + gtk_widget_show (dialog); + gtk_main (); + + if (glade_dialog) + g_object_unref (glade_dialog); + + return TRUE; +} + +void +zenity_tree_dialog_response (GtkWindow *window, int button, gpointer data) +{ + GError *error = NULL; + + switch (button) { + case GTK_RESPONSE_OK: + gtk_main_quit (); + break; + + case GTK_RESPONSE_CANCEL: + gtk_main_quit (); + break; + + default: + break; + } +} -- cgit From 344345d9aa262940fedfb8beed9dc0c9bb163a10 Mon Sep 17 00:00:00 2001 From: Glynn Foster Date: Mon, 6 Jan 2003 15:06:17 +0000 Subject: Add functions to init and free the parsing options. Still not terribly 2003-01-06 Glynn Foster * src/main.c: Add functions to init and free the parsing options. Still not terribly pretty though. * src/tree.c, src/zenity.h: Handle --column argument. * TODO: Update accordingly. --- src/tree.c | 143 +++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 77 insertions(+), 66 deletions(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index c5eef5a4..6e8709ce 100644 --- a/src/tree.c +++ b/src/tree.c @@ -31,13 +31,6 @@ static GladeXML *glade_dialog; -enum -{ - NAME_COLUMN, - DESCRIPTION_COLUMN, - N_COLUMNS -}; - void zenity_tree_dialog_response (GtkWindow *window, int button, gpointer data); static void @@ -52,10 +45,10 @@ zenity_tree_toggled_callback (GtkCellRendererToggle *cell, gchar *path_string, g path = gtk_tree_path_new_from_string (path_string); gtk_tree_model_get_iter (model, &iter, path); - gtk_tree_model_get (model, &iter, NAME_COLUMN, &value, -1); + gtk_tree_model_get (model, &iter, 0, &value, -1); value = !value; - gtk_list_store_set (GTK_LIST_STORE (model), &iter, NAME_COLUMN, value, -1); + gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, value, -1); gtk_tree_path_free (path); } @@ -80,23 +73,23 @@ zenity_tree_fill_entries (GtkTreeView *tree_view, const **argv) gtk_tree_model_foreach (model, count_rows_foreach, &i); while (i<10) { - gtk_list_store_append (GTK_LIST_STORE (model), &iter); - gtk_list_store_set (GTK_LIST_STORE (model), &iter, - NAME_COLUMN, "TRUE", - DESCRIPTION_COLUMN, "This is the bar above foobar", - -1); - - if (i == MAX_ELEMENTS_BEFORE_SCROLLING) { - GtkWidget *scrolled_window; - GtkRequisition rectangle; - - gtk_widget_size_request (GTK_WIDGET (tree_view), &rectangle); - scrolled_window = glade_xml_get_widget (glade_dialog, "zenity_tree_window"); - gtk_widget_set_size_request (scrolled_window, -1, rectangle.height); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), - GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); - } - i++; + 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); + + if (i == MAX_ELEMENTS_BEFORE_SCROLLING) { + GtkWidget *scrolled_window; + GtkRequisition rectangle; + + gtk_widget_size_request (GTK_WIDGET (tree_view), &rectangle); + scrolled_window = glade_xml_get_widget (glade_dialog, "zenity_tree_window"); + gtk_widget_set_size_request (scrolled_window, -1, rectangle.height); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), + GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); + } + + i++; } } @@ -107,6 +100,10 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) GtkWidget *tree_view; GtkTreeViewColumn *column; GtkListStore *model; + GType *column_types; + GSList *tmp; + gboolean first_column = FALSE; + gint i, column_index, column_n; glade_dialog = zenity_util_load_glade_file ("zenity_tree_dialog"); @@ -127,57 +124,71 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) tree_view = glade_xml_get_widget (glade_dialog, "zenity_tree_view"); - if (tree_data->checkbox || tree_data->radiobox) - model = gtk_list_store_new (N_COLUMNS, G_TYPE_BOOLEAN, G_TYPE_STRING); - else - model = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING); - - gtk_tree_view_set_model (GTK_TREE_VIEW (tree_view), GTK_TREE_MODEL (model)); + column_n = g_slist_length (tree_data->columns); - if (tree_data->checkbox) { - GtkCellRenderer *cell_renderer; + /* Create an empty list store */ + model = g_object_new (GTK_TYPE_LIST_STORE, NULL); - cell_renderer = gtk_cell_renderer_toggle_new (); - g_signal_connect (cell_renderer, "toggled", - G_CALLBACK (zenity_tree_toggled_callback), model); + column_types = g_new (GType, column_n); - column = gtk_tree_view_column_new_with_attributes (NULL, - cell_renderer, - "active", NAME_COLUMN, NULL); + for (i = 0; i < column_n; 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; + else + column_types[i] = G_TYPE_STRING; } - else if (tree_data->radiobox) { - GtkCellRenderer *cell_renderer; - cell_renderer = gtk_cell_renderer_toggle_new (); - g_object_set (G_OBJECT (cell_renderer), "radio", TRUE, NULL); - g_signal_connect (cell_renderer, "toggled", - G_CALLBACK (zenity_tree_toggled_callback), model); + gtk_list_store_set_column_types (model, column_n, column_types); - column = gtk_tree_view_column_new_with_attributes (NULL, - cell_renderer, - "active", NAME_COLUMN, NULL); - - } - else { - column = gtk_tree_view_column_new_with_attributes (tree_data->column_one_header, - gtk_cell_renderer_text_new (), - "text", NAME_COLUMN, NULL); - gtk_tree_view_column_set_sort_column_id (column, NAME_COLUMN); - } + gtk_tree_view_set_model (GTK_TREE_VIEW (tree_view), GTK_TREE_MODEL (model)); - gtk_tree_view_column_set_resizable (column, TRUE); - gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column); + column_index = 0; + + for (tmp = tree_data->columns; tmp; tmp = tmp->next) { + if (first_column == FALSE) { + if (tree_data->checkbox || tree_data->radiobox) { + GtkCellRenderer *cell_renderer; + + cell_renderer = gtk_cell_renderer_toggle_new (); + + if (tree_data->radiobox) + g_object_set (G_OBJECT (cell_renderer), "radio", TRUE, NULL); + + g_signal_connect (cell_renderer, "toggled", + G_CALLBACK (zenity_tree_toggled_callback), model); + + column = gtk_tree_view_column_new_with_attributes (tmp->data, + cell_renderer, + "active", column_index, NULL); + } + + else { + column = gtk_tree_view_column_new_with_attributes (tmp->data, + gtk_cell_renderer_text_new (), + "text", column_index, NULL); + gtk_tree_view_column_set_sort_column_id (column, column_index); + gtk_tree_view_column_set_resizable (column, TRUE); + } + + first_column = TRUE; + } + else { + column = gtk_tree_view_column_new_with_attributes (tmp->data, + gtk_cell_renderer_text_new (), + "text", column_index, NULL); + gtk_tree_view_column_set_sort_column_id (column, column_index); + gtk_tree_view_column_set_resizable (column, TRUE); + + } - column = gtk_tree_view_column_new_with_attributes (tree_data->column_two_header, - gtk_cell_renderer_text_new (), - "text", DESCRIPTION_COLUMN, NULL); - gtk_tree_view_column_set_sort_column_id (column, DESCRIPTION_COLUMN); - gtk_tree_view_column_set_resizable (column, TRUE); - gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column); + gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column); + column_index++; + } gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (tree_view), TRUE); - zenity_tree_fill_entries (GTK_TREE_VIEW (tree_view), NULL); + /* zenity_tree_fill_entries (GTK_TREE_VIEW (tree_view), NULL); */ gtk_widget_show (dialog); gtk_main (); -- cgit 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 --- src/tree.c | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index 6e8709ce..9308ab71 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 (); -- cgit From a8c3006035a068069ed9199400472332db540bb5 Mon Sep 17 00:00:00 2001 From: Glynn Foster Date: Tue, 7 Jan 2003 00:01:00 +0000 Subject: Improve error handling... a lot. 2003-01-06 Glynn Foster * src/calendar.c, src/main.c, src/progress.c, src/tree.c, src/zenity.h: Improve error handling... a lot. --- src/tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index 9308ab71..01be45cd 100644 --- a/src/tree.c +++ b/src/tree.c @@ -63,7 +63,7 @@ count_rows_foreach (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, g } static void -zenity_tree_fill_entries (GtkTreeView *tree_view, gchar **args, gint n_columns, gboolean toggles) +zenity_tree_fill_entries (GtkTreeView *tree_view, const gchar **args, gint n_columns, gboolean toggles) { GtkTreeModel *model; GtkTreeIter iter; -- cgit From 6a65d75921d352323277f770f357ca3065436133 Mon Sep 17 00:00:00 2001 From: Glynn Foster Date: Tue, 7 Jan 2003 13:22:57 +0000 Subject: Fix up the response signal handlers. Use returns of 0 for 'Ok' and 2003-01-07 Glynn Foster * src/calendar.c, src/entry.c, src/fileselection.c, src/main.c, src/msg.c, src/progress.c, src/text.c, src/tree.c, src/zenity.glade, src/zenity.h: Fix up the response signal handlers. Use returns of 0 for 'Ok' and 'Close', 1 for 'Cancel' and 'Escape' and -1 for 'Uh Oh'. Get stuff printing to stderr. Fix up the error handling that I thought was improved, although still have issues with popt callback getting called numerous times because of more than one instance of the same kind is being used in poptOption. * TODO: Update accordingly. --- src/tree.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index 01be45cd..401fbe00 100644 --- a/src/tree.c +++ b/src/tree.c @@ -31,7 +31,7 @@ static GladeXML *glade_dialog; -void zenity_tree_dialog_response (GtkWindow *window, int button, gpointer data); +static void zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer data); static void zenity_tree_toggled_callback (GtkCellRendererToggle *cell, gchar *path_string, gpointer data) @@ -104,7 +104,7 @@ zenity_tree_fill_entries (GtkTreeView *tree_view, const gchar **args, gint n_col } } -int +void zenity_tree (ZenityData *data, ZenityTreeData *tree_data) { GtkWidget *dialog; @@ -118,13 +118,18 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) glade_dialog = zenity_util_load_glade_file ("zenity_tree_dialog"); - if (glade_dialog == NULL) - return FALSE; + if (glade_dialog == NULL) { + data->exit_code = -1; + return; + } glade_xml_signal_autoconnect (glade_dialog); dialog = glade_xml_get_widget (glade_dialog, "zenity_tree_dialog"); + g_signal_connect (G_OBJECT (dialog), "response", + G_CALLBACK (zenity_tree_dialog_response), data); + if (data->dialog_title) gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title); @@ -209,25 +214,26 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) if (glade_dialog) g_object_unref (glade_dialog); - - return TRUE; } -void -zenity_tree_dialog_response (GtkWindow *window, int button, gpointer data) +static void +zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer data) { - GError *error = NULL; + ZenityData *zen_data = data; - switch (button) { + switch (response) { case GTK_RESPONSE_OK: + zen_data->exit_code = 0; gtk_main_quit (); break; case GTK_RESPONSE_CANCEL: + zen_data->exit_code = 1; gtk_main_quit (); break; default: + zen_data->exit_code = 1; break; } } -- cgit From 69636459e1faf1ce41685550cf7aec59acfbac39 Mon Sep 17 00:00:00 2001 From: Glynn Foster Date: Mon, 13 Jan 2003 16:48:45 +0000 Subject: Improve error handling. Make --list actually return something useful, 2003-01-13 Glynn Foster * src/main.c: Improve error handling. * src/tree.c: Make --list actually return something useful, although I still need to actually seperate things out so it's actually decipherable. * TODO: Update accordingly. --- src/tree.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 53 insertions(+), 12 deletions(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index 401fbe00..2b310023 100644 --- a/src/tree.c +++ b/src/tree.c @@ -53,15 +53,6 @@ zenity_tree_toggled_callback (GtkCellRendererToggle *cell, gchar *path_string, g gtk_tree_path_free (path); } -static gboolean -count_rows_foreach (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data) -{ - gint *rows = data; - - (*rows)++; - return FALSE; -} - static void zenity_tree_fill_entries (GtkTreeView *tree_view, const gchar **args, gint n_columns, gboolean toggles) { @@ -70,7 +61,6 @@ zenity_tree_fill_entries (GtkTreeView *tree_view, const gchar **args, gint n_col gint i = 0; model = gtk_tree_view_get_model (tree_view); - /* gtk_tree_model_foreach (model, count_rows_foreach, &i); */ while (args[i] != NULL) { gint j; @@ -123,6 +113,14 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) return; } + n_columns = g_slist_length (tree_data->columns); + + if (n_columns == 0) { + g_printerr (_("No column titles specified for --list\n")); + data->exit_code = -1; + return; + } + glade_xml_signal_autoconnect (glade_dialog); dialog = glade_xml_get_widget (glade_dialog, "zenity_tree_dialog"); @@ -140,8 +138,6 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) tree_view = glade_xml_get_widget (glade_dialog, "zenity_tree_view"); - n_columns = g_slist_length (tree_data->columns); - /* Create an empty list store */ model = g_object_new (GTK_TYPE_LIST_STORE, NULL); @@ -216,13 +212,58 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) g_object_unref (glade_dialog); } +static void +zenity_tree_dialog_output (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)); + g_value_unset (&value); +} + +static gboolean +zenity_tree_dialog_toggle_output (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data) +{ + GValue toggle_value = {0, }; + + gtk_tree_model_get_value (model, iter, 0, &toggle_value); + + 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)); + g_value_unset (&value); + } + g_value_unset (&toggle_value); + return FALSE; +} + static void zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer data) { ZenityData *zen_data = data; + GtkWidget *tree_view; + GtkTreeSelection *selection; + GtkTreeModel *model; switch (response) { case GTK_RESPONSE_OK: + tree_view = glade_xml_get_widget (glade_dialog, "zenity_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) { + gtk_tree_model_foreach (model, + (GtkTreeModelForeachFunc) zenity_tree_dialog_toggle_output, + NULL); + } + else { + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)); + gtk_tree_selection_selected_foreach (selection, + (GtkTreeSelectionForeachFunc) zenity_tree_dialog_output, + GTK_TREE_VIEW (tree_view)); + } zen_data->exit_code = 0; gtk_main_quit (); break; -- cgit From f00eb34c0604dcf68457ab09278295f647c622b8 Mon Sep 17 00:00:00 2001 From: Glynn Foster Date: Tue, 14 Jan 2003 01:52:23 +0000 Subject: Add support to separate the selected rows output with a character with '/' 2003-01-14 Glynn Foster * src/tree.c, src/zenity.h, src/main.c: Add support to separate the selected rows output with a character with '/' used by default. --- src/tree.c | 45 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index 2b310023..29b38c66 100644 --- a/src/tree.c +++ b/src/tree.c @@ -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); @@ -112,7 +114,9 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) data->exit_code = -1; 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; -- cgit From 0e338ba3e0fa03b28664448af0cea686c5e6c26d Mon Sep 17 00:00:00 2001 From: Mike Newman Date: Fri, 17 Jan 2003 07:46:11 +0000 Subject: Fix a segfault in the --list if no data is supplied to populate the tree. --- src/tree.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index 29b38c66..c19b1804 100644 --- a/src/tree.c +++ b/src/tree.c @@ -124,7 +124,13 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) data->exit_code = -1; return; } - + + if (tree_data->data == NULL) { + g_printerr (_("No contents specified for --list\n")); + data->exit_code = -1; + return; + } + glade_xml_signal_autoconnect (glade_dialog); dialog = glade_xml_get_widget (glade_dialog, "zenity_tree_dialog"); -- cgit From 22625f8b16e1dc38be50cc2e869780b74e7f6891 Mon Sep 17 00:00:00 2001 From: Glynn Foster Date: Tue, 28 Jan 2003 14:58:30 +0000 Subject: Don't display the translators tab unless there is stuff to show. 2003-01-28 Glynn Foster * src/about.c: Don't display the translators tab unless there is stuff to show. * src/entry.c: Add sanity NULL checking. * src/tree.c, src/zenity.h: Add support for a new --editable option. * src/main.c: Add support for new --editable option for the List dialog. Merge in the list of Gtk+ options into the popt table - ripped this from libbonoboui, thanks to James for pointing this out. * src/zenity.glade: Make the translatable strings less arse. * TODO: Update accordingly. --- src/tree.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 88 insertions(+), 14 deletions(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index c19b1804..e5573fff 100644 --- a/src/tree.c +++ b/src/tree.c @@ -24,6 +24,7 @@ */ #include +#include #include "zenity.h" #include "util.h" @@ -56,7 +57,7 @@ zenity_tree_toggled_callback (GtkCellRendererToggle *cell, gchar *path_string, g } static void -zenity_tree_fill_entries (GtkTreeView *tree_view, const gchar **args, gint n_columns, gboolean toggles) +zenity_tree_fill_entries (GtkTreeView *tree_view, const gchar **args, gint n_columns, gboolean toggles, gboolean editable) { GtkTreeModel *model; GtkTreeIter iter; @@ -80,7 +81,10 @@ zenity_tree_fill_entries (GtkTreeView *tree_view, const gchar **args, gint n_col else gtk_list_store_set (GTK_LIST_STORE (model), &iter, j, args[i+j], -1); } - + + if (editable) + gtk_list_store_set (GTK_LIST_STORE (model), &iter, n_columns, TRUE, -1); + if (i == MAX_ELEMENTS_BEFORE_SCROLLING) { GtkWidget *scrolled_window; GtkRequisition rectangle; @@ -96,6 +100,26 @@ zenity_tree_fill_entries (GtkTreeView *tree_view, const gchar **args, gint n_col } } +static void +zenity_cell_edited_callback (GtkCellRendererText *cell, const gchar *path_string, const gchar *new_text, gpointer data) +{ + GtkTreeModel *model; + GtkTreePath *path; + GtkTreeIter iter; + gint column; + + model = GTK_TREE_MODEL (data); + path = gtk_tree_path_new_from_string (path_string); + + column = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (cell), "column")); + gtk_tree_model_get_iter (model, &iter, path); + + gtk_list_store_set (GTK_LIST_STORE (model), &iter, + column, new_text, -1); + + gtk_tree_path_free (path); +} + void zenity_tree (ZenityData *data, ZenityTreeData *tree_data) { @@ -151,7 +175,10 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) /* Create an empty list store */ model = g_object_new (GTK_TYPE_LIST_STORE, NULL); - column_types = g_new (GType, n_columns); + if (tree_data->editable) + column_types = g_new (GType, n_columns + 1); + else + column_types = g_new (GType, n_columns); for (i = 0; i < n_columns; i++) { /* Have the limitation that the radioboxes and checkboxes are in the first column */ @@ -161,10 +188,19 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) column_types[i] = G_TYPE_STRING; } - gtk_list_store_set_column_types (model, n_columns, column_types); + if (tree_data->editable) + column_types[n_columns] = G_TYPE_BOOLEAN; + + if (tree_data->editable) + gtk_list_store_set_column_types (model, n_columns + 1, column_types); + else + 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)); + gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)), + GTK_SELECTION_MULTIPLE); + column_index = 0; for (tmp = tree_data->columns; tmp; tmp = tmp->next) { @@ -186,9 +222,28 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) } else { - column = gtk_tree_view_column_new_with_attributes (tmp->data, - gtk_cell_renderer_text_new (), - "text", column_index, NULL); + if (tree_data->editable == TRUE) { + GtkCellRenderer *cell_renderer; + + cell_renderer = gtk_cell_renderer_text_new (); + g_signal_connect (G_OBJECT (cell_renderer), "edited", + G_CALLBACK (zenity_cell_edited_callback), + gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view))); + g_object_set_data (G_OBJECT (cell_renderer), "column", + (gint *) column_index); + + column = gtk_tree_view_column_new_with_attributes (tmp->data, + cell_renderer, + "text", column_index, + "editable", n_columns, + NULL); + } + else { + column = gtk_tree_view_column_new_with_attributes (tmp->data, + gtk_cell_renderer_text_new (), + "text", column_index, NULL); + } + gtk_tree_view_column_set_sort_column_id (column, column_index); gtk_tree_view_column_set_resizable (column, TRUE); } @@ -196,9 +251,28 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) first_column = TRUE; } else { - column = gtk_tree_view_column_new_with_attributes (tmp->data, - gtk_cell_renderer_text_new (), - "text", column_index, NULL); + if (tree_data->editable == TRUE) { + GtkCellRenderer *cell_renderer; + + cell_renderer = gtk_cell_renderer_text_new (); + g_signal_connect (G_OBJECT (cell_renderer), "edited", + G_CALLBACK (zenity_cell_edited_callback), + gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view))); + g_object_set_data (G_OBJECT (cell_renderer), "column", + (gint *) column_index); + + column = gtk_tree_view_column_new_with_attributes (tmp->data, + cell_renderer, + "text", column_index, + "editable", n_columns, + NULL); + } + else { + column = gtk_tree_view_column_new_with_attributes (tmp->data, + gtk_cell_renderer_text_new (), + "text", column_index, NULL); + } + gtk_tree_view_column_set_sort_column_id (column, column_index); gtk_tree_view_column_set_resizable (column, TRUE); @@ -211,9 +285,9 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (tree_view), TRUE); if (tree_data->radiobox || tree_data->checkbox) - zenity_tree_fill_entries (GTK_TREE_VIEW (tree_view), tree_data->data, n_columns, TRUE); + zenity_tree_fill_entries (GTK_TREE_VIEW (tree_view), tree_data->data, n_columns, TRUE, tree_data->editable); else - zenity_tree_fill_entries (GTK_TREE_VIEW (tree_view), tree_data->data, n_columns, FALSE); + zenity_tree_fill_entries (GTK_TREE_VIEW (tree_view), tree_data->data, n_columns, FALSE, tree_data->editable); gtk_widget_show (dialog); gtk_main (); @@ -258,9 +332,9 @@ zenity_tree_dialog_output (void) 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) + if (strstr ((const gchar *) separator, (const gchar *) "\\n") != NULL) g_printerr ("%s\n", tmp->data); - else if (strstr (separator, "\\t") != NULL) + else if (strstr ((const gchar *) separator, (const gchar *) "\\t") != NULL) g_printerr ("%s\t", tmp->data); else g_printerr ("%s%s", tmp->data, separator); -- cgit From 49f89795349a47ae4e061666d84a715bf24f5373 Mon Sep 17 00:00:00 2001 From: Glynn Foster Date: Mon, 10 Mar 2003 17:11:18 +0000 Subject: Mass indentation cleanup. Make sure the glade dialogs aren't initially 2003-03-10 Glynn Foster * src/about.c, src/calendar.c, src/entry.c, src/fileselection.c, src/main.c, src/msg.c, src/progress.c, src/text.c, src/tree.c, src/util.c, src/util.h, src/zenity.glade, src/zenity.h: Mass indentation cleanup. Make sure the glade dialogs aren't initially visible because this avoids a visibility jump. Apparently == TRUE is bad mojo. Fix up. --- src/tree.c | 549 +++++++++++++++++++++++++++++++------------------------------ 1 file changed, 275 insertions(+), 274 deletions(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index e5573fff..ee529ce0 100644 --- a/src/tree.c +++ b/src/tree.c @@ -39,351 +39,352 @@ static void zenity_tree_dialog_response (GtkWidget *widget, int response, gpoint static void zenity_tree_toggled_callback (GtkCellRendererToggle *cell, gchar *path_string, gpointer data) { - GtkTreeModel *model; - GtkTreeIter iter; - GtkTreePath *path; - gboolean value; + GtkTreeModel *model; + GtkTreeIter iter; + GtkTreePath *path; + gboolean value; - model = GTK_TREE_MODEL (data); - path = gtk_tree_path_new_from_string (path_string); + model = GTK_TREE_MODEL (data); + path = gtk_tree_path_new_from_string (path_string); - gtk_tree_model_get_iter (model, &iter, path); - gtk_tree_model_get (model, &iter, 0, &value, -1); + gtk_tree_model_get_iter (model, &iter, path); + gtk_tree_model_get (model, &iter, 0, &value, -1); - value = !value; - gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, value, -1); + value = !value; + gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, value, -1); - gtk_tree_path_free (path); + gtk_tree_path_free (path); } static void -zenity_tree_fill_entries (GtkTreeView *tree_view, const gchar **args, gint n_columns, gboolean toggles, gboolean editable) +zenity_tree_fill_entries (GtkTreeView *tree_view, + const gchar **args, + gint n_columns, + gboolean toggles, + gboolean editable) { - GtkTreeModel *model; - GtkTreeIter iter; - gint i = 0; + GtkTreeModel *model; + GtkTreeIter iter; + gint i = 0; - model = gtk_tree_view_get_model (tree_view); + model = gtk_tree_view_get_model (tree_view); - while (args[i] != NULL) { - gint j; + while (args[i] != NULL) { + gint j; - gtk_list_store_append (GTK_LIST_STORE (model), &iter); + gtk_list_store_append (GTK_LIST_STORE (model), &iter); - for (j = 0; j < n_columns; j++) { + for (j = 0; j < n_columns; j++) { - if (toggles && j == 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); - } - else - gtk_list_store_set (GTK_LIST_STORE (model), &iter, j, args[i+j], -1); - } - - if (editable) - gtk_list_store_set (GTK_LIST_STORE (model), &iter, n_columns, TRUE, -1); - - if (i == MAX_ELEMENTS_BEFORE_SCROLLING) { - GtkWidget *scrolled_window; - GtkRequisition rectangle; - - gtk_widget_size_request (GTK_WIDGET (tree_view), &rectangle); - scrolled_window = glade_xml_get_widget (glade_dialog, "zenity_tree_window"); - gtk_widget_set_size_request (scrolled_window, -1, rectangle.height); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), - GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); - } - i += n_columns; - - } + if (toggles && j == 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); + } + else + gtk_list_store_set (GTK_LIST_STORE (model), &iter, j, args[i+j], -1); + } + + if (editable) + gtk_list_store_set (GTK_LIST_STORE (model), &iter, n_columns, TRUE, -1); + + if (i == MAX_ELEMENTS_BEFORE_SCROLLING) { + GtkWidget *scrolled_window; + GtkRequisition rectangle; + + gtk_widget_size_request (GTK_WIDGET (tree_view), &rectangle); + scrolled_window = glade_xml_get_widget (glade_dialog, "zenity_tree_window"); + gtk_widget_set_size_request (scrolled_window, -1, rectangle.height); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), + GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); + } + i += n_columns; + + } } static void -zenity_cell_edited_callback (GtkCellRendererText *cell, const gchar *path_string, const gchar *new_text, gpointer data) +zenity_cell_edited_callback (GtkCellRendererText *cell, + const gchar *path_string, + const gchar *new_text, + gpointer data) { - GtkTreeModel *model; - GtkTreePath *path; - GtkTreeIter iter; - gint column; + GtkTreeModel *model; + GtkTreePath *path; + GtkTreeIter iter; + gint column; - model = GTK_TREE_MODEL (data); - path = gtk_tree_path_new_from_string (path_string); + model = GTK_TREE_MODEL (data); + path = gtk_tree_path_new_from_string (path_string); - column = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (cell), "column")); - gtk_tree_model_get_iter (model, &iter, path); - - gtk_list_store_set (GTK_LIST_STORE (model), &iter, - column, new_text, -1); + column = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (cell), "column")); + gtk_tree_model_get_iter (model, &iter, path); + + gtk_list_store_set (GTK_LIST_STORE (model), &iter, column, new_text, -1); - gtk_tree_path_free (path); + gtk_tree_path_free (path); } void zenity_tree (ZenityData *data, ZenityTreeData *tree_data) { - GtkWidget *dialog; - GtkWidget *tree_view; - GtkTreeViewColumn *column; - GtkListStore *model; - GType *column_types; - GSList *tmp; - gboolean first_column = FALSE; - gint i, column_index, n_columns; - - glade_dialog = zenity_util_load_glade_file ("zenity_tree_dialog"); - - if (glade_dialog == NULL) { - data->exit_code = -1; - return; - } + GtkWidget *dialog; + GtkWidget *tree_view; + GtkTreeViewColumn *column; + GtkListStore *model; + GType *column_types; + GSList *tmp; + gboolean first_column = FALSE; + gint i, column_index, n_columns; + + glade_dialog = zenity_util_load_glade_file ("zenity_tree_dialog"); + + if (glade_dialog == NULL) { + data->exit_code = -1; + return; + } - separator = g_strdup (tree_data->separator); + separator = g_strdup (tree_data->separator); - n_columns = g_slist_length (tree_data->columns); + n_columns = g_slist_length (tree_data->columns); - if (n_columns == 0) { - g_printerr (_("No column titles specified for --list\n")); - data->exit_code = -1; - return; - } + if (n_columns == 0) { + g_printerr (_("No column titles specified for --list\n")); + data->exit_code = -1; + return; + } - if (tree_data->data == NULL) { - g_printerr (_("No contents specified for --list\n")); - data->exit_code = -1; - return; - } + if (tree_data->data == NULL) { + g_printerr (_("No contents specified for --list\n")); + data->exit_code = -1; + return; + } - glade_xml_signal_autoconnect (glade_dialog); + glade_xml_signal_autoconnect (glade_dialog); - dialog = glade_xml_get_widget (glade_dialog, "zenity_tree_dialog"); + dialog = glade_xml_get_widget (glade_dialog, "zenity_tree_dialog"); - g_signal_connect (G_OBJECT (dialog), "response", - G_CALLBACK (zenity_tree_dialog_response), data); + g_signal_connect (G_OBJECT (dialog), "response", + G_CALLBACK (zenity_tree_dialog_response), data); - if (data->dialog_title) - gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title); + if (data->dialog_title) + gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title); - if (data->window_icon) - zenity_util_set_window_icon (dialog, data->window_icon); - else - zenity_util_set_window_icon (dialog, ZENITY_IMAGE_FULLPATH ("zenity-list.png")); + if (data->window_icon) + zenity_util_set_window_icon (dialog, data->window_icon); + else + zenity_util_set_window_icon (dialog, ZENITY_IMAGE_FULLPATH ("zenity-list.png")); - tree_view = glade_xml_get_widget (glade_dialog, "zenity_tree_view"); + tree_view = glade_xml_get_widget (glade_dialog, "zenity_tree_view"); - /* Create an empty list store */ - model = g_object_new (GTK_TYPE_LIST_STORE, NULL); + /* Create an empty list store */ + model = g_object_new (GTK_TYPE_LIST_STORE, NULL); - if (tree_data->editable) - column_types = g_new (GType, n_columns + 1); - else - column_types = g_new (GType, n_columns); + if (tree_data->editable) + column_types = g_new (GType, n_columns + 1); + else + column_types = g_new (GType, n_columns); - 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; - else - column_types[i] = G_TYPE_STRING; - } + 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; + else + column_types[i] = G_TYPE_STRING; + } - if (tree_data->editable) - column_types[n_columns] = G_TYPE_BOOLEAN; + if (tree_data->editable) + column_types[n_columns] = G_TYPE_BOOLEAN; - if (tree_data->editable) - gtk_list_store_set_column_types (model, n_columns + 1, column_types); - else - gtk_list_store_set_column_types (model, n_columns, column_types); + if (tree_data->editable) + gtk_list_store_set_column_types (model, n_columns + 1, column_types); + else + 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)); + gtk_tree_view_set_model (GTK_TREE_VIEW (tree_view), GTK_TREE_MODEL (model)); - gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)), - GTK_SELECTION_MULTIPLE); + gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)), + GTK_SELECTION_MULTIPLE); - column_index = 0; + column_index = 0; - for (tmp = tree_data->columns; tmp; tmp = tmp->next) { - if (first_column == FALSE) { - if (tree_data->checkbox || tree_data->radiobox) { - GtkCellRenderer *cell_renderer; - - cell_renderer = gtk_cell_renderer_toggle_new (); + for (tmp = tree_data->columns; tmp; tmp = tmp->next) { + if (!first_column) { + if (tree_data->checkbox || tree_data->radiobox) { + GtkCellRenderer *cell_renderer; + + cell_renderer = gtk_cell_renderer_toggle_new (); - if (tree_data->radiobox) - g_object_set (G_OBJECT (cell_renderer), "radio", TRUE, NULL); - - g_signal_connect (cell_renderer, "toggled", - G_CALLBACK (zenity_tree_toggled_callback), model); - - column = gtk_tree_view_column_new_with_attributes (tmp->data, - cell_renderer, - "active", column_index, NULL); - } - - else { - if (tree_data->editable == TRUE) { - GtkCellRenderer *cell_renderer; - - cell_renderer = gtk_cell_renderer_text_new (); - g_signal_connect (G_OBJECT (cell_renderer), "edited", - G_CALLBACK (zenity_cell_edited_callback), - gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view))); - g_object_set_data (G_OBJECT (cell_renderer), "column", - (gint *) column_index); - - column = gtk_tree_view_column_new_with_attributes (tmp->data, - cell_renderer, - "text", column_index, - "editable", n_columns, - NULL); - } - else { - column = gtk_tree_view_column_new_with_attributes (tmp->data, - gtk_cell_renderer_text_new (), - "text", column_index, NULL); - } - - gtk_tree_view_column_set_sort_column_id (column, column_index); - gtk_tree_view_column_set_resizable (column, TRUE); - } - - first_column = TRUE; - } - else { - if (tree_data->editable == TRUE) { - GtkCellRenderer *cell_renderer; - - cell_renderer = gtk_cell_renderer_text_new (); - g_signal_connect (G_OBJECT (cell_renderer), "edited", - G_CALLBACK (zenity_cell_edited_callback), - gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view))); - g_object_set_data (G_OBJECT (cell_renderer), "column", - (gint *) column_index); - - column = gtk_tree_view_column_new_with_attributes (tmp->data, - cell_renderer, - "text", column_index, - "editable", n_columns, - NULL); - } - else { - column = gtk_tree_view_column_new_with_attributes (tmp->data, - gtk_cell_renderer_text_new (), - "text", column_index, NULL); - } - - gtk_tree_view_column_set_sort_column_id (column, column_index); - gtk_tree_view_column_set_resizable (column, TRUE); + if (tree_data->radiobox) + g_object_set (G_OBJECT (cell_renderer), "radio", TRUE, NULL); + + g_signal_connect (cell_renderer, "toggled", + G_CALLBACK (zenity_tree_toggled_callback), model); + + column = gtk_tree_view_column_new_with_attributes (tmp->data, + cell_renderer, + "active", column_index, NULL); + } + else { + if (tree_data->editable) { + GtkCellRenderer *cell_renderer; + + cell_renderer = gtk_cell_renderer_text_new (); + g_signal_connect (G_OBJECT (cell_renderer), "edited", + G_CALLBACK (zenity_cell_edited_callback), + gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view))); + g_object_set_data (G_OBJECT (cell_renderer), "column", (gint *) column_index); + + column = gtk_tree_view_column_new_with_attributes (tmp->data, + cell_renderer, + "text", column_index, + "editable", n_columns, + NULL); + } + else { + column = gtk_tree_view_column_new_with_attributes (tmp->data, + gtk_cell_renderer_text_new (), + "text", column_index, + NULL); + } + + gtk_tree_view_column_set_sort_column_id (column, column_index); + gtk_tree_view_column_set_resizable (column, TRUE); + } - } + first_column = TRUE; + } + else { + if (tree_data->editable) { + GtkCellRenderer *cell_renderer; + + cell_renderer = gtk_cell_renderer_text_new (); + g_signal_connect (G_OBJECT (cell_renderer), "edited", + G_CALLBACK (zenity_cell_edited_callback), + gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view))); + g_object_set_data (G_OBJECT (cell_renderer), "column", (gint *) column_index); + + column = gtk_tree_view_column_new_with_attributes (tmp->data, + cell_renderer, + "text", column_index, + "editable", n_columns, + NULL); + } + else { + column = gtk_tree_view_column_new_with_attributes (tmp->data, + gtk_cell_renderer_text_new (), + "text", column_index, NULL); + } + + gtk_tree_view_column_set_sort_column_id (column, column_index); + gtk_tree_view_column_set_resizable (column, TRUE); + } - gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column); - column_index++; - } + gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column); + column_index++; + } - gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (tree_view), TRUE); + gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (tree_view), TRUE); - if (tree_data->radiobox || tree_data->checkbox) - zenity_tree_fill_entries (GTK_TREE_VIEW (tree_view), tree_data->data, n_columns, TRUE, tree_data->editable); - else - zenity_tree_fill_entries (GTK_TREE_VIEW (tree_view), tree_data->data, n_columns, FALSE, tree_data->editable); + if (tree_data->radiobox || tree_data->checkbox) + zenity_tree_fill_entries (GTK_TREE_VIEW (tree_view), tree_data->data, n_columns, TRUE, tree_data->editable); + else + zenity_tree_fill_entries (GTK_TREE_VIEW (tree_view), tree_data->data, n_columns, FALSE, tree_data->editable); - gtk_widget_show (dialog); - gtk_main (); + gtk_widget_show (dialog); + gtk_main (); - if (glade_dialog) - g_object_unref (glade_dialog); + if (glade_dialog) + g_object_unref (glade_dialog); } static void zenity_tree_dialog_get_selected (GtkTreeModel *model, GtkTreePath *path_buf, GtkTreeIter *iter, GtkTreeView *tree_view) { - GValue value = {0, }; + GValue value = {0, }; - gtk_tree_model_get_value (model, iter, 0, &value); + gtk_tree_model_get_value (model, iter, 0, &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); } static gboolean zenity_tree_dialog_toggle_get_selected (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data) { - GValue toggle_value = {0, }; - - gtk_tree_model_get_value (model, iter, 0, &toggle_value); - - if (g_value_get_boolean (&toggle_value) == TRUE) { - 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); - } - g_value_unset (&toggle_value); - return FALSE; + GValue toggle_value = {0, }; + + 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); + } + 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 ((const gchar *) separator, (const gchar *) "\\n") != NULL) - g_printerr ("%s\n", tmp->data); - else if (strstr ((const gchar *) separator, (const gchar *) "\\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; + 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 ((const gchar *) separator, (const gchar *) "\\n") != NULL) + g_printerr ("%s\n", tmp->data); + else if (strstr ((const gchar *) separator, (const gchar *) "\\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) { - ZenityData *zen_data = data; - GtkWidget *tree_view; - GtkTreeSelection *selection; - GtkTreeModel *model; - - switch (response) { - case GTK_RESPONSE_OK: - tree_view = glade_xml_get_widget (glade_dialog, "zenity_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) { - gtk_tree_model_foreach (model, - (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_get_selected, - GTK_TREE_VIEW (tree_view)); - } - zenity_tree_dialog_output (); - zen_data->exit_code = 0; - gtk_main_quit (); - break; - - case GTK_RESPONSE_CANCEL: - zen_data->exit_code = 1; - gtk_main_quit (); - break; - - default: - zen_data->exit_code = 1; - break; - } + ZenityData *zen_data = data; + GtkWidget *tree_view; + GtkTreeSelection *selection; + GtkTreeModel *model; + + switch (response) { + case GTK_RESPONSE_OK: + tree_view = glade_xml_get_widget (glade_dialog, "zenity_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) + gtk_tree_model_foreach (model, (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_get_selected, + GTK_TREE_VIEW (tree_view)); + } + zenity_tree_dialog_output (); + zen_data->exit_code = 0; + gtk_main_quit (); + break; + + case GTK_RESPONSE_CANCEL: + zen_data->exit_code = 1; + gtk_main_quit (); + break; + + default: + /* Esc dialog */ + zen_data->exit_code = 1; + break; + } } -- cgit From 965c2a91497fcf96c88c0029b18a6a1e9f5d46bd Mon Sep 17 00:00:00 2001 From: Glynn Foster Date: Sun, 13 Apr 2003 15:42:41 +0000 Subject: Finish off the indentation cleanup. Add new '--width' and '--height' 2003-04-13 Glynn Foster * src/calendar.c, src/entry.c, src/fileselection.c, src/main.c, src/msg.c, src/progress.c, src/text.c, src/tree.c, src/zenity.h: Finish off the indentation cleanup. Add new '--width' and '--height' options to the general options. Fix up the radio list view, so that we can now act like a radio button group. * TODO: Update --- src/tree.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index ee529ce0..08043787 100644 --- a/src/tree.c +++ b/src/tree.c @@ -36,6 +36,17 @@ static gchar *separator; static void zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer data); +static gboolean +zenity_tree_dialog_untoggle (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data) +{ + GValue toggle_value = {0, }; + + gtk_tree_model_get_value (model, iter, 0, &toggle_value); + + if (g_value_get_boolean (&toggle_value)) + gtk_list_store_set (GTK_LIST_STORE (model), iter, 0, FALSE, -1); +} + static void zenity_tree_toggled_callback (GtkCellRendererToggle *cell, gchar *path_string, gpointer data) { @@ -45,8 +56,16 @@ zenity_tree_toggled_callback (GtkCellRendererToggle *cell, gchar *path_string, g gboolean value; model = GTK_TREE_MODEL (data); - path = gtk_tree_path_new_from_string (path_string); + /* Because this is a radio list, we should untoggle the previous toggle so that + * we only have one selection at any given time + */ + + if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (model), "radio")) == 1) { + gtk_tree_model_foreach (model, zenity_tree_dialog_untoggle, NULL); + } + + path = gtk_tree_path_new_from_string (path_string); gtk_tree_model_get_iter (model, &iter, path); gtk_tree_model_get (model, &iter, 0, &value, -1); @@ -176,6 +195,8 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) else zenity_util_set_window_icon (dialog, ZENITY_IMAGE_FULLPATH ("zenity-list.png")); + gtk_window_set_default_size (GTK_WINDOW (dialog), data->width, data->height); + tree_view = glade_xml_get_widget (glade_dialog, "zenity_tree_view"); /* Create an empty list store */ @@ -216,8 +237,10 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) cell_renderer = gtk_cell_renderer_toggle_new (); - if (tree_data->radiobox) + if (tree_data->radiobox) { g_object_set (G_OBJECT (cell_renderer), "radio", TRUE, NULL); + g_object_set_data (G_OBJECT (model), "radio", (gint *) 1); + } g_signal_connect (cell_renderer, "toggled", G_CALLBACK (zenity_tree_toggled_callback), model); -- cgit From 8ff2b32c9eb4b2eb8970a9fa48c4889847c347b1 Mon Sep 17 00:00:00 2001 From: Glynn Foster Date: Mon, 5 May 2003 17:17:02 +0000 Subject: Make the list dialog handle stdin - a little bit buggy still. Update 2003-05-05 Glynn Foster * src/tree.c, src/util.c, src/util.h: Make the list dialog handle stdin - a little bit buggy still. * TODO: Update --- src/tree.c | 133 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 128 insertions(+), 5 deletions(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index 08043787..2481d8b9 100644 --- a/src/tree.c +++ b/src/tree.c @@ -75,6 +75,119 @@ zenity_tree_toggled_callback (GtkCellRendererToggle *cell, gchar *path_string, g gtk_tree_path_free (path); } +static gboolean +zenity_tree_handle_stdin (GIOChannel *channel, + GIOCondition condition, + gpointer data) +{ + static GtkTreeView *tree_view; + GtkTreeModel *model; + GtkTreeIter iter; + static gint column_count = 0; + static gint row_count = 0; + static gint n_columns; + static gboolean editable; + static gboolean toggles; + + tree_view = GTK_TREE_VIEW (data); + n_columns = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tree_view), "n_columns")); + editable = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tree_view), "editable")); + toggles = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tree_view), "toggles")); + + model = gtk_tree_view_get_model (tree_view); + + if ((condition == G_IO_IN) || (condition == G_IO_IN + G_IO_HUP)) { + GString *string; + GError *error = NULL; + + string = g_string_new (NULL); + + while (channel->is_readable != TRUE) + ; + do { + gint status; + + do { + status = g_io_channel_read_line_string (channel, string, NULL, &error); + + while (gtk_events_pending ()) + gtk_main_iteration (); + + } while (status == G_IO_STATUS_AGAIN); + + if (status != G_IO_STATUS_NORMAL) { + if (error) { + g_warning ("zenity_tree_handle_stdin () : %s", error->message); + g_error_free (error); + error = NULL; + } + continue; + } + + if (column_count == n_columns) { + /* We're starting a new row */ + column_count = 0; + row_count++; + gtk_list_store_append (GTK_LIST_STORE (model), &iter); + } + + if (toggles && column_count == 0) { + if (strcmp (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); + } + else { + gtk_list_store_set (GTK_LIST_STORE (model), &iter, column_count, zenity_util_strip_newline (string->str), -1); + } + + if (editable) { + g_print ("Shouldn't be going here"); + gtk_list_store_set (GTK_LIST_STORE (model), &iter, n_columns, TRUE, -1); + } + + if (row_count == MAX_ELEMENTS_BEFORE_SCROLLING) { + GtkWidget *scrolled_window; + GtkRequisition rectangle; + + gtk_widget_size_request (GTK_WIDGET (tree_view), &rectangle); + scrolled_window = glade_xml_get_widget (glade_dialog, "zenity_tree_window"); + gtk_widget_set_size_request (scrolled_window, -1, rectangle.height); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), + GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); + } + + column_count ++; + + } while (g_io_channel_get_buffer_condition (channel) == G_IO_IN); + g_string_free (string, TRUE); + } + + if (condition != G_IO_IN) { + g_io_channel_shutdown (channel, TRUE, NULL); + return FALSE; + } + return TRUE; +} + +static void +zenity_tree_fill_entries_from_stdin (GtkTreeView *tree_view, + gint n_columns, + gboolean toggles, + gboolean editable) +{ + GIOChannel *channel; + + g_object_set_data (G_OBJECT (tree_view), "n_columns", (gint *) n_columns); + g_object_set_data (G_OBJECT (tree_view), "toggles", (gint *) toggles); + g_object_set_data (G_OBJECT (tree_view), "editable", (gint *) editable); + + channel = g_io_channel_unix_new (0); + g_io_channel_set_encoding (channel, NULL, NULL); + g_io_channel_set_flags (channel, G_IO_FLAG_NONBLOCK, NULL); + g_io_add_watch (channel, G_IO_IN | G_IO_HUP, zenity_tree_handle_stdin, tree_view); +} + static void zenity_tree_fill_entries (GtkTreeView *tree_view, const gchar **args, @@ -118,8 +231,8 @@ zenity_tree_fill_entries (GtkTreeView *tree_view, gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); } - i += n_columns; + i += n_columns; } } @@ -174,11 +287,13 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) return; } + /* if (tree_data->data == NULL) { g_printerr (_("No contents specified for --list\n")); data->exit_code = -1; return; } + */ glade_xml_signal_autoconnect (glade_dialog); @@ -310,10 +425,18 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (tree_view), TRUE); - if (tree_data->radiobox || tree_data->checkbox) - zenity_tree_fill_entries (GTK_TREE_VIEW (tree_view), tree_data->data, n_columns, TRUE, tree_data->editable); - else - zenity_tree_fill_entries (GTK_TREE_VIEW (tree_view), tree_data->data, n_columns, FALSE, tree_data->editable); + if (tree_data->radiobox || tree_data->checkbox) { + if (tree_data->data) + zenity_tree_fill_entries (GTK_TREE_VIEW (tree_view), tree_data->data, n_columns, TRUE, tree_data->editable); + else + zenity_tree_fill_entries_from_stdin (GTK_TREE_VIEW (tree_view), n_columns, TRUE, tree_data->editable); + } + else { + if (tree_data->data) + zenity_tree_fill_entries (GTK_TREE_VIEW (tree_view), tree_data->data, n_columns, FALSE, tree_data->editable); + else + zenity_tree_fill_entries_from_stdin (GTK_TREE_VIEW (tree_view), n_columns, FALSE, tree_data->editable); + } gtk_widget_show (dialog); gtk_main (); -- cgit From d5549deab31020185742dbeb41594a6224270240 Mon Sep 17 00:00:00 2001 From: Glynn Foster Date: Tue, 6 May 2003 20:22:16 +0000 Subject: Fix up the stdin list dialog stuff. Updated to actually include the 2003-05-06 Glynn Foster * src/tree.c: Fix up the stdin list dialog stuff. * NEWS: Updated to actually include the updated translations as well. --- src/tree.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index 2481d8b9..5b32fd17 100644 --- a/src/tree.c +++ b/src/tree.c @@ -28,7 +28,7 @@ #include "zenity.h" #include "util.h" -#define MAX_ELEMENTS_BEFORE_SCROLLING 8 +#define MAX_ELEMENTS_BEFORE_SCROLLING 5 static GladeXML *glade_dialog; static GSList *selected; @@ -88,6 +88,7 @@ zenity_tree_handle_stdin (GIOChannel *channel, static gint n_columns; static gboolean editable; static gboolean toggles; + static gboolean first_time = FALSE; tree_view = GTK_TREE_VIEW (data); n_columns = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tree_view), "n_columns")); @@ -96,6 +97,11 @@ zenity_tree_handle_stdin (GIOChannel *channel, model = gtk_tree_view_get_model (tree_view); + if (!first_time) { + first_time = TRUE; + gtk_list_store_append (GTK_LIST_STORE (model), &iter); + } + if ((condition == G_IO_IN) || (condition == G_IO_IN + G_IO_HUP)) { GString *string; GError *error = NULL; @@ -132,9 +138,9 @@ zenity_tree_handle_stdin (GIOChannel *channel, } if (toggles && column_count == 0) { - if (strcmp (string->str, "TRUE") == 0) + if (strcmp (zenity_util_strip_newline (string->str), "TRUE") == 0) 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); } else { @@ -142,7 +148,6 @@ zenity_tree_handle_stdin (GIOChannel *channel, } if (editable) { - g_print ("Shouldn't be going here"); gtk_list_store_set (GTK_LIST_STORE (model), &iter, n_columns, TRUE, -1); } -- cgit From a08343daf90e9425c85c1138cf6eea90addafb11 Mon Sep 17 00:00:00 2001 From: Glynn Foster Date: Wed, 7 May 2003 01:08:08 +0000 Subject: Update commandline error message, needs updating of translations. Remove 2003-05-06 Glynn Foster * src/main.c: Update commandline error message, needs updating of translations. * src/tree.c: Remove some commented out code. * src/zenity.glade: Updated error and info dialogs to do wrapping. --- src/tree.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index 5b32fd17..b94f6344 100644 --- a/src/tree.c +++ b/src/tree.c @@ -287,19 +287,11 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) n_columns = g_slist_length (tree_data->columns); if (n_columns == 0) { - g_printerr (_("No column titles specified for --list\n")); + g_printerr (_("No column titles specified for List dialog.\n")); data->exit_code = -1; return; } - /* - if (tree_data->data == NULL) { - g_printerr (_("No contents specified for --list\n")); - data->exit_code = -1; - return; - } - */ - glade_xml_signal_autoconnect (glade_dialog); dialog = glade_xml_get_widget (glade_dialog, "zenity_tree_dialog"); -- cgit From 65cb873430d7bfcdf0452c76bf07f2ebbb4a21af Mon Sep 17 00:00:00 2001 From: Glynn Foster Date: Wed, 4 Jun 2003 12:53:46 +0000 Subject: Fix up some build warnings as reported by Ross Burton and his amazing gcc 2003-06-04 Glynn Foster * src/about.c, src/main.c, src/msg.c, src/progress.c, src/tree.c, src/util.c: Fix up some build warnings as reported by Ross Burton and his amazing gcc 3.3 techno machine. --- src/tree.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index b94f6344..f3e63779 100644 --- a/src/tree.c +++ b/src/tree.c @@ -45,6 +45,7 @@ zenity_tree_dialog_untoggle (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter if (g_value_get_boolean (&toggle_value)) gtk_list_store_set (GTK_LIST_STORE (model), iter, 0, FALSE, -1); + return FALSE; } static void @@ -479,14 +480,14 @@ zenity_tree_dialog_output (void) if (tmp->next != NULL) { /* FIXME: There must be a nicer way to do this. This is just arse */ if (strstr ((const gchar *) separator, (const gchar *) "\\n") != NULL) - g_printerr ("%s\n", tmp->data); + g_printerr ("%s\n", (gchar *) tmp->data); else if (strstr ((const gchar *) separator, (const gchar *) "\\t") != NULL) - g_printerr ("%s\t", tmp->data); + g_printerr ("%s\t", (gchar *) tmp->data); else - g_printerr ("%s%s", tmp->data, separator); + g_printerr ("%s%s", (gchar *) tmp->data, separator); } else - g_printerr ("%s\n", tmp->data); + g_printerr ("%s\n", (gchar *) tmp->data); } g_free (separator); -- cgit From 5bade6fe6a14cce50508ee5d510a4560ebe3e421 Mon Sep 17 00:00:00 2001 From: Mike Newman Date: Sat, 7 Jun 2003 14:41:56 +0000 Subject: Support user-defined return values via env vars, like dialog did. --- src/tree.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index f3e63779..903ef704 100644 --- a/src/tree.c +++ b/src/tree.c @@ -279,7 +279,7 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) glade_dialog = zenity_util_load_glade_file ("zenity_tree_dialog"); if (glade_dialog == NULL) { - data->exit_code = -1; + data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR); return; } @@ -289,7 +289,7 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) if (n_columns == 0) { g_printerr (_("No column titles specified for List dialog.\n")); - data->exit_code = -1; + data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR); return; } @@ -517,18 +517,18 @@ zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer data) GTK_TREE_VIEW (tree_view)); } zenity_tree_dialog_output (); - zen_data->exit_code = 0; + zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK); gtk_main_quit (); break; case GTK_RESPONSE_CANCEL: - zen_data->exit_code = 1; + zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL); gtk_main_quit (); break; default: /* Esc dialog */ - zen_data->exit_code = 1; + zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC); break; } } -- cgit From cfe29d9ad04761e7a97964af5e8f20fca7d22cfc Mon Sep 17 00:00:00 2001 From: Mike Newman Date: Tue, 10 Jun 2003 21:30:22 +0000 Subject: Allow /t and /n in dialog text. Some code cleanup. --- src/tree.c | 6 ------ 1 file changed, 6 deletions(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index 903ef704..80562d86 100644 --- a/src/tree.c +++ b/src/tree.c @@ -478,12 +478,6 @@ zenity_tree_dialog_output (void) 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 ((const gchar *) separator, (const gchar *) "\\n") != NULL) - g_printerr ("%s\n", (gchar *) tmp->data); - else if (strstr ((const gchar *) separator, (const gchar *) "\\t") != NULL) - g_printerr ("%s\t", (gchar *) tmp->data); - else g_printerr ("%s%s", (gchar *) tmp->data, separator); } else -- cgit From 652c90596e2c4fff6b7b748afcb01df6e21d22d9 Mon Sep 17 00:00:00 2001 From: "Kevin C. Krinke" Date: Sun, 13 Jul 2003 23:03:18 +0000 Subject: user input data output to STDOUT via g_print instead of outputting to 2003-07-11 Kevin C. Krinke * src/calendar.c, src/entry.c, src/fileselection.c, src/text.c, src/tree.c: user input data output to STDOUT via g_print instead of outputting to STDERR via g_printerr. This makes it possible to destinguish user input data from GTK+ warnings / errors. * THANKS, src/about.c: I figure this is my second patch submission so I belong in the credits... --- src/tree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index 80562d86..73e9565d 100644 --- a/src/tree.c +++ b/src/tree.c @@ -478,10 +478,10 @@ zenity_tree_dialog_output (void) for (tmp = selected; tmp; tmp = tmp->next) { if (tmp->next != NULL) { - g_printerr ("%s%s", (gchar *) tmp->data, separator); + g_print ("%s%s", (gchar *) tmp->data, separator); } else - g_printerr ("%s\n", (gchar *) tmp->data); + g_print ("%s\n", (gchar *) tmp->data); } g_free (separator); -- cgit From d02a5bcd112cf475f7312d234e02c4c761dd9e1f Mon Sep 17 00:00:00 2001 From: Glynn Foster Date: Wed, 27 Aug 2003 12:10:04 +0000 Subject: Put horizontal scrolling on automatic, otherwise we expand off the edge of 2003-08-27 Glynn Foster * src/tree.c: Put horizontal scrolling on automatic, otherwise we expand off the edge of the screen. --- src/tree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index 73e9565d..aaf513c6 100644 --- a/src/tree.c +++ b/src/tree.c @@ -160,7 +160,7 @@ zenity_tree_handle_stdin (GIOChannel *channel, scrolled_window = glade_xml_get_widget (glade_dialog, "zenity_tree_window"); gtk_widget_set_size_request (scrolled_window, -1, rectangle.height); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), - GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); + GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); } column_count ++; @@ -235,7 +235,7 @@ zenity_tree_fill_entries (GtkTreeView *tree_view, scrolled_window = glade_xml_get_widget (glade_dialog, "zenity_tree_window"); gtk_widget_set_size_request (scrolled_window, -1, rectangle.height); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), - GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); + GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); } i += n_columns; -- cgit From b43bbda2e247e72782cf116003d308d21346935f Mon Sep 17 00:00:00 2001 From: Glynn Foster Date: Fri, 19 Mar 2004 02:28:30 +0000 Subject: Patch from Darren Adams to make sure the new 2004-03-19 Glynn Foster * src/calendar.c, src/entry.c, src/fileselection.c, src/msg.c, src/progress.c, src/text.c, src/tree.c: Patch from Darren Adams to make sure the new file chooser resizes nicely. Sanitize the default setting of the other widgets. * configure.in, src/util.c: Lose gconf dependancy since we don't currently use it, although arguably we should to detect which help browser we're supposed to run :/ * THANKS, src/about.c: Add Darren to the list. --- src/tree.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index aaf513c6..03404b04 100644 --- a/src/tree.c +++ b/src/tree.c @@ -308,7 +308,8 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) else zenity_util_set_window_icon (dialog, ZENITY_IMAGE_FULLPATH ("zenity-list.png")); - gtk_window_set_default_size (GTK_WINDOW (dialog), data->width, data->height); + if (data->width > -1 || data->height > -1) + gtk_window_set_default_size (GTK_WINDOW (dialog), data->width, data->height); tree_view = glade_xml_get_widget (glade_dialog, "zenity_tree_view"); -- cgit From 62785ed80fb0b86847b4eaa3f4cf596f4c109324 Mon Sep 17 00:00:00 2001 From: Glynn Foster Date: Mon, 26 Apr 2004 04:41:25 +0000 Subject: Add from the 2 Sebastian's, and make email addresses more spam proof. 2004-04-26 Glynn Foster * THANKS, src/about.c: Add from the 2 Sebastian's, and make email addresses more spam proof. * src/calendar.c, src/entry.c, src/fileselection.c, src/msg.c, * src/progress.c, src/text.c, src/tree.c, src/util.c, * src/util.h: Patch from Sebastian Kapfer to make all zenity dialogs transients of the parent xterm. Fixes #136226. * src/zenity.glade: Patch from Sebastian Heinlein to improve things HIG wise. Fixes #140745. --- src/tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index 03404b04..a1c1bb95 100644 --- a/src/tree.c +++ b/src/tree.c @@ -437,7 +437,7 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) zenity_tree_fill_entries_from_stdin (GTK_TREE_VIEW (tree_view), n_columns, FALSE, tree_data->editable); } - gtk_widget_show (dialog); + zenity_util_show_dialog (dialog); gtk_main (); if (glade_dialog) -- cgit From 02955ce70f7fa58da88dc8d66e07520afb94f642 Mon Sep 17 00:00:00 2001 From: Glynn Foster Date: Wed, 28 Apr 2004 12:06:02 +0000 Subject: Fix the list dialog not being able to handle --text to change the text. It 2004-04-29 Glynn Foster * src/main.c, src/tree.c: Fix the list dialog not being able to handle --text to change the text. It was also intentional but must have fallen through the gaps. * data/zenity.1: Update * help/C/zenity.xml: Update. --- src/tree.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index a1c1bb95..bc1cc1cc 100644 --- a/src/tree.c +++ b/src/tree.c @@ -269,6 +269,7 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) { GtkWidget *dialog; GtkWidget *tree_view; + GtkWidget *text; GtkTreeViewColumn *column; GtkListStore *model; GType *column_types; @@ -303,6 +304,11 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) if (data->dialog_title) gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title); + text = glade_xml_get_widget (glade_dialog, "zenity_tree_text"); + + if (tree_data->dialog_text) + gtk_label_set_text (GTK_LABEL (text), tree_data->dialog_text); + if (data->window_icon) zenity_util_set_window_icon (dialog, data->window_icon); else -- cgit From ffaed088561e8c0a085fd2797543aaef65419f0c Mon Sep 17 00:00:00 2001 From: Glynn Foster Date: Mon, 19 Jul 2004 01:01:28 +0000 Subject: Add new option for --print-column, based on a patch by Paul Bolle. Fixes 2004-07-19 Glynn Foster * 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. --- src/tree.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 55 insertions(+), 10 deletions(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index bc1cc1cc..e828dfc3 100644 --- a/src/tree.c +++ b/src/tree.c @@ -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, -- cgit From 63661a6ea0de0250b545d794f645a36ffeb88490 Mon Sep 17 00:00:00 2001 From: Glynn Foster Date: Mon, 19 Jul 2004 01:13:40 +0000 Subject: src/calendar.c, src/entry.c, src/fileselection.c, Cleanup fixes from Paul 2004-07-19 Glynn Foster * src/calendar.c, src/entry.c, src/fileselection.c, * src/msg.c, src/progress.c, src/text.c, src/tree.c: Cleanup fixes from Paul Bolle. --- src/tree.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index e828dfc3..fed58e2a 100644 --- a/src/tree.c +++ b/src/tree.c @@ -564,12 +564,10 @@ zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer data) } zenity_tree_dialog_output (); zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK); - gtk_main_quit (); break; case GTK_RESPONSE_CANCEL: zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL); - gtk_main_quit (); break; default: @@ -577,4 +575,5 @@ zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer data) zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC); break; } + gtk_main_quit (); } -- cgit From 3e05834b4c23a5d5951403719b8594ff3d9fe30b Mon Sep 17 00:00:00 2001 From: Glynn Foster Date: Mon, 13 Sep 2004 07:51:51 +0000 Subject: Add new notification icon. Update for new files. Restructure code a little 2004-09-13 Glynn Foster * data/Makefile.am, data/zenity-notification.png: Add new notification icon. * src/Makefile.am: Update for new files. * src/about.c, src/calendar.c, src/entry.c, src/fileselection.c, src/progress.c, src/text.c, src/tree.c, src/msg.c: Restructure code a little bit for new utility functions for setting window icons. * src/eggtrayicon.c, src/eggtrayicon.h: New files for notification area support. * src/main.c, src/notification.c, src/util.c, src/util.h, src/zenity.h: Add support for notification area. * data/zenity.1, help/*: Update docs for notification and new file selection changes. --- src/tree.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index fed58e2a..436f632f 100644 --- a/src/tree.c +++ b/src/tree.c @@ -320,10 +320,7 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) if (tree_data->dialog_text) gtk_label_set_text (GTK_LABEL (text), tree_data->dialog_text); - if (data->window_icon) - zenity_util_set_window_icon (dialog, data->window_icon); - else - zenity_util_set_window_icon (dialog, ZENITY_IMAGE_FULLPATH ("zenity-list.png")); + zenity_util_set_window_icon (dialog, data->window_icon, ZENITY_IMAGE_FULLPATH ("zenity-list.png")); if (data->width > -1 || data->height > -1) gtk_window_set_default_size (GTK_WINDOW (dialog), data->width, data->height); -- cgit From ca975e839996dbe1a85825b7f3472b170505540c Mon Sep 17 00:00:00 2001 From: Kjartan Maraas Date: Fri, 17 Sep 2004 08:57:21 +0000 Subject: Add missing header. Same ANSIfication. Closes bug #152851. 2004-09-17 Kjartan Maraas * src/progress.c: Add missing header. * src/tree.c: Same * src/util.c: (transient_get_xterm), (transient_get_xterm_toplevel): ANSIfication. Closes bug #152851. --- src/tree.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index 436f632f..49c1d782 100644 --- a/src/tree.c +++ b/src/tree.c @@ -25,6 +25,7 @@ #include #include +#include #include "zenity.h" #include "util.h" -- cgit From bc282cfa65502ea8d8a84553162f5690b8bf328c Mon Sep 17 00:00:00 2001 From: Glynn Foster Date: Mon, 17 Jan 2005 01:33:23 +0000 Subject: Patch from Ed Catmur to fix the list dialog on stdin. Fixes #164152. 2005-01-17 Glynn Foster * src/tree.c: Patch from Ed Catmur to fix the list dialog on stdin. Fixes #164152. * src/about.c, THANKS: Update. --- src/tree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index 49c1d782..63fe4aee 100644 --- a/src/tree.c +++ b/src/tree.c @@ -440,13 +440,13 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (tree_view), TRUE); if (tree_data->radiobox || tree_data->checkbox) { - if (tree_data->data) + if (tree_data->data && *tree_data->data) zenity_tree_fill_entries (GTK_TREE_VIEW (tree_view), tree_data->data, n_columns, TRUE, tree_data->editable); else zenity_tree_fill_entries_from_stdin (GTK_TREE_VIEW (tree_view), n_columns, TRUE, tree_data->editable); } else { - if (tree_data->data) + if (tree_data->data && *tree_data->data) zenity_tree_fill_entries (GTK_TREE_VIEW (tree_view), tree_data->data, n_columns, FALSE, tree_data->editable); else zenity_tree_fill_entries_from_stdin (GTK_TREE_VIEW (tree_view), n_columns, FALSE, tree_data->editable); -- cgit From 6abd93050f533752e47b75158e95431575c652ac Mon Sep 17 00:00:00 2001 From: Glynn Foster Date: Mon, 25 Apr 2005 03:20:45 +0000 Subject: COPYING, src/about.c, src/calendar.c, src/eggtrayicon.c, src/entry.c, 2005-04-25 Glynn Foster * COPYING, src/about.c, src/calendar.c, src/eggtrayicon.c, * src/entry.c, src/fileselection.c, src/main.c, src/msg.c, * src/notification.c, src/option.c, src/progress.c, * src/text.c, src/tree.c, src/util.c: Update the FSF address to point to 51 Franklin Street, Fifth Floor as per forwarded mail from Alvaro Lopez Ortega. --- src/tree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index 63fe4aee..b50a755b 100644 --- a/src/tree.c +++ b/src/tree.c @@ -15,8 +15,8 @@ * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. * * Authors: Glynn Foster * Jonathan Blanford -- cgit From 9c792cb86a8d0422a07a716a3b024f25d9bca1bb Mon Sep 17 00:00:00 2001 From: Lucas Almeida Rocha Date: Mon, 27 Jun 2005 03:13:37 +0000 Subject: Changed list dialog Selection behavior --- src/tree.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index b50a755b..e60e262f 100644 --- a/src/tree.c +++ b/src/tree.c @@ -354,8 +354,17 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) gtk_tree_view_set_model (GTK_TREE_VIEW (tree_view), GTK_TREE_MODEL (model)); - gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)), - GTK_SELECTION_MULTIPLE); + if (!(tree_data->radiobox || tree_data->checkbox)) { + if (tree_data->multi) + gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)), + GTK_SELECTION_MULTIPLE); + else + gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)), + GTK_SELECTION_SINGLE); + } + else + gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)), + GTK_SELECTION_NONE); column_index = 0; -- cgit From 5d584ca8ef032cecaf05fcc4ceca0db24e70ff16 Mon Sep 17 00:00:00 2001 From: Lucas Almeida Rocha Date: Mon, 27 Jun 2005 04:27:15 +0000 Subject: Double-clicking on list dialog --- src/tree.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index e60e262f..46b68c23 100644 --- a/src/tree.c +++ b/src/tree.c @@ -38,6 +38,8 @@ 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_row_activated (GtkTreeView *tree_view, GtkTreePath *tree_path, + GtkTreeViewColumn *tree_col, gpointer data); static gboolean zenity_tree_dialog_untoggle (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data) @@ -328,6 +330,10 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) tree_view = glade_xml_get_widget (glade_dialog, "zenity_tree_view"); + if (!(tree_data->radiobox || tree_data->checkbox)) + g_signal_connect (G_OBJECT (tree_view), "row-activated", + G_CALLBACK (zenity_tree_row_activated), data); + /* Create an empty list store */ model = g_object_new (GTK_TYPE_LIST_STORE, NULL); @@ -584,3 +590,23 @@ zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer data) } gtk_main_quit (); } + +static void +zenity_tree_row_activated (GtkTreeView *tree_view, GtkTreePath *tree_path, + GtkTreeViewColumn *tree_col, gpointer data) +{ + ZenityData *zen_data = data; + GtkTreeSelection *selection; + GtkTreeModel *model; + + model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view)); + + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)); + gtk_tree_selection_selected_foreach (selection, + (GtkTreeSelectionForeachFunc) zenity_tree_dialog_get_selected, + GTK_TREE_VIEW (tree_view)); + + zenity_tree_dialog_output (); + zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK); + gtk_main_quit (); +} -- cgit From cc3fc2be3ea3f322ca53b13b82dc9e73a44e58b2 Mon Sep 17 00:00:00 2001 From: Lucas Almeida Rocha Date: Tue, 28 Jun 2005 04:43:10 +0000 Subject: Error handling when trying to use checklist and radiolist in the same List dialog --- src/tree.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index 46b68c23..0e213d5f 100644 --- a/src/tree.c +++ b/src/tree.c @@ -308,6 +308,12 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) return; } + if (tree_data->checkbox && tree_data->radiobox) { + g_printerr (_("You should use only one List dialog type.\n")); + data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR); + return; + } + glade_xml_signal_autoconnect (glade_dialog); dialog = glade_xml_get_widget (glade_dialog, "zenity_tree_dialog"); -- cgit From c9be8d057942521381c3e3a7d76c374d02b88dbf Mon Sep 17 00:00:00 2001 From: Lucas Almeida Rocha Date: Tue, 28 Jun 2005 11:11:50 +0000 Subject: New --print-column syntax. Now it's possible to pass a comma-separated list of column indexes. --- src/tree.c | 60 ++++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 22 deletions(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index 0e213d5f..1a0d35d1 100644 --- a/src/tree.c +++ b/src/tree.c @@ -30,12 +30,13 @@ #include "util.h" #define MAX_ELEMENTS_BEFORE_SCROLLING 5 +#define PRINT_HIDE_COLUMN_SEPARATOR "," static GladeXML *glade_dialog; static GSList *selected; static gchar *separator; 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_row_activated (GtkTreeView *tree_view, GtkTreePath *tree_path, @@ -146,11 +147,11 @@ zenity_tree_handle_stdin (GIOChannel *channel, if (toggles && column_count == 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 + else gtk_list_store_set (GTK_LIST_STORE (model), &iter, column_count, FALSE, -1); } else { - gtk_list_store_set (GTK_LIST_STORE (model), &iter, column_count, zenity_util_strip_newline (string->str), -1); + gtk_list_store_set (GTK_LIST_STORE (model), &iter, column_count, zenity_util_strip_newline (string->str), -1); } if (editable) { @@ -220,15 +221,15 @@ zenity_tree_fill_entries (GtkTreeView *tree_view, gtk_list_store_append (GTK_LIST_STORE (model), &iter); for (j = 0; j < n_columns; j++) { - + if (toggles && j == 0) { if (strcmp (g_strdown ((gchar *) args[i+j]), "true") == 0) 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); } else - gtk_list_store_set (GTK_LIST_STORE (model), &iter, j, args[i+j], -1); + gtk_list_store_set (GTK_LIST_STORE (model), &iter, j, args[i+j], -1); } if (editable) @@ -299,7 +300,13 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) if (strcmp (g_strdown (tree_data->print_column), "all") == 0) print_all_columns = TRUE; 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) { @@ -327,7 +334,7 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) text = glade_xml_get_widget (glade_dialog, "zenity_tree_text"); if (tree_data->dialog_text) - gtk_label_set_text (GTK_LABEL (text), tree_data->dialog_text); + gtk_label_set_text (GTK_LABEL (text), tree_data->dialog_text); zenity_util_set_window_icon (dialog, data->window_icon, ZENITY_IMAGE_FULLPATH ("zenity-list.png")); @@ -386,13 +393,13 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) GtkCellRenderer *cell_renderer; cell_renderer = gtk_cell_renderer_toggle_new (); - + if (tree_data->radiobox) { g_object_set (G_OBJECT (cell_renderer), "radio", TRUE, NULL); g_object_set_data (G_OBJECT (model), "radio", (gint *) 1); } - g_signal_connect (cell_renderer, "toggled", + g_signal_connect (cell_renderer, "toggled", G_CALLBACK (zenity_tree_toggled_callback), model); column = gtk_tree_view_column_new_with_attributes (tmp->data, @@ -425,7 +432,7 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) gtk_tree_view_column_set_sort_column_id (column, column_index); gtk_tree_view_column_set_resizable (column, TRUE); } - + first_column = TRUE; } else { @@ -453,7 +460,7 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) gtk_tree_view_column_set_sort_column_id (column, column_index); gtk_tree_view_column_set_resizable (column, TRUE); } - + gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column); column_index++; } @@ -484,7 +491,7 @@ static void zenity_tree_dialog_get_selected (GtkTreeModel *model, GtkTreePath *path_buf, GtkTreeIter *iter, GtkTreeView *tree_view) { 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")); @@ -498,11 +505,15 @@ zenity_tree_dialog_get_selected (GtkTreeModel *model, GtkTreePath *path_buf, Gtk return; } - if (print_column_n > 0 && print_column_n <= n_columns) { - gtk_tree_model_get_value (model, iter, print_column_n - 1, &value); + for (i = 0; print_columns[i] != NULL; i++) { + 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))); - g_value_unset (&value); + selected = g_slist_append (selected, g_strdup (g_value_get_string (&value))); + g_value_unset (&value); + } } } @@ -510,7 +521,7 @@ static gboolean zenity_tree_dialog_toggle_get_selected (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, GtkTreeView *tree_view) { 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")); @@ -530,11 +541,15 @@ zenity_tree_dialog_toggle_get_selected (GtkTreeModel *model, GtkTreePath *path, return FALSE; } - if (print_column_n > 0 && print_column_n <= n_columns) { - gtk_tree_model_get_value (model, iter, print_column_n, &value); + for (i = 0; print_columns[i] != NULL; i++) { + print_column = atoi (print_columns[i]); - selected = g_slist_append (selected, g_strdup (g_value_get_string (&value))); - g_value_unset (&value); + 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))); + g_value_unset (&value); + } } } g_value_unset (&toggle_value); @@ -554,6 +569,7 @@ zenity_tree_dialog_output (void) g_print ("%s\n", (gchar *) tmp->data); } + g_strfreev (print_columns); g_free (separator); g_slist_foreach (selected, (GFunc) g_free, NULL); selected = NULL; -- cgit From da0a2585b3dce693eb1961fdc64ffcb3840a1bba Mon Sep 17 00:00:00 2001 From: Lucas Almeida Rocha Date: Thu, 30 Jun 2005 23:43:23 +0000 Subject: Data structure improvements on List dialogs. --- src/tree.c | 72 ++++++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 47 insertions(+), 25 deletions(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index 1a0d35d1..ea2ba9e4 100644 --- a/src/tree.c +++ b/src/tree.c @@ -36,8 +36,9 @@ static GladeXML *glade_dialog; static GSList *selected; static gchar *separator; static gboolean print_all_columns = FALSE; -static char **print_columns = NULL; +static gint *print_columns = NULL; +static int *zenity_tree_extract_column_indexes (char *indexes, gint n_columns); static void zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer data); static void zenity_tree_row_activated (GtkTreeView *tree_view, GtkTreePath *tree_path, GtkTreeViewColumn *tree_col, gpointer data); @@ -299,14 +300,13 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) if (tree_data->print_column) { if (strcmp (g_strdown (tree_data->print_column), "all") == 0) print_all_columns = TRUE; - else - print_columns = g_strsplit (tree_data->print_column, - PRINT_HIDE_COLUMN_SEPARATOR, 0); + else + print_columns = zenity_tree_extract_column_indexes (tree_data->print_column, n_columns); } else { - print_columns = (char **) g_new (char**, 2); - print_columns[0] = g_strdup ("1"); - print_columns[1] = NULL; + print_columns = g_new (gint, 2); + print_columns[0] = 1; + print_columns[1] = 0; } if (n_columns == 0) { @@ -491,7 +491,7 @@ static void zenity_tree_dialog_get_selected (GtkTreeModel *model, GtkTreePath *path_buf, GtkTreeIter *iter, GtkTreeView *tree_view) { GValue value = {0, }; - gint n_columns, print_column, i; + gint n_columns, i; n_columns = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tree_view), "n_columns")); @@ -505,15 +505,11 @@ zenity_tree_dialog_get_selected (GtkTreeModel *model, GtkTreePath *path_buf, Gtk return; } - for (i = 0; print_columns[i] != NULL; i++) { - 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); + for (i = 0; print_columns[i] != 0; i++) { + gtk_tree_model_get_value (model, iter, print_columns[i] - 1, &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); } } @@ -541,18 +537,16 @@ zenity_tree_dialog_toggle_get_selected (GtkTreeModel *model, GtkTreePath *path, return FALSE; } - for (i = 0; print_columns[i] != NULL; i++) { - print_column = atoi (print_columns[i]); + for (i = 0; print_columns[i] != 0; i++) { + gtk_tree_model_get_value (model, iter, print_columns[i], &value); - 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))); - g_value_unset (&value); - } + selected = g_slist_append (selected, g_strdup (g_value_get_string (&value))); + g_value_unset (&value); } } + g_value_unset (&toggle_value); + return FALSE; } @@ -569,7 +563,7 @@ zenity_tree_dialog_output (void) g_print ("%s\n", (gchar *) tmp->data); } - g_strfreev (print_columns); + g_free (print_columns); g_free (separator); g_slist_foreach (selected, (GFunc) g_free, NULL); selected = NULL; @@ -632,3 +626,31 @@ zenity_tree_row_activated (GtkTreeView *tree_view, GtkTreePath *tree_path, zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK); gtk_main_quit (); } + +static gint * +zenity_tree_extract_column_indexes (char *indexes, int n_columns) +{ + char **tmp; + gint *result; + gint i, j, index; + + tmp = g_strsplit (indexes, + PRINT_HIDE_COLUMN_SEPARATOR, 0); + + result = g_new (gint, 1); + + for (j = i = 0; tmp[i] != NULL; i++) { + index = atoi (tmp[i]); + + if (index > 0 && index <= n_columns) { + result[j] = index; + j++; + g_renew (gint, result, j + 1); + } + } + result[j] = 0; + + g_strfreev (tmp); + + return result; +} -- cgit From 8ba040f33b37ef92976b75be79a1a342bceb91f9 Mon Sep 17 00:00:00 2001 From: Lucas Almeida Rocha Date: Fri, 1 Jul 2005 21:28:36 +0000 Subject: New --hide-column option. --- src/tree.c | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index ea2ba9e4..57e81285 100644 --- a/src/tree.c +++ b/src/tree.c @@ -37,8 +37,10 @@ static GSList *selected; static gchar *separator; static gboolean print_all_columns = FALSE; static gint *print_columns = NULL; +static gint *hide_columns = NULL; static int *zenity_tree_extract_column_indexes (char *indexes, gint n_columns); +static gboolean zenity_tree_column_is_hidden (gint column_index); static void zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer data); static void zenity_tree_row_activated (GtkTreeView *tree_view, GtkTreePath *tree_path, GtkTreeViewColumn *tree_col, gpointer data); @@ -309,6 +311,9 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) print_columns[1] = 0; } + if (tree_data->hide_column) + hide_columns = zenity_tree_extract_column_indexes (tree_data->hide_column, n_columns); + if (n_columns == 0) { g_printerr (_("No column titles specified for List dialog.\n")); data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR); @@ -421,18 +426,20 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) "text", column_index, "editable", n_columns, NULL); - } - else { - column = gtk_tree_view_column_new_with_attributes (tmp->data, - gtk_cell_renderer_text_new (), - "text", column_index, - NULL); - } + } + else { + column = gtk_tree_view_column_new_with_attributes (tmp->data, + gtk_cell_renderer_text_new (), + "text", column_index, + NULL); + } gtk_tree_view_column_set_sort_column_id (column, column_index); gtk_tree_view_column_set_resizable (column, TRUE); } - + if (zenity_tree_column_is_hidden (1)) + gtk_tree_view_column_set_visible (column, FALSE); + first_column = TRUE; } else { @@ -459,6 +466,9 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) gtk_tree_view_column_set_sort_column_id (column, column_index); gtk_tree_view_column_set_resizable (column, TRUE); + + if (zenity_tree_column_is_hidden (column_index + 1)) + gtk_tree_view_column_set_visible (column, FALSE); } gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column); @@ -564,6 +574,7 @@ zenity_tree_dialog_output (void) } g_free (print_columns); + g_free (hide_columns); g_free (separator); g_slist_foreach (selected, (GFunc) g_free, NULL); selected = NULL; @@ -627,6 +638,19 @@ zenity_tree_row_activated (GtkTreeView *tree_view, GtkTreePath *tree_path, gtk_main_quit (); } +static gboolean +zenity_tree_column_is_hidden (gint column_index) +{ + gint i; + + if (hide_columns != NULL) + for (i = 0; hide_columns[i] != 0; i++) + if (hide_columns[i] == column_index) + return TRUE; + + return FALSE; +} + static gint * zenity_tree_extract_column_indexes (char *indexes, int n_columns) { -- cgit From 4c328078b6ff16a0ba648f53c3bee7a68fe4dbc5 Mon Sep 17 00:00:00 2001 From: Lucas Almeida Rocha Date: Wed, 6 Jul 2005 20:13:11 +0000 Subject: Include cleanups (config.h) --- src/tree.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index 57e81285..72a9b392 100644 --- a/src/tree.c +++ b/src/tree.c @@ -23,6 +23,8 @@ * Kristian Rietveld */ +#include "config.h" + #include #include #include -- cgit From 21f7bc6a54636c749cf5514e091feb68cc88907b Mon Sep 17 00:00:00 2001 From: Lucas Rocha Date: Fri, 8 Jul 2005 23:21:34 +0000 Subject: general code cleanups. Contribution from Benoît Dejean. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2005-07-08 Lucas Rocha * src/about.c, src/calendar.c, src/fileselection.c, src/option.c, src/progress.c, src/text.c, src/tree.c, src/util.c: general code cleanups. Contribution from Benoît Dejean. --- src/tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index 72a9b392..d6621c32 100644 --- a/src/tree.c +++ b/src/tree.c @@ -529,7 +529,7 @@ static gboolean zenity_tree_dialog_toggle_get_selected (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, GtkTreeView *tree_view) { GValue toggle_value = {0, }; - gint n_columns, print_column, i; + gint n_columns, i; n_columns = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tree_view), "n_columns")); -- cgit From 5547de9384430dfccb9c3c8a68badfa120760b4a Mon Sep 17 00:00:00 2001 From: Lucas Rocha Date: Tue, 15 Nov 2005 04:14:35 +0000 Subject: make it possible to add new lines and markup in the dialog text. 2005-11-15 Lucas Rocha * src/calendar.c, src/progress.c, src/tree.c: make it possible to add new lines and markup in the dialog text. --- src/tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index d6621c32..b3bb977c 100644 --- a/src/tree.c +++ b/src/tree.c @@ -341,7 +341,7 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) text = glade_xml_get_widget (glade_dialog, "zenity_tree_text"); if (tree_data->dialog_text) - gtk_label_set_text (GTK_LABEL (text), tree_data->dialog_text); + gtk_label_set_markup (GTK_LABEL (text), g_strcompress (tree_data->dialog_text)); zenity_util_set_window_icon (dialog, data->window_icon, ZENITY_IMAGE_FULLPATH ("zenity-list.png")); -- cgit From e97b6eeaebedf82788f7218e1b63d4e6c7478e92 Mon Sep 17 00:00:00 2001 From: Lucas Rocha Date: Mon, 17 Apr 2006 04:11:15 +0000 Subject: don't ignore return value from g_renew() (Fixes bug #338038). Patch from 2006-04-16 Lucas Rocha * src/tree.c (zenity_tree_extract_column_indexes): don't ignore return value from g_renew() (Fixes bug #338038). Patch from Behdad Esfahbod . --- src/tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index b3bb977c..0273e551 100644 --- a/src/tree.c +++ b/src/tree.c @@ -671,7 +671,7 @@ zenity_tree_extract_column_indexes (char *indexes, int n_columns) if (index > 0 && index <= n_columns) { result[j] = index; j++; - g_renew (gint, result, j + 1); + result = g_renew (gint, result, j + 1); } } result[j] = 0; -- cgit From 216ee62fe1c062a9fb87aa3ce2097e0f8d21a06e Mon Sep 17 00:00:00 2001 From: Lucas Rocha Date: Wed, 26 Jul 2006 23:17:04 +0000 Subject: fix small build warnings on 64-bit architectures (Fixes bug #344125). fix 2006-07-26 Lucas Rocha * src/tree.c (zenity_tree_fill_entries_from_stdin, zenity_tree): fix small build warnings on 64-bit architectures (Fixes bug #344125). * src/zenity.h: fix small build warning. --- src/tree.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index 0273e551..1e67f706 100644 --- a/src/tree.c +++ b/src/tree.c @@ -195,9 +195,9 @@ zenity_tree_fill_entries_from_stdin (GtkTreeView *tree_view, { GIOChannel *channel; - g_object_set_data (G_OBJECT (tree_view), "n_columns", (gint *) n_columns); - g_object_set_data (G_OBJECT (tree_view), "toggles", (gint *) toggles); - g_object_set_data (G_OBJECT (tree_view), "editable", (gint *) editable); + g_object_set_data (G_OBJECT (tree_view), "n_columns", GINT_TO_POINTER (n_columns)); + g_object_set_data (G_OBJECT (tree_view), "toggles", GINT_TO_POINTER (toggles)); + g_object_set_data (G_OBJECT (tree_view), "editable", GINT_TO_POINTER (editable)); channel = g_io_channel_unix_new (0); g_io_channel_set_encoding (channel, NULL, NULL); @@ -218,7 +218,7 @@ 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); + g_object_set_data (G_OBJECT (tree_view), "n_columns", GINT_TO_POINTER (n_columns)); while (args[i] != NULL) { gint j; @@ -403,7 +403,7 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) if (tree_data->radiobox) { g_object_set (G_OBJECT (cell_renderer), "radio", TRUE, NULL); - g_object_set_data (G_OBJECT (model), "radio", (gint *) 1); + g_object_set_data (G_OBJECT (model), "radio", GINT_TO_POINTER (1)); } g_signal_connect (cell_renderer, "toggled", @@ -421,7 +421,7 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) g_signal_connect (G_OBJECT (cell_renderer), "edited", G_CALLBACK (zenity_cell_edited_callback), gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view))); - g_object_set_data (G_OBJECT (cell_renderer), "column", (gint *) column_index); + g_object_set_data (G_OBJECT (cell_renderer), "column", GINT_TO_POINTER (column_index)); column = gtk_tree_view_column_new_with_attributes (tmp->data, cell_renderer, @@ -452,7 +452,7 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) g_signal_connect (G_OBJECT (cell_renderer), "edited", G_CALLBACK (zenity_cell_edited_callback), gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view))); - g_object_set_data (G_OBJECT (cell_renderer), "column", (gint *) column_index); + g_object_set_data (G_OBJECT (cell_renderer), "column", GINT_TO_POINTER (column_index)); column = gtk_tree_view_column_new_with_attributes (tmp->data, cell_renderer, -- cgit From a705262d816a7f2d9bdd5405f6c077b690219cef Mon Sep 17 00:00:00 2001 From: Lucas Rocha Date: Mon, 14 May 2007 22:07:13 +0000 Subject: fix index handling for --print-column (Fixes bug #420396). 2007-05-15 Lucas Rocha * src/tree.c (zenity_tree_dialog_toggle_get_selected): fix index handling for --print-column (Fixes bug #420396). svn path=/trunk/; revision=1211 --- src/tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index 1e67f706..09346e0a 100644 --- a/src/tree.c +++ b/src/tree.c @@ -550,7 +550,7 @@ zenity_tree_dialog_toggle_get_selected (GtkTreeModel *model, GtkTreePath *path, } for (i = 0; print_columns[i] != 0; i++) { - gtk_tree_model_get_value (model, iter, print_columns[i], &value); + gtk_tree_model_get_value (model, iter, print_columns[i] - 1, &value); selected = g_slist_append (selected, g_strdup (g_value_get_string (&value))); g_value_unset (&value); -- cgit From b2459f3b6e480ba8568084f4ed50d1634239b0ea Mon Sep 17 00:00:00 2001 From: Lucas Rocha Date: Sun, 27 May 2007 21:20:39 +0000 Subject: fix broken handling of input from pipes in list dialog (Fixes bug 2007-05-27 Lucas Rocha * src/tree.c: fix broken handling of input from pipes in list dialog (Fixes bug #343684). svn path=/trunk/; revision=1221 --- src/tree.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index 09346e0a..dafb2eb5 100644 --- a/src/tree.c +++ b/src/tree.c @@ -94,13 +94,13 @@ zenity_tree_handle_stdin (GIOChannel *channel, { static GtkTreeView *tree_view; GtkTreeModel *model; - GtkTreeIter iter; + static GtkTreeIter iter; static gint column_count = 0; static gint row_count = 0; static gint n_columns; static gboolean editable; static gboolean toggles; - static gboolean first_time = FALSE; + static gboolean first_time = TRUE; tree_view = GTK_TREE_VIEW (data); n_columns = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tree_view), "n_columns")); @@ -109,8 +109,8 @@ zenity_tree_handle_stdin (GIOChannel *channel, model = gtk_tree_view_get_model (tree_view); - if (!first_time) { - first_time = TRUE; + if (first_time) { + first_time = FALSE; gtk_list_store_append (GTK_LIST_STORE (model), &iter); } @@ -159,22 +159,22 @@ zenity_tree_handle_stdin (GIOChannel *channel, gtk_list_store_set (GTK_LIST_STORE (model), &iter, column_count, zenity_util_strip_newline (string->str), -1); } - if (editable) { - gtk_list_store_set (GTK_LIST_STORE (model), &iter, n_columns, TRUE, -1); - } + if (editable) { + gtk_list_store_set (GTK_LIST_STORE (model), &iter, n_columns, TRUE, -1); + } - if (row_count == MAX_ELEMENTS_BEFORE_SCROLLING) { - GtkWidget *scrolled_window; - GtkRequisition rectangle; + if (row_count == MAX_ELEMENTS_BEFORE_SCROLLING) { + GtkWidget *scrolled_window; + GtkRequisition rectangle; - gtk_widget_size_request (GTK_WIDGET (tree_view), &rectangle); - scrolled_window = glade_xml_get_widget (glade_dialog, "zenity_tree_window"); - gtk_widget_set_size_request (scrolled_window, -1, rectangle.height); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), - GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - } + gtk_widget_size_request (GTK_WIDGET (tree_view), &rectangle); + scrolled_window = glade_xml_get_widget (glade_dialog, "zenity_tree_window"); + gtk_widget_set_size_request (scrolled_window, -1, rectangle.height); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), + GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + } - column_count ++; + column_count++; } while (g_io_channel_get_buffer_condition (channel) == G_IO_IN); g_string_free (string, TRUE); -- cgit From ae3e8d1496fcfc3bf2ca65e475455bbf4c935e50 Mon Sep 17 00:00:00 2001 From: Lucas Rocha Date: Mon, 13 Aug 2007 20:16:37 +0000 Subject: fix critical warning when using checkbox and radiobox in list dialog 2007-08-13 Lucas Rocha * src/tree.c: fix critical warning when using checkbox and radiobox in list dialog (Fixes bug #453713). svn path=/trunk/; revision=1230 --- src/tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index dafb2eb5..254ac0e7 100644 --- a/src/tree.c +++ b/src/tree.c @@ -309,7 +309,7 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) } else { print_columns = g_new (gint, 2); - print_columns[0] = 1; + print_columns[0] = (tree_data->radiobox || tree_data->checkbox ? 2 : 1); print_columns[1] = 0; } -- cgit From 8b16d4d4122e6337517ec16b9ca22dd27df0dafb Mon Sep 17 00:00:00 2001 From: Lucas Rocha Date: Mon, 13 Aug 2007 20:36:29 +0000 Subject: added timeout option to all dialogs (Fixes bug #160654). Based on patch 2007-08-13 Lucas Rocha * src/*.c: added timeout option to all dialogs (Fixes bug #160654). Based on patch from Muthiah Annamalai . svn path=/trunk/; revision=1231 --- src/tree.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index 254ac0e7..6dd3f645 100644 --- a/src/tree.c +++ b/src/tree.c @@ -493,6 +493,11 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) } zenity_util_show_dialog (dialog); + + if(data->timeout_delay > 0) { + g_timeout_add (data->timeout_delay * 1000, (GSourceFunc) zenity_util_timeout_handle, NULL); + } + gtk_main (); if (glade_dialog) -- cgit From a740e32652506eb82fd2a20623dd996ed3bd1ae7 Mon Sep 17 00:00:00 2001 From: Lucas Rocha Date: Thu, 10 Apr 2008 09:57:14 +0000 Subject: use g_value_dup_string when applicable (Fixes bug #527258). Patch from 2008-04-10 Lucas Rocha * src/tree.c (zenity_tree_dialog_get_selected, zenity_tree_dialog_toggle_get_selected): use g_value_dup_string when applicable (Fixes bug #527258). Patch from kraai@ftbfs.org. svn path=/trunk/; revision=1352 --- src/tree.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index 6dd3f645..65e9c471 100644 --- a/src/tree.c +++ b/src/tree.c @@ -516,7 +516,7 @@ zenity_tree_dialog_get_selected (GtkTreeModel *model, GtkTreePath *path_buf, Gtk 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_value_dup_string (&value)); g_value_unset (&value); } return; @@ -525,7 +525,7 @@ zenity_tree_dialog_get_selected (GtkTreeModel *model, GtkTreePath *path_buf, Gtk for (i = 0; print_columns[i] != 0; i++) { gtk_tree_model_get_value (model, iter, print_columns[i] - 1, &value); - selected = g_slist_append (selected, g_strdup (g_value_get_string (&value))); + selected = g_slist_append (selected, g_value_dup_string (&value)); g_value_unset (&value); } } @@ -547,7 +547,7 @@ zenity_tree_dialog_toggle_get_selected (GtkTreeModel *model, GtkTreePath *path, 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_value_dup_string (&value)); g_value_unset (&value); } g_value_unset (&toggle_value); @@ -557,7 +557,7 @@ zenity_tree_dialog_toggle_get_selected (GtkTreeModel *model, GtkTreePath *path, for (i = 0; print_columns[i] != 0; i++) { gtk_tree_model_get_value (model, iter, print_columns[i] - 1, &value); - selected = g_slist_append (selected, g_strdup (g_value_get_string (&value))); + selected = g_slist_append (selected, g_value_dup_string (&value)); g_value_unset (&value); } } -- cgit From ba29edd13497fac1414d9dacd9f1ad147ac716ad Mon Sep 17 00:00:00 2001 From: Lucas Rocha Date: Fri, 9 Jan 2009 00:14:01 +0000 Subject: GNOME Goal: Remove deprecated GLib symbols (Fixes bug #560452). Patch from 2009-01-09 Lucas Rocha * src/tree.c: GNOME Goal: Remove deprecated GLib symbols (Fixes bug #560452). Patch from Frederic Peters . svn path=/trunk/; revision=1463 --- src/tree.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index 65e9c471..3237cded 100644 --- a/src/tree.c +++ b/src/tree.c @@ -150,7 +150,7 @@ zenity_tree_handle_stdin (GIOChannel *channel, } if (toggles && column_count == 0) { - if (strcmp (g_strdown (zenity_util_strip_newline (string->str)), "true") == 0) + if (strcmp (g_ascii_strdown (zenity_util_strip_newline (string->str), -1), "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); @@ -228,7 +228,7 @@ zenity_tree_fill_entries (GtkTreeView *tree_view, for (j = 0; j < n_columns; j++) { if (toggles && j == 0) { - if (strcmp (g_strdown ((gchar *) args[i+j]), "true") == 0) + if (strcmp (g_ascii_strdown ((gchar *) args[i+j], -1), "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); @@ -302,7 +302,7 @@ 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) + if (strcmp (g_ascii_strdown (tree_data->print_column, -1), "all") == 0) print_all_columns = TRUE; else print_columns = zenity_tree_extract_column_indexes (tree_data->print_column, n_columns); -- cgit From 3f33966167cf2216f813c091d47461c451837602 Mon Sep 17 00:00:00 2001 From: Felix Riemann Date: Mon, 20 Jul 2009 10:23:32 +0200 Subject: Bug 578393 – convert from libglade to GtkBuilder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/tree.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index 3237cded..da2cf474 100644 --- a/src/tree.c +++ b/src/tree.c @@ -25,7 +25,6 @@ #include "config.h" -#include #include #include #include "zenity.h" @@ -34,7 +33,7 @@ #define MAX_ELEMENTS_BEFORE_SCROLLING 5 #define PRINT_HIDE_COLUMN_SEPARATOR "," -static GladeXML *glade_dialog; +static GtkBuilder *builder; static GSList *selected; static gchar *separator; static gboolean print_all_columns = FALSE; @@ -168,7 +167,8 @@ zenity_tree_handle_stdin (GIOChannel *channel, GtkRequisition rectangle; gtk_widget_size_request (GTK_WIDGET (tree_view), &rectangle); - scrolled_window = glade_xml_get_widget (glade_dialog, "zenity_tree_window"); + scrolled_window = GTK_WIDGET (gtk_builder_get_object (builder, + "zenity_tree_window")); gtk_widget_set_size_request (scrolled_window, -1, rectangle.height); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); @@ -245,7 +245,8 @@ zenity_tree_fill_entries (GtkTreeView *tree_view, GtkRequisition rectangle; gtk_widget_size_request (GTK_WIDGET (tree_view), &rectangle); - scrolled_window = glade_xml_get_widget (glade_dialog, "zenity_tree_window"); + scrolled_window = GTK_WIDGET (gtk_builder_get_object (builder, + "zenity_tree_window")); gtk_widget_set_size_request (scrolled_window, -1, rectangle.height); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); @@ -281,8 +282,8 @@ void zenity_tree (ZenityData *data, ZenityTreeData *tree_data) { GtkWidget *dialog; - GtkWidget *tree_view; - GtkWidget *text; + GObject *tree_view; + GObject *text; GtkTreeViewColumn *column; GtkListStore *model; GType *column_types; @@ -290,9 +291,9 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) gboolean first_column = FALSE; gint i, column_index, n_columns; - glade_dialog = zenity_util_load_glade_file ("zenity_tree_dialog"); + builder = zenity_util_load_ui_file ("zenity_tree_dialog", NULL); - if (glade_dialog == NULL) { + if (builder == NULL) { data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR); return; } @@ -328,9 +329,9 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) return; } - glade_xml_signal_autoconnect (glade_dialog); + gtk_builder_connect_signals (builder, NULL); - dialog = glade_xml_get_widget (glade_dialog, "zenity_tree_dialog"); + dialog = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_tree_dialog")); g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK (zenity_tree_dialog_response), data); @@ -338,7 +339,7 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) if (data->dialog_title) gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title); - text = glade_xml_get_widget (glade_dialog, "zenity_tree_text"); + text = gtk_builder_get_object (builder, "zenity_tree_text"); if (tree_data->dialog_text) gtk_label_set_markup (GTK_LABEL (text), g_strcompress (tree_data->dialog_text)); @@ -348,10 +349,10 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) if (data->width > -1 || data->height > -1) gtk_window_set_default_size (GTK_WINDOW (dialog), data->width, data->height); - tree_view = glade_xml_get_widget (glade_dialog, "zenity_tree_view"); + tree_view = gtk_builder_get_object (builder, "zenity_tree_view"); if (!(tree_data->radiobox || tree_data->checkbox)) - g_signal_connect (G_OBJECT (tree_view), "row-activated", + g_signal_connect (tree_view, "row-activated", G_CALLBACK (zenity_tree_row_activated), data); /* Create an empty list store */ @@ -500,8 +501,7 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) gtk_main (); - if (glade_dialog) - g_object_unref (glade_dialog); + g_object_unref (builder); } static void @@ -591,13 +591,13 @@ static void zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer data) { ZenityData *zen_data = data; - GtkWidget *tree_view; + GObject *tree_view; GtkTreeSelection *selection; GtkTreeModel *model; switch (response) { case GTK_RESPONSE_OK: - tree_view = glade_xml_get_widget (glade_dialog, "zenity_tree_view"); + tree_view = gtk_builder_get_object (builder, "zenity_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) -- cgit From 8e190dbb1f39eae31210f7d4c97a4c5ebb496907 Mon Sep 17 00:00:00 2001 From: Bryce Harrington Date: Mon, 10 Aug 2009 04:10:53 +0100 Subject: Bug 552971 - Add a hide-header option to list dialog --- src/tree.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index da2cf474..f0fc1873 100644 --- a/src/tree.c +++ b/src/tree.c @@ -480,6 +480,9 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (tree_view), TRUE); + if (tree_data->hide_header) + gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (tree_view), FALSE); + if (tree_data->radiobox || tree_data->checkbox) { if (tree_data->data && *tree_data->data) zenity_tree_fill_entries (GTK_TREE_VIEW (tree_view), tree_data->data, n_columns, TRUE, tree_data->editable); -- cgit From cf0f0b1668d4a20f86eb30af290a7a136563f11c Mon Sep 17 00:00:00 2001 From: Lucas Rocha Date: Wed, 16 Sep 2009 21:30:46 +0100 Subject: [list] allow escaped chars as separator --- src/tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index f0fc1873..63287e36 100644 --- a/src/tree.c +++ b/src/tree.c @@ -298,7 +298,7 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) return; } - separator = g_strdup (tree_data->separator); + separator = g_strcompress (tree_data->separator); n_columns = g_slist_length (tree_data->columns); -- cgit From 1570a2bbf07627cb5f8d9828a95db67b7d00634c Mon Sep 17 00:00:00 2001 From: Philippe Gauthier Date: Fri, 30 Oct 2009 14:51:16 -0400 Subject: Use g_timeout_add_seconds instead g_timeout_add The calls to g_timeout_add are replaced with g_timeout_add_seconds to reduce the number or program wake ups. See the GNOME Goal description: http://live.gnome.org/GnomeGoals/UseTimeoutAddSeconds --- src/tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index 63287e36..3861e863 100644 --- a/src/tree.c +++ b/src/tree.c @@ -499,7 +499,7 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) zenity_util_show_dialog (dialog); if(data->timeout_delay > 0) { - g_timeout_add (data->timeout_delay * 1000, (GSourceFunc) zenity_util_timeout_handle, NULL); + g_timeout_add_seconds (data->timeout_delay, (GSourceFunc) zenity_util_timeout_handle, NULL); } gtk_main (); -- cgit From ef3a33a142620fee850351d14f4a1c191fc6e273 Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Sun, 2 Jan 2011 22:57:42 -0200 Subject: Fix for bug 540560. Patch by Victor Ananjevsky --- src/tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index 3861e863..7b466674 100644 --- a/src/tree.c +++ b/src/tree.c @@ -180,7 +180,7 @@ zenity_tree_handle_stdin (GIOChannel *channel, g_string_free (string, TRUE); } - if (condition != G_IO_IN) { + if ((condition != G_IO_IN) && (condition != G_IO_IN + G_IO_HUP)) { g_io_channel_shutdown (channel, TRUE, NULL); return FALSE; } -- cgit From b39ad33c35bb93c647e7f6f05d1310a0ce6895d5 Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Thu, 16 Jun 2011 11:07:58 -0300 Subject: Bug 651948 - zenity list does not return default value when timeout is over --- src/tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index 7b466674..c7477c36 100644 --- a/src/tree.c +++ b/src/tree.c @@ -499,7 +499,7 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) zenity_util_show_dialog (dialog); if(data->timeout_delay > 0) { - g_timeout_add_seconds (data->timeout_delay, (GSourceFunc) zenity_util_timeout_handle, NULL); + g_timeout_add_seconds (data->timeout_delay, (GSourceFunc) zenity_util_timeout_handle, dialog); } gtk_main (); -- cgit From d60e5eeeb379e5444ad218d7335b17eaa821b182 Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Fri, 17 Jun 2011 10:47:07 -0300 Subject: Now if you use --timeout option, the return code will be properly handled The default behavior will be done (ie. user click on ok button) The return code will be 5 --- src/tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index c7477c36..b0ff4c5f 100644 --- a/src/tree.c +++ b/src/tree.c @@ -613,7 +613,7 @@ zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer data) GTK_TREE_VIEW (tree_view)); } zenity_tree_dialog_output (); - zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK); + zenity_util_exit_code_with_data(ZENITY_OK, zen_data); break; case GTK_RESPONSE_CANCEL: -- cgit From 9ab8380ff217cf6162ef4be7a473bb7a34b4d104 Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Fri, 8 Jul 2011 11:57:18 -0300 Subject: Fix for bug #540489 and #501001 both related to 100% use of cpu. --- src/tree.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index b0ff4c5f..cdc1599c 100644 --- a/src/tree.c +++ b/src/tree.c @@ -130,6 +130,9 @@ zenity_tree_handle_stdin (GIOChannel *channel, while (gtk_events_pending ()) gtk_main_iteration (); + // TODO: Find a better way to avoid 100% cpu utilization + g_usleep(10000); + } while (status == G_IO_STATUS_AGAIN); if (status != G_IO_STATUS_NORMAL) { -- cgit From 7a34df3041844918e2a0c5c44cb5601cff4c451a Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Tue, 26 Jul 2011 10:08:31 -0300 Subject: Bug #592195. This fix made the --list mode return as soon as receive an ok or cancel response avoiding crash. --- src/tree.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index cdc1599c..c15f502e 100644 --- a/src/tree.c +++ b/src/tree.c @@ -39,6 +39,7 @@ static gchar *separator; static gboolean print_all_columns = FALSE; static gint *print_columns = NULL; static gint *hide_columns = NULL; +static GIOChannel *channel; static int *zenity_tree_extract_column_indexes (char *indexes, gint n_columns); static gboolean zenity_tree_column_is_hidden (gint column_index); @@ -125,7 +126,10 @@ zenity_tree_handle_stdin (GIOChannel *channel, gint status; do { - status = g_io_channel_read_line_string (channel, string, NULL, &error); + if (channel->is_readable == TRUE) + status = g_io_channel_read_line_string (channel, string, NULL, &error); + else + return FALSE; while (gtk_events_pending ()) gtk_main_iteration (); @@ -196,8 +200,6 @@ zenity_tree_fill_entries_from_stdin (GtkTreeView *tree_view, gboolean toggles, gboolean editable) { - GIOChannel *channel; - g_object_set_data (G_OBJECT (tree_view), "n_columns", GINT_TO_POINTER (n_columns)); g_object_set_data (G_OBJECT (tree_view), "toggles", GINT_TO_POINTER (toggles)); g_object_set_data (G_OBJECT (tree_view), "editable", GINT_TO_POINTER (editable)); @@ -628,6 +630,9 @@ zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer data) zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC); break; } + if (channel != NULL) + g_io_channel_shutdown (channel, TRUE, NULL); + gtk_main_quit (); } -- cgit From 6768a40e997697d05008aecdb41815e1dbae61c6 Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Tue, 26 Jul 2011 14:00:28 -0300 Subject: Fix for bug #611297 Now Zenity have --ok-label and --cancel-label in all dialogs. This patch doesn't break old zenity scripts. --- src/tree.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index c15f502e..10d8946b 100644 --- a/src/tree.c +++ b/src/tree.c @@ -287,6 +287,7 @@ void zenity_tree (ZenityData *data, ZenityTreeData *tree_data) { GtkWidget *dialog; + GtkWidget *button; GObject *tree_view; GObject *text; GtkTreeViewColumn *column; @@ -344,6 +345,20 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) if (data->dialog_title) gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title); + if (data->ok_label) { + button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_tree_ok_button")); + gtk_button_set_label (GTK_BUTTON (button), data->ok_label); + gtk_button_set_image (GTK_BUTTON (button), + gtk_image_new_from_stock (GTK_STOCK_OK, GTK_ICON_SIZE_BUTTON)); + } + + if (data->cancel_label) { + button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_tree_cancel_button")); + gtk_button_set_label (GTK_BUTTON (button), data->cancel_label); + gtk_button_set_image (GTK_BUTTON (button), + gtk_image_new_from_stock (GTK_STOCK_CANCEL, GTK_ICON_SIZE_BUTTON)); + } + text = gtk_builder_get_object (builder, "zenity_tree_text"); if (tree_data->dialog_text) -- cgit From fd165dfe195375f66d5d97b97a2d3ab22c0bb633 Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Mon, 30 Jan 2012 15:56:23 -0200 Subject: Bug #668935 - the channel was being freed twice. --- src/tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index 10d8946b..ad4a6d14 100644 --- a/src/tree.c +++ b/src/tree.c @@ -645,7 +645,7 @@ zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer data) zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC); break; } - if (channel != NULL) + if (channel->is_readable == TRUE) g_io_channel_shutdown (channel, TRUE, NULL); gtk_main_quit (); -- cgit From 4a30be17b3adfd7b8383f5c23fae71e31933326b Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Tue, 17 Apr 2012 16:50:52 -0300 Subject: Bug #673529 Fix segmentation fault in --list option --- src/tree.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index ad4a6d14..721817ec 100644 --- a/src/tree.c +++ b/src/tree.c @@ -120,13 +120,13 @@ zenity_tree_handle_stdin (GIOChannel *channel, string = g_string_new (NULL); - while (channel->is_readable != TRUE) + while (g_io_channel_get_flags(channel) != G_IO_FLAG_IS_READABLE) ; do { gint status; do { - if (channel->is_readable == TRUE) + if (g_io_channel_get_flags(channel) == G_IO_FLAG_IS_READABLE) status = g_io_channel_read_line_string (channel, string, NULL, &error); else return FALSE; @@ -645,7 +645,7 @@ zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer data) zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC); break; } - if (channel->is_readable == TRUE) + if (channel != NULL && g_io_channel_get_flags (channel) == G_IO_FLAG_IS_READABLE) g_io_channel_shutdown (channel, TRUE, NULL); gtk_main_quit (); -- cgit From 127c298ac43cbdf3b965002e7e9115571ca1d90d Mon Sep 17 00:00:00 2001 From: Julian Taylor Date: Tue, 8 May 2012 22:14:58 +0200 Subject: mask the result of g_io_channel_get_flags for the wanted flag --- src/tree.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index 721817ec..b347b158 100644 --- a/src/tree.c +++ b/src/tree.c @@ -120,13 +120,13 @@ zenity_tree_handle_stdin (GIOChannel *channel, string = g_string_new (NULL); - while (g_io_channel_get_flags(channel) != G_IO_FLAG_IS_READABLE) + while ((g_io_channel_get_flags(channel) & G_IO_FLAG_IS_READABLE) != G_IO_FLAG_IS_READABLE) ; do { gint status; do { - if (g_io_channel_get_flags(channel) == G_IO_FLAG_IS_READABLE) + if (g_io_channel_get_flags(channel) & G_IO_FLAG_IS_READABLE) status = g_io_channel_read_line_string (channel, string, NULL, &error); else return FALSE; @@ -645,7 +645,7 @@ zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer data) zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC); break; } - if (channel != NULL && g_io_channel_get_flags (channel) == G_IO_FLAG_IS_READABLE) + if (channel != NULL && g_io_channel_get_flags (channel) & G_IO_FLAG_IS_READABLE) g_io_channel_shutdown (channel, TRUE, NULL); gtk_main_quit (); -- cgit From c17eff5863009c69196e92520b150643f1f7937d Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Thu, 19 Jul 2012 14:22:25 -0300 Subject: Added support to --imagelist on tree. Thanks to Joshua Nathaniel Pritikin now the first column can have an image. --- src/tree.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 6 deletions(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index b347b158..4234fc1a 100644 --- a/src/tree.c +++ b/src/tree.c @@ -87,6 +87,44 @@ zenity_tree_toggled_callback (GtkCellRendererToggle *cell, gchar *path_string, g gtk_tree_path_free (path); } +static void +zenity_load_pixbuf (GtkTreeViewColumn *tree_column, + GtkCellRenderer *cell, + GtkTreeModel *tree_model, + GtkTreeIter *iter, + gpointer data) +{ + static GHashTable *pixbuf_cache = NULL; + GError *error = NULL; + GdkPixbuf *pixbuf; + gchar *str; + + gtk_tree_model_get (tree_model, iter, 0, &str, -1); + + if (!str) + return; + + if (!pixbuf_cache) { + pixbuf_cache = g_hash_table_new (g_str_hash, g_str_equal); + g_assert(pixbuf_cache); + } + + pixbuf = g_hash_table_lookup (pixbuf_cache, str); + + if (!pixbuf) { + pixbuf = gdk_pixbuf_new_from_file (str, &error); + if (!pixbuf) + g_warning ("Failed to load '%s'", str); + + g_hash_table_insert (pixbuf_cache, g_strdup (str), pixbuf); + } + + if (pixbuf) + g_object_set (cell, "pixbuf", pixbuf, NULL); + + g_free (str); +} + static gboolean zenity_tree_handle_stdin (GIOChannel *channel, GIOCondition condition, @@ -249,7 +287,7 @@ zenity_tree_fill_entries (GtkTreeView *tree_view, GtkWidget *scrolled_window; GtkRequisition rectangle; - gtk_widget_size_request (GTK_WIDGET (tree_view), &rectangle); + gtk_widget_get_preferred_size (GTK_WIDGET (tree_view), &rectangle, NULL); scrolled_window = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_tree_window")); gtk_widget_set_size_request (scrolled_window, -1, rectangle.height); @@ -329,7 +367,7 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) return; } - if (tree_data->checkbox && tree_data->radiobox) { + if (tree_data->checkbox + tree_data->radiobox + tree_data->imagebox > 1) { g_printerr (_("You should use only one List dialog type.\n")); data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR); return; @@ -433,6 +471,12 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) column = gtk_tree_view_column_new_with_attributes (tmp->data, cell_renderer, "active", column_index, NULL); + } else if (tree_data->imagebox) { + GtkCellRenderer *cell_renderer = gtk_cell_renderer_pixbuf_new (); + column = gtk_tree_view_column_new_with_attributes (tmp->data, + cell_renderer, NULL); + gtk_tree_view_column_set_cell_data_func (column, cell_renderer, + zenity_load_pixbuf, NULL, NULL); } else { if (tree_data->editable) { @@ -657,10 +701,7 @@ zenity_tree_row_activated (GtkTreeView *tree_view, GtkTreePath *tree_path, { ZenityData *zen_data = data; GtkTreeSelection *selection; - GtkTreeModel *model; - - model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view)); - + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)); gtk_tree_selection_selected_foreach (selection, (GtkTreeSelectionForeachFunc) zenity_tree_dialog_get_selected, -- cgit From 0628bd3291aad936b6b553366600590cca360bfa Mon Sep 17 00:00:00 2001 From: Florian Müllner Date: Tue, 18 Sep 2012 18:33:07 +0200 Subject: util: Add an option to request dialogs being modal As WMs cannot open windows themselves, Mutter uses zenity to open "Force Quit" dialogs for unresponsive windows; as those are strongly tied to the corresponding window, it makes sense to make them modal (in particular when attaching them to their parent). https://bugzilla.gnome.org/show_bug.cgi?id=684322 --- src/tree.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index 4234fc1a..c1a20d0f 100644 --- a/src/tree.c +++ b/src/tree.c @@ -383,6 +383,9 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) if (data->dialog_title) gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title); + if (data->modal) + gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); + if (data->ok_label) { button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_tree_ok_button")); gtk_button_set_label (GTK_BUTTON (button), data->ok_label); -- cgit From 1ac1da63f8de626ce10d350be7b29744a743ec95 Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Tue, 5 Mar 2013 16:56:24 -0300 Subject: But #674881 - Timeout option overriding normal exit code --- src/tree.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index c1a20d0f..cf902391 100644 --- a/src/tree.c +++ b/src/tree.c @@ -640,6 +640,23 @@ zenity_tree_dialog_toggle_get_selected (GtkTreeModel *model, GtkTreePath *path, static void zenity_tree_dialog_output (void) { +GObject *tree_view; + GtkTreeSelection *selection; + GtkTreeModel *model; + + tree_view = gtk_builder_get_object (builder, "zenity_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) + 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, + (GtkTreeSelectionForeachFunc) zenity_tree_dialog_get_selected, + GTK_TREE_VIEW (tree_view)); + } + GSList *tmp; for (tmp = selected; tmp; tmp = tmp->next) { @@ -661,24 +678,9 @@ static void zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer data) { ZenityData *zen_data = data; - GObject *tree_view; - GtkTreeSelection *selection; - GtkTreeModel *model; switch (response) { case GTK_RESPONSE_OK: - tree_view = gtk_builder_get_object (builder, "zenity_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) - 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, - (GtkTreeSelectionForeachFunc) zenity_tree_dialog_get_selected, - GTK_TREE_VIEW (tree_view)); - } zenity_tree_dialog_output (); zenity_util_exit_code_with_data(ZENITY_OK, zen_data); break; @@ -687,6 +689,11 @@ zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer data) zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL); break; + case ZENITY_TIMEOUT: + zenity_tree_dialog_output (); + zen_data->exit_code = zenity_util_return_exit_code (ZENITY_TIMEOUT); + break; + default: /* Esc dialog */ zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC); -- cgit From 7c234ed9b71d5f009abff509ef2bf576f61a0cbb Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Thu, 23 May 2013 16:27:58 -0300 Subject: Bug 698683 - Double clicking an item or hitting enter after selecting an item returns it twice --- src/tree.c | 6 ------ 1 file changed, 6 deletions(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index cf902391..031765e4 100644 --- a/src/tree.c +++ b/src/tree.c @@ -710,12 +710,6 @@ zenity_tree_row_activated (GtkTreeView *tree_view, GtkTreePath *tree_path, GtkTreeViewColumn *tree_col, gpointer data) { ZenityData *zen_data = data; - GtkTreeSelection *selection; - - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)); - gtk_tree_selection_selected_foreach (selection, - (GtkTreeSelectionForeachFunc) zenity_tree_dialog_get_selected, - GTK_TREE_VIEW (tree_view)); zenity_tree_dialog_output (); zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK); -- cgit From c89ce9c3812fdc3a2637fd76b42a07385ad50684 Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Tue, 4 Jun 2013 16:27:48 -0300 Subject: Bug #653468. Fixed by Kurt Miller . Fix the broken auto-close option in progress and list dialogs. --- src/tree.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index 031765e4..4634ba12 100644 --- a/src/tree.c +++ b/src/tree.c @@ -139,6 +139,7 @@ zenity_tree_handle_stdin (GIOChannel *channel, static gboolean editable; static gboolean toggles; static gboolean first_time = TRUE; + GIOStatus status = G_IO_STATUS_NORMAL; tree_view = GTK_TREE_VIEW (data); n_columns = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tree_view), "n_columns")); @@ -152,7 +153,7 @@ zenity_tree_handle_stdin (GIOChannel *channel, gtk_list_store_append (GTK_LIST_STORE (model), &iter); } - if ((condition == G_IO_IN) || (condition == G_IO_IN + G_IO_HUP)) { + if ((condition & G_IO_IN) == G_IO_IN) { GString *string; GError *error = NULL; @@ -161,8 +162,6 @@ zenity_tree_handle_stdin (GIOChannel *channel, while ((g_io_channel_get_flags(channel) & G_IO_FLAG_IS_READABLE) != G_IO_FLAG_IS_READABLE) ; do { - gint status; - do { if (g_io_channel_get_flags(channel) & G_IO_FLAG_IS_READABLE) status = g_io_channel_read_line_string (channel, string, NULL, &error); @@ -221,11 +220,11 @@ zenity_tree_handle_stdin (GIOChannel *channel, column_count++; - } while (g_io_channel_get_buffer_condition (channel) == G_IO_IN); + } while ((g_io_channel_get_buffer_condition (channel) & G_IO_IN) == G_IO_IN && status != G_IO_STATUS_EOF); g_string_free (string, TRUE); } - if ((condition != G_IO_IN) && (condition != G_IO_IN + G_IO_HUP)) { + if ((condition & G_IO_IN) != G_IO_IN || status == G_IO_STATUS_EOF) { g_io_channel_shutdown (channel, TRUE, NULL); return FALSE; } -- cgit From 009523d5da827392b027ac6da1a50f94314e3a35 Mon Sep 17 00:00:00 2001 From: Weitian Leung Date: Fri, 23 Aug 2013 09:15:07 +0800 Subject: added attach option for transient window --- src/tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index 4634ba12..a8b324f7 100644 --- a/src/tree.c +++ b/src/tree.c @@ -562,7 +562,7 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) zenity_tree_fill_entries_from_stdin (GTK_TREE_VIEW (tree_view), n_columns, FALSE, tree_data->editable); } - zenity_util_show_dialog (dialog); + zenity_util_show_dialog (dialog, data->attach); if(data->timeout_delay > 0) { g_timeout_add_seconds (data->timeout_delay, (GSourceFunc) zenity_util_timeout_handle, dialog); -- cgit From 15e2759668a1d17bb1570a890bf294aaa796cbf5 Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Tue, 21 Oct 2014 18:30:35 +0200 Subject: Bug #685051 Adding --mid-search option to --list This will enable users to find a row with a text matching the middle of the row. Consider the following list: Little piggy one Little piggy two Little piggy three As a user I would expect that entering 'th' would focus the last row, because it's the first one that contains 'th' --- src/tree.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index a8b324f7..819f9a8e 100644 --- a/src/tree.c +++ b/src/tree.c @@ -298,6 +298,17 @@ zenity_tree_fill_entries (GtkTreeView *tree_view, } } +static gboolean +zenity_mid_search_func (GtkTreeModel *model, gint column, + const gchar *key, GtkTreeIter *iter, + gpointer search_data) +{ + gchar *iter_string = NULL; + gtk_tree_model_get (model, iter, column, &iter_string, -1); + return ! g_strrstr (g_utf8_strdown(iter_string, -1), + g_utf8_strdown(key, -1)) != NULL; +} + static void zenity_cell_edited_callback (GtkCellRendererText *cell, const gchar *path_string, @@ -564,6 +575,9 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) zenity_util_show_dialog (dialog, data->attach); + if (tree_data->mid_search) + gtk_tree_view_set_search_equal_func(GTK_TREE_VIEW(tree_view), (GtkTreeViewSearchEqualFunc) zenity_mid_search_func, model, NULL); + if(data->timeout_delay > 0) { g_timeout_add_seconds (data->timeout_delay, (GSourceFunc) zenity_util_timeout_handle, dialog); } -- cgit From 6fcbb80fd1b5268fbedcdb985ffa873a2e475840 Mon Sep 17 00:00:00 2001 From: Javier Jardón Date: Sun, 22 Mar 2015 04:57:05 +0000 Subject: Do not use an icon for Cancel/OK buttons GTK+ documentation recommends to not use an icons, but use "_OK"/"_Cancel" labels instead --- src/tree.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index 819f9a8e..ac61cd87 100644 --- a/src/tree.c +++ b/src/tree.c @@ -399,15 +399,11 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) if (data->ok_label) { button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_tree_ok_button")); gtk_button_set_label (GTK_BUTTON (button), data->ok_label); - gtk_button_set_image (GTK_BUTTON (button), - gtk_image_new_from_stock (GTK_STOCK_OK, GTK_ICON_SIZE_BUTTON)); } if (data->cancel_label) { button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_tree_cancel_button")); gtk_button_set_label (GTK_BUTTON (button), data->cancel_label); - gtk_button_set_image (GTK_BUTTON (button), - gtk_image_new_from_stock (GTK_STOCK_CANCEL, GTK_ICON_SIZE_BUTTON)); } text = gtk_builder_get_object (builder, "zenity_tree_text"); -- cgit From f01d7220db8d62846a01ab044a5976dd1304f446 Mon Sep 17 00:00:00 2001 From: Javier Jardón Date: Sun, 22 Mar 2015 09:07:34 +0000 Subject: src/tree.c: Do not use deprecated gtk_tree_view_set_rules_hint() --- src/tree.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index ac61cd87..a979d8a1 100644 --- a/src/tree.c +++ b/src/tree.c @@ -551,8 +551,6 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) column_index++; } - gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (tree_view), TRUE); - if (tree_data->hide_header) gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (tree_view), FALSE); -- cgit From c45daa96bfdc5a958cc0f2cdaf4db71ac61b8fde Mon Sep 17 00:00:00 2001 From: Javier Jardón Date: Sun, 22 Mar 2015 09:24:26 +0000 Subject: src/tree.c: avoid a compilation warning --- src/tree.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index a979d8a1..c87958f0 100644 --- a/src/tree.c +++ b/src/tree.c @@ -305,8 +305,9 @@ zenity_mid_search_func (GtkTreeModel *model, gint column, { gchar *iter_string = NULL; gtk_tree_model_get (model, iter, column, &iter_string, -1); - return ! g_strrstr (g_utf8_strdown(iter_string, -1), - g_utf8_strdown(key, -1)) != NULL; + return ! (g_strrstr (g_utf8_strdown(iter_string, -1), + g_utf8_strdown(key, -1)) != NULL); + } static void -- cgit From ba5ea0386de2a80a664fb28d3af7e8d395968314 Mon Sep 17 00:00:00 2001 From: Gama Anderson Date: Sat, 28 Feb 2015 20:06:09 +0100 Subject: ADD gchar **extra_label TO struct ZenityData this is done to keep the name of the extra buttons ADD general option "extra-button" with string array as argument This will upon consecutive calls save the name of buttons in an array of strings To all MODES, except notification.c and about.c ADD if (data->extra_label) { gint i=0; while(data->extra_label[i]!=NULL){ gtk_dialog_add_button (GTK_DIALOG (dialog), data->extra_label[i], i); i++; } } This add the extra buttons to the dialog. The response is the number of the button To all MODES response, except notification.c and about.c ADD default: if (response < g_strv_length(zen_data->extra_label)) printf("%s\n",zen_data->extra_label[response]); This will print the button name to stdout when they are pressed ADD question option "switch" This will suppress the standard "ok" and "cancel" button in question. This just wort in combination with --extra-button, otherwise error is raised. https://bugzilla.gnome.org/show_bug.cgi?id=118016 --- src/tree.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index 819f9a8e..0e2665c1 100644 --- a/src/tree.c +++ b/src/tree.c @@ -396,6 +396,14 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) if (data->modal) gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); + if (data->extra_label) { + gint i=0; + while(data->extra_label[i]!=NULL){ + gtk_dialog_add_button (GTK_DIALOG (dialog), data->extra_label[i], i); + i++; + } + } + if (data->ok_label) { button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_tree_ok_button")); gtk_button_set_label (GTK_BUTTON (button), data->ok_label); @@ -708,7 +716,8 @@ zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer data) break; default: - /* Esc dialog */ + if (response < g_strv_length(zen_data->extra_label)) + printf("%s\n",zen_data->extra_label[response]); zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC); break; } -- cgit From e6055cc19a2b8b04cd472e1e3511d48ba83bc046 Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Fri, 29 May 2015 13:55:27 +0200 Subject: Fixing deprecated declarations --- src/tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index 0849946c..7398fc26 100644 --- a/src/tree.c +++ b/src/tree.c @@ -210,7 +210,7 @@ zenity_tree_handle_stdin (GIOChannel *channel, GtkWidget *scrolled_window; GtkRequisition rectangle; - gtk_widget_size_request (GTK_WIDGET (tree_view), &rectangle); + gtk_widget_get_preferred_size (GTK_WIDGET (tree_view), &rectangle, NULL); scrolled_window = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_tree_window")); gtk_widget_set_size_request (scrolled_window, -1, rectangle.height); -- cgit From d063797fdfa73e5bec96d9399ab1bf47173a62d4 Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Fri, 2 Oct 2015 14:35:06 +0200 Subject: Fixing GLib-CRITICAL messages --- src/tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index 7398fc26..058b6b61 100644 --- a/src/tree.c +++ b/src/tree.c @@ -711,7 +711,7 @@ zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer data) break; default: - if (response < g_strv_length(zen_data->extra_label)) + if (zen_data->extra_label && response < g_strv_length(zen_data->extra_label)) printf("%s\n",zen_data->extra_label[response]); zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC); break; -- cgit From 4eddb202cafdcabc254aa941ad1348ff09372627 Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Fri, 7 Apr 2017 14:00:42 +0200 Subject: Fix style Fixing style in all zenity code, removing useless spaces, empty lines, all code in 80 columns, etc. --- src/tree.c | 1392 +++++++++++++++++++++++++++++++----------------------------- 1 file changed, 731 insertions(+), 661 deletions(-) (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index 058b6b61..d94ce7e8 100644 --- a/src/tree.c +++ b/src/tree.c @@ -25,10 +25,10 @@ #include "config.h" -#include -#include -#include "zenity.h" #include "util.h" +#include "zenity.h" +#include +#include #define MAX_ELEMENTS_BEFORE_SCROLLING 5 #define PRINT_HIDE_COLUMN_SEPARATOR "," @@ -43,733 +43,803 @@ static GIOChannel *channel; static int *zenity_tree_extract_column_indexes (char *indexes, gint n_columns); static gboolean zenity_tree_column_is_hidden (gint column_index); -static void zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer data); -static void zenity_tree_row_activated (GtkTreeView *tree_view, GtkTreePath *tree_path, - GtkTreeViewColumn *tree_col, 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, GtkTreeViewColumn *tree_col, gpointer data); static gboolean -zenity_tree_dialog_untoggle (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data) -{ - GValue toggle_value = {0, }; +zenity_tree_dialog_untoggle ( + GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data) { + GValue toggle_value = { + 0, + }; - 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)) - gtk_list_store_set (GTK_LIST_STORE (model), iter, 0, FALSE, -1); - return FALSE; + if (g_value_get_boolean (&toggle_value)) + gtk_list_store_set (GTK_LIST_STORE (model), iter, 0, FALSE, -1); + return FALSE; } static void -zenity_tree_toggled_callback (GtkCellRendererToggle *cell, gchar *path_string, gpointer data) -{ - GtkTreeModel *model; - GtkTreeIter iter; - GtkTreePath *path; - gboolean value; +zenity_tree_toggled_callback ( + GtkCellRendererToggle *cell, gchar *path_string, gpointer data) { + GtkTreeModel *model; + GtkTreeIter iter; + GtkTreePath *path; + gboolean value; - model = GTK_TREE_MODEL (data); + model = GTK_TREE_MODEL (data); - /* Because this is a radio list, we should untoggle the previous toggle so that - * we only have one selection at any given time - */ + /* Because this is a radio list, we should untoggle the previous toggle so + * that + * we only have one selection at any given time + */ - if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (model), "radio")) == 1) { - gtk_tree_model_foreach (model, zenity_tree_dialog_untoggle, NULL); - } + if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (model), "radio")) == 1) { + gtk_tree_model_foreach (model, zenity_tree_dialog_untoggle, NULL); + } - path = gtk_tree_path_new_from_string (path_string); - gtk_tree_model_get_iter (model, &iter, path); - gtk_tree_model_get (model, &iter, 0, &value, -1); + path = gtk_tree_path_new_from_string (path_string); + gtk_tree_model_get_iter (model, &iter, path); + gtk_tree_model_get (model, &iter, 0, &value, -1); - value = !value; - gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, value, -1); + value = !value; + gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, value, -1); - gtk_tree_path_free (path); + gtk_tree_path_free (path); } static void -zenity_load_pixbuf (GtkTreeViewColumn *tree_column, - GtkCellRenderer *cell, - GtkTreeModel *tree_model, - GtkTreeIter *iter, - gpointer data) -{ - static GHashTable *pixbuf_cache = NULL; - GError *error = NULL; - GdkPixbuf *pixbuf; - gchar *str; +zenity_load_pixbuf (GtkTreeViewColumn *tree_column, GtkCellRenderer *cell, + GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data) { + static GHashTable *pixbuf_cache = NULL; + GError *error = NULL; + GdkPixbuf *pixbuf; + gchar *str; - gtk_tree_model_get (tree_model, iter, 0, &str, -1); + gtk_tree_model_get (tree_model, iter, 0, &str, -1); - if (!str) - return; + if (!str) + return; - if (!pixbuf_cache) { - pixbuf_cache = g_hash_table_new (g_str_hash, g_str_equal); - g_assert(pixbuf_cache); - } + if (!pixbuf_cache) { + pixbuf_cache = g_hash_table_new (g_str_hash, g_str_equal); + g_assert (pixbuf_cache); + } - pixbuf = g_hash_table_lookup (pixbuf_cache, str); + pixbuf = g_hash_table_lookup (pixbuf_cache, str); - if (!pixbuf) { - pixbuf = gdk_pixbuf_new_from_file (str, &error); - if (!pixbuf) - g_warning ("Failed to load '%s'", str); + if (!pixbuf) { + pixbuf = gdk_pixbuf_new_from_file (str, &error); + if (!pixbuf) + g_warning ("Failed to load '%s'", str); - g_hash_table_insert (pixbuf_cache, g_strdup (str), pixbuf); - } + g_hash_table_insert (pixbuf_cache, g_strdup (str), pixbuf); + } - if (pixbuf) - g_object_set (cell, "pixbuf", pixbuf, NULL); + if (pixbuf) + g_object_set (cell, "pixbuf", pixbuf, NULL); - g_free (str); + g_free (str); } static gboolean -zenity_tree_handle_stdin (GIOChannel *channel, - GIOCondition condition, - gpointer data) -{ - static GtkTreeView *tree_view; - GtkTreeModel *model; - static GtkTreeIter iter; - static gint column_count = 0; - static gint row_count = 0; - static gint n_columns; - static gboolean editable; - static gboolean toggles; - static gboolean first_time = TRUE; - GIOStatus status = G_IO_STATUS_NORMAL; - - tree_view = GTK_TREE_VIEW (data); - n_columns = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tree_view), "n_columns")); - editable = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tree_view), "editable")); - toggles = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tree_view), "toggles")); - - model = gtk_tree_view_get_model (tree_view); - - if (first_time) { - first_time = FALSE; - gtk_list_store_append (GTK_LIST_STORE (model), &iter); - } - - if ((condition & G_IO_IN) == G_IO_IN) { - GString *string; - GError *error = NULL; - - string = g_string_new (NULL); - - while ((g_io_channel_get_flags(channel) & G_IO_FLAG_IS_READABLE) != G_IO_FLAG_IS_READABLE) - ; - do { - do { - if (g_io_channel_get_flags(channel) & G_IO_FLAG_IS_READABLE) - status = g_io_channel_read_line_string (channel, string, NULL, &error); - else - return FALSE; - - while (gtk_events_pending ()) - gtk_main_iteration (); - - // TODO: Find a better way to avoid 100% cpu utilization - g_usleep(10000); - - } while (status == G_IO_STATUS_AGAIN); - - if (status != G_IO_STATUS_NORMAL) { - if (error) { - g_warning ("zenity_tree_handle_stdin () : %s", error->message); - g_error_free (error); - error = NULL; - } - continue; - } - - if (column_count == n_columns) { - /* We're starting a new row */ - column_count = 0; - row_count++; - gtk_list_store_append (GTK_LIST_STORE (model), &iter); - } - - if (toggles && column_count == 0) { - if (strcmp (g_ascii_strdown (zenity_util_strip_newline (string->str), -1), "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); - } - else { - gtk_list_store_set (GTK_LIST_STORE (model), &iter, column_count, zenity_util_strip_newline (string->str), -1); - } - - if (editable) { - gtk_list_store_set (GTK_LIST_STORE (model), &iter, n_columns, TRUE, -1); - } - - if (row_count == MAX_ELEMENTS_BEFORE_SCROLLING) { - GtkWidget *scrolled_window; - GtkRequisition rectangle; - - gtk_widget_get_preferred_size (GTK_WIDGET (tree_view), &rectangle, NULL); - scrolled_window = GTK_WIDGET (gtk_builder_get_object (builder, - "zenity_tree_window")); - gtk_widget_set_size_request (scrolled_window, -1, rectangle.height); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), - GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - } - - column_count++; - - } while ((g_io_channel_get_buffer_condition (channel) & G_IO_IN) == G_IO_IN && status != G_IO_STATUS_EOF); - g_string_free (string, TRUE); - } - - if ((condition & G_IO_IN) != G_IO_IN || status == G_IO_STATUS_EOF) { - g_io_channel_shutdown (channel, TRUE, NULL); - return FALSE; - } - return TRUE; +zenity_tree_handle_stdin ( + GIOChannel *channel, GIOCondition condition, gpointer data) { + static GtkTreeView *tree_view; + GtkTreeModel *model; + static GtkTreeIter iter; + static gint column_count = 0; + static gint row_count = 0; + static gint n_columns; + static gboolean editable; + static gboolean toggles; + static gboolean first_time = TRUE; + GIOStatus status = G_IO_STATUS_NORMAL; + + tree_view = GTK_TREE_VIEW (data); + n_columns = + GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tree_view), "n_columns")); + editable = + GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tree_view), "editable")); + toggles = + GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tree_view), "toggles")); + + model = gtk_tree_view_get_model (tree_view); + + if (first_time) { + first_time = FALSE; + gtk_list_store_append (GTK_LIST_STORE (model), &iter); + } + + if ((condition & G_IO_IN) == G_IO_IN) { + GString *string; + GError *error = NULL; + + string = g_string_new (NULL); + + while ((g_io_channel_get_flags (channel) & G_IO_FLAG_IS_READABLE) != + G_IO_FLAG_IS_READABLE) + ; + do { + do { + if (g_io_channel_get_flags (channel) & G_IO_FLAG_IS_READABLE) + status = g_io_channel_read_line_string ( + channel, string, NULL, &error); + else + return FALSE; + + while (gtk_events_pending ()) + gtk_main_iteration (); + + // TODO: Find a better way to avoid 100% cpu utilization + g_usleep (10000); + + } while (status == G_IO_STATUS_AGAIN); + + if (status != G_IO_STATUS_NORMAL) { + if (error) { + g_warning ( + "zenity_tree_handle_stdin () : %s", error->message); + g_error_free (error); + error = NULL; + } + continue; + } + + if (column_count == n_columns) { + /* We're starting a new row */ + column_count = 0; + row_count++; + gtk_list_store_append (GTK_LIST_STORE (model), &iter); + } + + if (toggles && column_count == 0) { + if (strcmp (g_ascii_strdown ( + zenity_util_strip_newline (string->str), -1), + "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); + } else { + gtk_list_store_set (GTK_LIST_STORE (model), + &iter, + column_count, + zenity_util_strip_newline (string->str), + -1); + } + + if (editable) { + gtk_list_store_set ( + GTK_LIST_STORE (model), &iter, n_columns, TRUE, -1); + } + + if (row_count == MAX_ELEMENTS_BEFORE_SCROLLING) { + GtkWidget *scrolled_window; + GtkRequisition rectangle; + + gtk_widget_get_preferred_size ( + GTK_WIDGET (tree_view), &rectangle, NULL); + scrolled_window = GTK_WIDGET ( + gtk_builder_get_object (builder, "zenity_tree_window")); + gtk_widget_set_size_request ( + scrolled_window, -1, rectangle.height); + gtk_scrolled_window_set_policy ( + GTK_SCROLLED_WINDOW (scrolled_window), + GTK_POLICY_AUTOMATIC, + GTK_POLICY_AUTOMATIC); + } + + column_count++; + + } while ((g_io_channel_get_buffer_condition (channel) & G_IO_IN) == + G_IO_IN && + status != G_IO_STATUS_EOF); + g_string_free (string, TRUE); + } + + if ((condition & G_IO_IN) != G_IO_IN || status == G_IO_STATUS_EOF) { + g_io_channel_shutdown (channel, TRUE, NULL); + return FALSE; + } + return TRUE; } static void -zenity_tree_fill_entries_from_stdin (GtkTreeView *tree_view, - gint n_columns, - gboolean toggles, - gboolean editable) -{ - g_object_set_data (G_OBJECT (tree_view), "n_columns", GINT_TO_POINTER (n_columns)); - g_object_set_data (G_OBJECT (tree_view), "toggles", GINT_TO_POINTER (toggles)); - g_object_set_data (G_OBJECT (tree_view), "editable", GINT_TO_POINTER (editable)); - - channel = g_io_channel_unix_new (0); - g_io_channel_set_encoding (channel, NULL, NULL); - g_io_channel_set_flags (channel, G_IO_FLAG_NONBLOCK, NULL); - g_io_add_watch (channel, G_IO_IN | G_IO_HUP, zenity_tree_handle_stdin, tree_view); +zenity_tree_fill_entries_from_stdin (GtkTreeView *tree_view, gint n_columns, + gboolean toggles, gboolean editable) { + g_object_set_data ( + G_OBJECT (tree_view), "n_columns", GINT_TO_POINTER (n_columns)); + g_object_set_data ( + G_OBJECT (tree_view), "toggles", GINT_TO_POINTER (toggles)); + g_object_set_data ( + G_OBJECT (tree_view), "editable", GINT_TO_POINTER (editable)); + + channel = g_io_channel_unix_new (0); + g_io_channel_set_encoding (channel, NULL, NULL); + g_io_channel_set_flags (channel, G_IO_FLAG_NONBLOCK, NULL); + g_io_add_watch ( + channel, G_IO_IN | G_IO_HUP, zenity_tree_handle_stdin, tree_view); } static void -zenity_tree_fill_entries (GtkTreeView *tree_view, - const gchar **args, - gint n_columns, - gboolean toggles, - gboolean editable) -{ - GtkTreeModel *model; - GtkTreeIter iter; - gint i = 0; - - model = gtk_tree_view_get_model (tree_view); - - g_object_set_data (G_OBJECT (tree_view), "n_columns", GINT_TO_POINTER (n_columns)); - - while (args[i] != NULL) { - gint j; - - gtk_list_store_append (GTK_LIST_STORE (model), &iter); - - for (j = 0; j < n_columns; j++) { - - if (toggles && j == 0) { - if (strcmp (g_ascii_strdown ((gchar *) args[i+j], -1), "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 (editable) - gtk_list_store_set (GTK_LIST_STORE (model), &iter, n_columns, TRUE, -1); - - if (i == MAX_ELEMENTS_BEFORE_SCROLLING) { - GtkWidget *scrolled_window; - GtkRequisition rectangle; - - gtk_widget_get_preferred_size (GTK_WIDGET (tree_view), &rectangle, NULL); - scrolled_window = GTK_WIDGET (gtk_builder_get_object (builder, - "zenity_tree_window")); - gtk_widget_set_size_request (scrolled_window, -1, rectangle.height); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), - GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - } - - i += n_columns; - } +zenity_tree_fill_entries (GtkTreeView *tree_view, const gchar **args, + gint n_columns, gboolean toggles, gboolean editable) { + GtkTreeModel *model; + GtkTreeIter iter; + gint i = 0; + + model = gtk_tree_view_get_model (tree_view); + + g_object_set_data ( + G_OBJECT (tree_view), "n_columns", GINT_TO_POINTER (n_columns)); + + while (args[i] != NULL) { + gint j; + + gtk_list_store_append (GTK_LIST_STORE (model), &iter); + + for (j = 0; j < n_columns; j++) { + + if (toggles && j == 0) { + if (strcmp (g_ascii_strdown ((gchar *) args[i + j], -1), + "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 (editable) + gtk_list_store_set ( + GTK_LIST_STORE (model), &iter, n_columns, TRUE, -1); + + if (i == MAX_ELEMENTS_BEFORE_SCROLLING) { + GtkWidget *scrolled_window; + GtkRequisition rectangle; + + gtk_widget_get_preferred_size ( + GTK_WIDGET (tree_view), &rectangle, NULL); + scrolled_window = GTK_WIDGET ( + gtk_builder_get_object (builder, "zenity_tree_window")); + gtk_widget_set_size_request (scrolled_window, -1, rectangle.height); + gtk_scrolled_window_set_policy ( + GTK_SCROLLED_WINDOW (scrolled_window), + GTK_POLICY_AUTOMATIC, + GTK_POLICY_AUTOMATIC); + } + + i += n_columns; + } } static gboolean -zenity_mid_search_func (GtkTreeModel *model, gint column, - const gchar *key, GtkTreeIter *iter, - gpointer search_data) -{ - gchar *iter_string = NULL; - gtk_tree_model_get (model, iter, column, &iter_string, -1); - return ! (g_strrstr (g_utf8_strdown(iter_string, -1), - g_utf8_strdown(key, -1)) != NULL); - +zenity_mid_search_func (GtkTreeModel *model, gint column, const gchar *key, + GtkTreeIter *iter, gpointer search_data) { + gchar *iter_string = NULL; + gtk_tree_model_get (model, iter, column, &iter_string, -1); + return !(g_strrstr (g_utf8_strdown (iter_string, -1), + g_utf8_strdown (key, -1)) != NULL); } static void -zenity_cell_edited_callback (GtkCellRendererText *cell, - const gchar *path_string, - const gchar *new_text, - gpointer data) -{ - GtkTreeModel *model; - GtkTreePath *path; - GtkTreeIter iter; - gint column; - - model = GTK_TREE_MODEL (data); - path = gtk_tree_path_new_from_string (path_string); - - column = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (cell), "column")); - gtk_tree_model_get_iter (model, &iter, path); - - gtk_list_store_set (GTK_LIST_STORE (model), &iter, column, new_text, -1); - - gtk_tree_path_free (path); -} +zenity_cell_edited_callback (GtkCellRendererText *cell, + const gchar *path_string, const gchar *new_text, gpointer data) { + GtkTreeModel *model; + GtkTreePath *path; + GtkTreeIter iter; + gint column; -void -zenity_tree (ZenityData *data, ZenityTreeData *tree_data) -{ - GtkWidget *dialog; - GtkWidget *button; - GObject *tree_view; - GObject *text; - GtkTreeViewColumn *column; - GtkListStore *model; - GType *column_types; - GSList *tmp; - gboolean first_column = FALSE; - gint i, column_index, n_columns; - - builder = zenity_util_load_ui_file ("zenity_tree_dialog", NULL); - - if (builder == NULL) { - data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR); - return; - } - - separator = g_strcompress (tree_data->separator); - - n_columns = g_slist_length (tree_data->columns); - - if (tree_data->print_column) { - if (strcmp (g_ascii_strdown (tree_data->print_column, -1), "all") == 0) - print_all_columns = TRUE; - else - print_columns = zenity_tree_extract_column_indexes (tree_data->print_column, n_columns); - } - else { - print_columns = g_new (gint, 2); - print_columns[0] = (tree_data->radiobox || tree_data->checkbox ? 2 : 1); - print_columns[1] = 0; - } - - if (tree_data->hide_column) - hide_columns = zenity_tree_extract_column_indexes (tree_data->hide_column, n_columns); - - if (n_columns == 0) { - g_printerr (_("No column titles specified for List dialog.\n")); - data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR); - return; - } - - if (tree_data->checkbox + tree_data->radiobox + tree_data->imagebox > 1) { - g_printerr (_("You should use only one List dialog type.\n")); - data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR); - return; - } - - gtk_builder_connect_signals (builder, NULL); - - dialog = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_tree_dialog")); - - g_signal_connect (G_OBJECT (dialog), "response", - G_CALLBACK (zenity_tree_dialog_response), data); - - if (data->dialog_title) - gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title); - - if (data->modal) - gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); - - if (data->extra_label) { - gint i=0; - while(data->extra_label[i]!=NULL){ - gtk_dialog_add_button (GTK_DIALOG (dialog), data->extra_label[i], i); - i++; - } - } - - if (data->ok_label) { - button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_tree_ok_button")); - gtk_button_set_label (GTK_BUTTON (button), data->ok_label); - } - - if (data->cancel_label) { - button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_tree_cancel_button")); - gtk_button_set_label (GTK_BUTTON (button), data->cancel_label); - } - - text = gtk_builder_get_object (builder, "zenity_tree_text"); - - if (tree_data->dialog_text) - gtk_label_set_markup (GTK_LABEL (text), g_strcompress (tree_data->dialog_text)); - - zenity_util_set_window_icon (dialog, data->window_icon, ZENITY_IMAGE_FULLPATH ("zenity-list.png")); - - if (data->width > -1 || data->height > -1) - gtk_window_set_default_size (GTK_WINDOW (dialog), data->width, data->height); - - tree_view = gtk_builder_get_object (builder, "zenity_tree_view"); - - if (!(tree_data->radiobox || tree_data->checkbox)) - g_signal_connect (tree_view, "row-activated", - G_CALLBACK (zenity_tree_row_activated), data); - - /* Create an empty list store */ - model = g_object_new (GTK_TYPE_LIST_STORE, NULL); - - if (tree_data->editable) - column_types = g_new (GType, n_columns + 1); - else - column_types = g_new (GType, n_columns); - - 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; - else - column_types[i] = G_TYPE_STRING; - } - - if (tree_data->editable) - column_types[n_columns] = G_TYPE_BOOLEAN; - - if (tree_data->editable) - gtk_list_store_set_column_types (model, n_columns + 1, column_types); - else - 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)); - - if (!(tree_data->radiobox || tree_data->checkbox)) { - if (tree_data->multi) - gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)), - GTK_SELECTION_MULTIPLE); - else - gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)), - GTK_SELECTION_SINGLE); - } - else - gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)), - GTK_SELECTION_NONE); - - column_index = 0; - - for (tmp = tree_data->columns; tmp; tmp = tmp->next) { - if (!first_column) { - if (tree_data->checkbox || tree_data->radiobox) { - GtkCellRenderer *cell_renderer; - - cell_renderer = gtk_cell_renderer_toggle_new (); - - if (tree_data->radiobox) { - g_object_set (G_OBJECT (cell_renderer), "radio", TRUE, NULL); - g_object_set_data (G_OBJECT (model), "radio", GINT_TO_POINTER (1)); - } - - g_signal_connect (cell_renderer, "toggled", - G_CALLBACK (zenity_tree_toggled_callback), model); - - column = gtk_tree_view_column_new_with_attributes (tmp->data, - cell_renderer, - "active", column_index, NULL); - } else if (tree_data->imagebox) { - GtkCellRenderer *cell_renderer = gtk_cell_renderer_pixbuf_new (); - column = gtk_tree_view_column_new_with_attributes (tmp->data, - cell_renderer, NULL); - gtk_tree_view_column_set_cell_data_func (column, cell_renderer, - zenity_load_pixbuf, NULL, NULL); - } - else { - if (tree_data->editable) { - GtkCellRenderer *cell_renderer; - - cell_renderer = gtk_cell_renderer_text_new (); - g_signal_connect (G_OBJECT (cell_renderer), "edited", - G_CALLBACK (zenity_cell_edited_callback), - gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view))); - g_object_set_data (G_OBJECT (cell_renderer), "column", GINT_TO_POINTER (column_index)); - - column = gtk_tree_view_column_new_with_attributes (tmp->data, - cell_renderer, - "text", column_index, - "editable", n_columns, - NULL); - } - else { - column = gtk_tree_view_column_new_with_attributes (tmp->data, - gtk_cell_renderer_text_new (), - "text", column_index, - NULL); - } - - gtk_tree_view_column_set_sort_column_id (column, column_index); - gtk_tree_view_column_set_resizable (column, TRUE); - } - if (zenity_tree_column_is_hidden (1)) - gtk_tree_view_column_set_visible (column, FALSE); - - first_column = TRUE; - } - else { - if (tree_data->editable) { - GtkCellRenderer *cell_renderer; - - cell_renderer = gtk_cell_renderer_text_new (); - g_signal_connect (G_OBJECT (cell_renderer), "edited", - G_CALLBACK (zenity_cell_edited_callback), - gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view))); - g_object_set_data (G_OBJECT (cell_renderer), "column", GINT_TO_POINTER (column_index)); - - column = gtk_tree_view_column_new_with_attributes (tmp->data, - cell_renderer, - "text", column_index, - "editable", n_columns, - NULL); - } - else { - column = gtk_tree_view_column_new_with_attributes (tmp->data, - gtk_cell_renderer_text_new (), - "text", column_index, NULL); - } - - gtk_tree_view_column_set_sort_column_id (column, column_index); - gtk_tree_view_column_set_resizable (column, TRUE); - - if (zenity_tree_column_is_hidden (column_index + 1)) - gtk_tree_view_column_set_visible (column, FALSE); - } - - gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column); - column_index++; - } - - if (tree_data->hide_header) - gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (tree_view), FALSE); - - if (tree_data->radiobox || tree_data->checkbox) { - if (tree_data->data && *tree_data->data) - zenity_tree_fill_entries (GTK_TREE_VIEW (tree_view), tree_data->data, n_columns, TRUE, tree_data->editable); - else - zenity_tree_fill_entries_from_stdin (GTK_TREE_VIEW (tree_view), n_columns, TRUE, tree_data->editable); - } - else { - if (tree_data->data && *tree_data->data) - zenity_tree_fill_entries (GTK_TREE_VIEW (tree_view), tree_data->data, n_columns, FALSE, tree_data->editable); - else - zenity_tree_fill_entries_from_stdin (GTK_TREE_VIEW (tree_view), n_columns, FALSE, tree_data->editable); - } - - zenity_util_show_dialog (dialog, data->attach); - - if (tree_data->mid_search) - gtk_tree_view_set_search_equal_func(GTK_TREE_VIEW(tree_view), (GtkTreeViewSearchEqualFunc) zenity_mid_search_func, model, NULL); - - if(data->timeout_delay > 0) { - g_timeout_add_seconds (data->timeout_delay, (GSourceFunc) zenity_util_timeout_handle, dialog); - } - - gtk_main (); - - g_object_unref (builder); -} + model = GTK_TREE_MODEL (data); + path = gtk_tree_path_new_from_string (path_string); -static void -zenity_tree_dialog_get_selected (GtkTreeModel *model, GtkTreePath *path_buf, GtkTreeIter *iter, GtkTreeView *tree_view) -{ - GValue value = {0, }; - gint n_columns, i; + column = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (cell), "column")); + gtk_tree_model_get_iter (model, &iter, path); - n_columns = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tree_view), "n_columns")); + gtk_list_store_set (GTK_LIST_STORE (model), &iter, column, new_text, -1); - 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_value_dup_string (&value)); - g_value_unset (&value); - } - return; - } + gtk_tree_path_free (path); +} - for (i = 0; print_columns[i] != 0; i++) { - gtk_tree_model_get_value (model, iter, print_columns[i] - 1, &value); +void +zenity_tree (ZenityData *data, ZenityTreeData *tree_data) { + GtkWidget *dialog; + GtkWidget *button; + GObject *tree_view; + GObject *text; + GtkTreeViewColumn *column; + GtkListStore *model; + GType *column_types; + GSList *tmp; + gboolean first_column = FALSE; + gint i, column_index, n_columns; + + builder = zenity_util_load_ui_file ("zenity_tree_dialog", NULL); + + if (builder == NULL) { + data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR); + return; + } + + separator = g_strcompress (tree_data->separator); + + n_columns = g_slist_length (tree_data->columns); + + if (tree_data->print_column) { + if (strcmp (g_ascii_strdown (tree_data->print_column, -1), "all") == 0) + print_all_columns = TRUE; + else + print_columns = zenity_tree_extract_column_indexes ( + tree_data->print_column, n_columns); + } else { + print_columns = g_new (gint, 2); + print_columns[0] = (tree_data->radiobox || tree_data->checkbox ? 2 : 1); + print_columns[1] = 0; + } + + if (tree_data->hide_column) + hide_columns = zenity_tree_extract_column_indexes ( + tree_data->hide_column, n_columns); + + if (n_columns == 0) { + g_printerr (_ ("No column titles specified for List dialog.\n")); + data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR); + return; + } + + if (tree_data->checkbox + tree_data->radiobox + tree_data->imagebox > 1) { + g_printerr (_ ("You should use only one List dialog type.\n")); + data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR); + return; + } + + gtk_builder_connect_signals (builder, NULL); + + dialog = + GTK_WIDGET (gtk_builder_get_object (builder, "zenity_tree_dialog")); + + g_signal_connect (G_OBJECT (dialog), + "response", + G_CALLBACK (zenity_tree_dialog_response), + data); + + if (data->dialog_title) + gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title); + + if (data->modal) + gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); + + if (data->extra_label) { + gint i = 0; + while (data->extra_label[i] != NULL) { + gtk_dialog_add_button ( + GTK_DIALOG (dialog), data->extra_label[i], i); + i++; + } + } + + if (data->ok_label) { + button = GTK_WIDGET ( + gtk_builder_get_object (builder, "zenity_tree_ok_button")); + gtk_button_set_label (GTK_BUTTON (button), data->ok_label); + } + + if (data->cancel_label) { + button = GTK_WIDGET ( + gtk_builder_get_object (builder, "zenity_tree_cancel_button")); + gtk_button_set_label (GTK_BUTTON (button), data->cancel_label); + } + + text = gtk_builder_get_object (builder, "zenity_tree_text"); + + if (tree_data->dialog_text) + gtk_label_set_markup ( + GTK_LABEL (text), g_strcompress (tree_data->dialog_text)); + + zenity_util_set_window_icon ( + dialog, data->window_icon, ZENITY_IMAGE_FULLPATH ("zenity-list.png")); + + if (data->width > -1 || data->height > -1) + gtk_window_set_default_size ( + GTK_WINDOW (dialog), data->width, data->height); + + tree_view = gtk_builder_get_object (builder, "zenity_tree_view"); + + if (!(tree_data->radiobox || tree_data->checkbox)) + g_signal_connect (tree_view, + "row-activated", + G_CALLBACK (zenity_tree_row_activated), + data); + + /* Create an empty list store */ + model = g_object_new (GTK_TYPE_LIST_STORE, NULL); + + if (tree_data->editable) + column_types = g_new (GType, n_columns + 1); + else + column_types = g_new (GType, n_columns); + + 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; + else + column_types[i] = G_TYPE_STRING; + } + + if (tree_data->editable) + column_types[n_columns] = G_TYPE_BOOLEAN; + + if (tree_data->editable) + gtk_list_store_set_column_types (model, n_columns + 1, column_types); + else + 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)); + + if (!(tree_data->radiobox || tree_data->checkbox)) { + if (tree_data->multi) + gtk_tree_selection_set_mode ( + gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)), + GTK_SELECTION_MULTIPLE); + else + gtk_tree_selection_set_mode ( + gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)), + GTK_SELECTION_SINGLE); + } else + gtk_tree_selection_set_mode ( + gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)), + GTK_SELECTION_NONE); + + column_index = 0; + + for (tmp = tree_data->columns; tmp; tmp = tmp->next) { + if (!first_column) { + if (tree_data->checkbox || tree_data->radiobox) { + GtkCellRenderer *cell_renderer; + + cell_renderer = gtk_cell_renderer_toggle_new (); + + if (tree_data->radiobox) { + g_object_set ( + G_OBJECT (cell_renderer), "radio", TRUE, NULL); + g_object_set_data ( + G_OBJECT (model), "radio", GINT_TO_POINTER (1)); + } + + g_signal_connect (cell_renderer, + "toggled", + G_CALLBACK (zenity_tree_toggled_callback), + model); + + column = gtk_tree_view_column_new_with_attributes ( + tmp->data, cell_renderer, "active", column_index, NULL); + } else if (tree_data->imagebox) { + GtkCellRenderer *cell_renderer = + gtk_cell_renderer_pixbuf_new (); + column = gtk_tree_view_column_new_with_attributes ( + tmp->data, cell_renderer, NULL); + gtk_tree_view_column_set_cell_data_func ( + column, cell_renderer, zenity_load_pixbuf, NULL, NULL); + } else { + if (tree_data->editable) { + GtkCellRenderer *cell_renderer; + + cell_renderer = gtk_cell_renderer_text_new (); + g_signal_connect (G_OBJECT (cell_renderer), + "edited", + G_CALLBACK (zenity_cell_edited_callback), + gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view))); + g_object_set_data (G_OBJECT (cell_renderer), + "column", + GINT_TO_POINTER (column_index)); + + column = + gtk_tree_view_column_new_with_attributes (tmp->data, + cell_renderer, + "text", + column_index, + "editable", + n_columns, + NULL); + } else { + column = + gtk_tree_view_column_new_with_attributes (tmp->data, + gtk_cell_renderer_text_new (), + "text", + column_index, + NULL); + } + + gtk_tree_view_column_set_sort_column_id (column, column_index); + gtk_tree_view_column_set_resizable (column, TRUE); + } + if (zenity_tree_column_is_hidden (1)) + gtk_tree_view_column_set_visible (column, FALSE); + + first_column = TRUE; + } else { + if (tree_data->editable) { + GtkCellRenderer *cell_renderer; + + cell_renderer = gtk_cell_renderer_text_new (); + g_signal_connect (G_OBJECT (cell_renderer), + "edited", + G_CALLBACK (zenity_cell_edited_callback), + gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view))); + g_object_set_data (G_OBJECT (cell_renderer), + "column", + GINT_TO_POINTER (column_index)); + + column = gtk_tree_view_column_new_with_attributes (tmp->data, + cell_renderer, + "text", + column_index, + "editable", + n_columns, + NULL); + } else { + column = gtk_tree_view_column_new_with_attributes (tmp->data, + gtk_cell_renderer_text_new (), + "text", + column_index, + NULL); + } + + gtk_tree_view_column_set_sort_column_id (column, column_index); + gtk_tree_view_column_set_resizable (column, TRUE); + + if (zenity_tree_column_is_hidden (column_index + 1)) + gtk_tree_view_column_set_visible (column, FALSE); + } + + gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column); + column_index++; + } + + if (tree_data->hide_header) + gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (tree_view), FALSE); + + if (tree_data->radiobox || tree_data->checkbox) { + if (tree_data->data && *tree_data->data) + zenity_tree_fill_entries (GTK_TREE_VIEW (tree_view), + tree_data->data, + n_columns, + TRUE, + tree_data->editable); + else + zenity_tree_fill_entries_from_stdin (GTK_TREE_VIEW (tree_view), + n_columns, + TRUE, + tree_data->editable); + } else { + if (tree_data->data && *tree_data->data) + zenity_tree_fill_entries (GTK_TREE_VIEW (tree_view), + tree_data->data, + n_columns, + FALSE, + tree_data->editable); + else + zenity_tree_fill_entries_from_stdin (GTK_TREE_VIEW (tree_view), + n_columns, + FALSE, + tree_data->editable); + } + + zenity_util_show_dialog (dialog, data->attach); + + if (tree_data->mid_search) + gtk_tree_view_set_search_equal_func (GTK_TREE_VIEW (tree_view), + (GtkTreeViewSearchEqualFunc) zenity_mid_search_func, + model, + NULL); + + if (data->timeout_delay > 0) { + g_timeout_add_seconds (data->timeout_delay, + (GSourceFunc) zenity_util_timeout_handle, + dialog); + } + + gtk_main (); + + g_object_unref (builder); +} - selected = g_slist_append (selected, g_value_dup_string (&value)); - g_value_unset (&value); - } +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")); + + 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_value_dup_string (&value)); + g_value_unset (&value); + } + return; + } + + for (i = 0; print_columns[i] != 0; i++) { + gtk_tree_model_get_value (model, iter, print_columns[i] - 1, &value); + + selected = g_slist_append (selected, g_value_dup_string (&value)); + g_value_unset (&value); + } } static gboolean -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, }; - - 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_value_dup_string (&value)); - g_value_unset (&value); - } - g_value_unset (&toggle_value); - return FALSE; - } - - for (i = 0; print_columns[i] != 0; i++) { - gtk_tree_model_get_value (model, iter, print_columns[i] - 1, &value); - - selected = g_slist_append (selected, g_value_dup_string (&value)); - g_value_unset (&value); - } - } - - g_value_unset (&toggle_value); - - return FALSE; +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, + }; + + 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_value_dup_string (&value)); + g_value_unset (&value); + } + g_value_unset (&toggle_value); + return FALSE; + } + + for (i = 0; print_columns[i] != 0; i++) { + gtk_tree_model_get_value ( + model, iter, print_columns[i] - 1, &value); + + selected = g_slist_append (selected, g_value_dup_string (&value)); + g_value_unset (&value); + } + } + + g_value_unset (&toggle_value); + + return FALSE; } static void -zenity_tree_dialog_output (void) -{ -GObject *tree_view; - GtkTreeSelection *selection; - GtkTreeModel *model; - - tree_view = gtk_builder_get_object (builder, "zenity_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) - 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, - (GtkTreeSelectionForeachFunc) zenity_tree_dialog_get_selected, - GTK_TREE_VIEW (tree_view)); - } - - GSList *tmp; - - for (tmp = selected; tmp; tmp = tmp->next) { - if (tmp->next != NULL) { - g_print ("%s%s", (gchar *) tmp->data, separator); - } - else - g_print ("%s\n", (gchar *) tmp->data); - } - - g_free (print_columns); - g_free (hide_columns); - g_free (separator); - g_slist_foreach (selected, (GFunc) g_free, NULL); - selected = NULL; +zenity_tree_dialog_output (void) { + GObject *tree_view; + GtkTreeSelection *selection; + GtkTreeModel *model; + + tree_view = gtk_builder_get_object (builder, "zenity_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) + 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, + (GtkTreeSelectionForeachFunc) zenity_tree_dialog_get_selected, + GTK_TREE_VIEW (tree_view)); + } + + GSList *tmp; + + for (tmp = selected; tmp; tmp = tmp->next) { + if (tmp->next != NULL) { + g_print ("%s%s", (gchar *) tmp->data, separator); + } else + g_print ("%s\n", (gchar *) tmp->data); + } + + g_free (print_columns); + g_free (hide_columns); + 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) -{ - ZenityData *zen_data = data; - - switch (response) { - case GTK_RESPONSE_OK: - zenity_tree_dialog_output (); - zenity_util_exit_code_with_data(ZENITY_OK, zen_data); - break; - - case GTK_RESPONSE_CANCEL: - zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL); - break; - - case ZENITY_TIMEOUT: - zenity_tree_dialog_output (); - zen_data->exit_code = zenity_util_return_exit_code (ZENITY_TIMEOUT); - break; - - default: - if (zen_data->extra_label && response < g_strv_length(zen_data->extra_label)) - printf("%s\n",zen_data->extra_label[response]); - zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC); - break; - } - if (channel != NULL && g_io_channel_get_flags (channel) & G_IO_FLAG_IS_READABLE) - g_io_channel_shutdown (channel, TRUE, NULL); - - gtk_main_quit (); +zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer data) { + ZenityData *zen_data = data; + + switch (response) { + case GTK_RESPONSE_OK: + zenity_tree_dialog_output (); + zenity_util_exit_code_with_data (ZENITY_OK, zen_data); + break; + + case GTK_RESPONSE_CANCEL: + zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL); + break; + + case ZENITY_TIMEOUT: + zenity_tree_dialog_output (); + zen_data->exit_code = zenity_util_return_exit_code (ZENITY_TIMEOUT); + break; + + default: + if (zen_data->extra_label && + response < g_strv_length (zen_data->extra_label)) + printf ("%s\n", zen_data->extra_label[response]); + zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC); + break; + } + if (channel != NULL && + g_io_channel_get_flags (channel) & G_IO_FLAG_IS_READABLE) + g_io_channel_shutdown (channel, TRUE, NULL); + + gtk_main_quit (); } static void -zenity_tree_row_activated (GtkTreeView *tree_view, GtkTreePath *tree_path, - GtkTreeViewColumn *tree_col, gpointer data) -{ - ZenityData *zen_data = data; - - zenity_tree_dialog_output (); - zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK); - gtk_main_quit (); +zenity_tree_row_activated (GtkTreeView *tree_view, GtkTreePath *tree_path, + GtkTreeViewColumn *tree_col, gpointer data) { + ZenityData *zen_data = data; + + zenity_tree_dialog_output (); + zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK); + gtk_main_quit (); } static gboolean -zenity_tree_column_is_hidden (gint column_index) -{ - gint i; +zenity_tree_column_is_hidden (gint column_index) { + gint i; - if (hide_columns != NULL) - for (i = 0; hide_columns[i] != 0; i++) - if (hide_columns[i] == column_index) - return TRUE; + if (hide_columns != NULL) + for (i = 0; hide_columns[i] != 0; i++) + if (hide_columns[i] == column_index) + return TRUE; - return FALSE; + return FALSE; } static gint * -zenity_tree_extract_column_indexes (char *indexes, int n_columns) -{ - char **tmp; - gint *result; - gint i, j, index; +zenity_tree_extract_column_indexes (char *indexes, int n_columns) { + char **tmp; + gint *result; + gint i, j, index; - tmp = g_strsplit (indexes, - PRINT_HIDE_COLUMN_SEPARATOR, 0); + tmp = g_strsplit (indexes, PRINT_HIDE_COLUMN_SEPARATOR, 0); - result = g_new (gint, 1); + result = g_new (gint, 1); - for (j = i = 0; tmp[i] != NULL; i++) { - index = atoi (tmp[i]); + for (j = i = 0; tmp[i] != NULL; i++) { + index = atoi (tmp[i]); - if (index > 0 && index <= n_columns) { - result[j] = index; - j++; - result = g_renew (gint, result, j + 1); - } - } - result[j] = 0; + if (index > 0 && index <= n_columns) { + result[j] = index; + j++; + result = g_renew (gint, result, j + 1); + } + } + result[j] = 0; - g_strfreev (tmp); + g_strfreev (tmp); - return result; + return result; } -- cgit