diff options
author | Glynn Foster <glynn.foster@sun.com> | 2003-03-10 17:11:18 +0000 |
---|---|---|
committer | Glynn Foster <gman@src.gnome.org> | 2003-03-10 17:11:18 +0000 |
commit | 49f89795349a47ae4e061666d84a715bf24f5373 (patch) | |
tree | fe33734a99bda00908c87cb8065c0dcd6644f51e /src/tree.c | |
parent | Added "pt_BR" (Brazilian Portuguese). (diff) | |
download | zenity-49f89795349a47ae4e061666d84a715bf24f5373.tar.gz zenity-49f89795349a47ae4e061666d84a715bf24f5373.tar.bz2 zenity-49f89795349a47ae4e061666d84a715bf24f5373.zip |
Mass indentation cleanup. Make sure the glade dialogs aren't initially
2003-03-10 Glynn Foster <glynn.foster@sun.com>
* 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.
Diffstat (limited to 'src/tree.c')
-rw-r--r-- | src/tree.c | 549 |
1 files changed, 275 insertions, 274 deletions
@@ -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; + } } |