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/option.c | 18 ++++++++++++++++++ src/tree.c | 40 ++++++++++++++++++++++++++++++++-------- src/zenity.h | 1 + 3 files changed, 51 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/option.c b/src/option.c index a167488..b4d35bc 100644 --- a/src/option.c +++ b/src/option.c @@ -66,6 +66,7 @@ gchar **zenity_list_columns; gboolean zenity_list_checklist; gboolean zenity_list_radiolist; gchar *zenity_list_print_column; +gchar *zenity_list_hide_column; /* Notification Dialog Options */ gboolean zenity_notification_active; @@ -443,6 +444,15 @@ GOptionEntry list_options[] = { N_("Print a specific column (Default is 1. 'ALL' can be used to print all columns)"), NULL }, + { + "hide-column", + '\0', + 0, + G_OPTION_ARG_STRING, + &zenity_list_hide_column, + N_("Hide a specific column"), + NULL + }, { NULL } @@ -699,6 +709,8 @@ zenity_option_free (void) { g_strfreev (zenity_list_columns); if (zenity_list_print_column) g_free (zenity_list_print_column); + if (zenity_list_hide_column) + g_free (zenity_list_hide_column); g_option_context_free (ctx); } @@ -831,6 +843,7 @@ zenity_list_pre_callback (GOptionContext *context, zenity_list_checklist = FALSE; zenity_list_radiolist = FALSE; zenity_list_print_column = NULL; + zenity_list_hide_column = NULL; return TRUE; } @@ -1090,6 +1103,7 @@ zenity_list_post_callback (GOptionContext *context, results->tree_data->multi = zenity_general_multiple; results->tree_data->editable = zenity_general_editable; results->tree_data->print_column = zenity_list_print_column; + results->tree_data->hide_column = zenity_list_hide_column; results->tree_data->separator = zenity_general_separator; } else { if (zenity_list_columns) @@ -1107,6 +1121,10 @@ zenity_list_post_callback (GOptionContext *context, if (zenity_list_print_column) zenity_option_error (zenity_option_get_name (list_options, &zenity_list_print_column), ERROR_SUPPORT); + + if (zenity_list_hide_column) + zenity_option_error (zenity_option_get_name (list_options, &zenity_list_hide_column), + ERROR_SUPPORT); } return TRUE; diff --git a/src/tree.c b/src/tree.c index ea2ba9e..57e8128 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) { diff --git a/src/zenity.h b/src/zenity.h index 0e1dba1..b224abd 100644 --- a/src/zenity.h +++ b/src/zenity.h @@ -97,6 +97,7 @@ typedef struct { gboolean multi; gboolean editable; gchar *print_column; + gchar *hide_column; const gchar **data; } ZenityTreeData; -- cgit v1.2.3-54-g00ecf