[gnumeric] Autofit column widths in stf import. [#427382]



commit b6706a228c4add7b310d1a0e254fda98295f340d
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Thu Jun 24 02:08:56 2010 -0600

     Autofit column widths in stf import. [#427382]
    
    2010-06-24  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* dialog-stf.h (FormatInfo_t): add new field
    	* dialog-stf.c (stf_dialog): transfer autofit array
    	* dialog-stf-format-page.c (cb_col_check_clicked): set
    	  sensitivity of autofit check
    	(cb_col_check_autofit_clicked): new
    	(format_page_update_preview): handle new field
    	(stf_dialog_format_page_cleanup): ditto
    	(stf_dialog_format_page_init): ditto
    
    2010-06-24  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* src/stf-parse.h: add field to parseoptions
    	* src/stf-parse.c (stf_parse_options_new): handle new field
    	(stf_parse_options_free): handle new field
    	(stf_parse_sheet): autofit columns

 ChangeLog                            |    7 ++++
 NEWS                                 |    1 +
 src/dialogs/ChangeLog                |   11 ++++++
 src/dialogs/dialog-stf-format-page.c |   67 ++++++++++++++++++++++++++++------
 src/dialogs/dialog-stf.c             |    3 ++
 src/dialogs/dialog-stf.h             |    1 +
 src/stf-parse.c                      |   25 +++++++++++--
 src/stf-parse.h                      |    2 +
 8 files changed, 103 insertions(+), 14 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index d52482f..32762e3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2010-06-24  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* src/stf-parse.h: add field to parseoptions
+	* src/stf-parse.c (stf_parse_options_new): handle new field
+	(stf_parse_options_free): handle new field
+	(stf_parse_sheet): autofit columns
+	
 2010-06-23  Andreas J. Guelzow <aguelzow pyrshep ca>
 
 	* src/validation.h (validation_eval_range): new
diff --git a/NEWS b/NEWS
index 64158ac..0da992d 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,7 @@ Andreas:
 	* Improve function syntax and formula guru tooltips.
 	* Avoid superfluous redo items under validation failure. [#622509]
 	* Fix validation for array and range entry. [#622511]
+	* Autofit column widths in stf import. [#427382]
 
 Jean:
 	* Fixed autofilter (and other) combo positions. [#621817]
diff --git a/src/dialogs/ChangeLog b/src/dialogs/ChangeLog
index cf810ba..e8db1b0 100644
--- a/src/dialogs/ChangeLog
+++ b/src/dialogs/ChangeLog
@@ -1,3 +1,14 @@
+2010-06-24  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* dialog-stf.h (FormatInfo_t): add new field 
+	* dialog-stf.c (stf_dialog): transfer autofit array
+	* dialog-stf-format-page.c (cb_col_check_clicked): set
+	  sensitivity of autofit check
+	(cb_col_check_autofit_clicked): new
+	(format_page_update_preview): handle new field
+	(stf_dialog_format_page_cleanup): ditto
+	(stf_dialog_format_page_init): ditto
+	
 2010-06-22  Andreas J. Guelzow <aguelzow pyrshep ca>
 
 	* dialog-sheetobject-size.c (set_params): new
diff --git a/src/dialogs/dialog-stf-format-page.c b/src/dialogs/dialog-stf-format-page.c
index 0263256..b40ce34 100644
--- a/src/dialogs/dialog-stf-format-page.c
+++ b/src/dialogs/dialog-stf-format-page.c
@@ -162,6 +162,8 @@ cb_col_check_clicked (GtkToggleButton *togglebutton, gpointer _i)
 		g_object_get_data (G_OBJECT (togglebutton), "pagedata");
 	gboolean active = gtk_toggle_button_get_active (togglebutton);
 	GtkCellRenderer *renderer;
+	GtkTreeViewColumn* column;
+	GtkWidget *check_autofit;
 
 	g_return_if_fail (i < pagedata->format.col_import_array_len);
 
@@ -194,6 +196,26 @@ cb_col_check_clicked (GtkToggleButton *togglebutton, gpointer _i)
 			g_free (msg);
 		}
 	}
+
+	column = stf_preview_get_column (pagedata->format.renderdata, i);
+	check_autofit = g_object_get_data (G_OBJECT (column), "checkbox-autofit");
+
+	gtk_widget_set_sensitive (check_autofit, active);
+	return;
+}
+
+static void
+cb_col_check_autofit_clicked (GtkToggleButton *togglebutton, gpointer _i)
+{
+	int i = GPOINTER_TO_INT (_i);
+	StfDialogData *pagedata =
+		g_object_get_data (G_OBJECT (togglebutton), "pagedata");
+	gboolean active = gtk_toggle_button_get_active (togglebutton);
+
+	g_return_if_fail (i < pagedata->format.col_import_array_len);
+
+	pagedata->format.col_autofit_array[i] = active;
+
 	return;
 }
 
@@ -494,6 +516,9 @@ format_page_update_preview (StfDialogData *pagedata)
 	col_import_array_len_old = pagedata->format.col_import_array_len;
 	pagedata->format.col_import_array_len = renderdata->colcount;
 
+	pagedata->format.col_autofit_array =
+		g_renew(gboolean, pagedata->format.col_autofit_array,
+			pagedata->format.col_import_array_len);
 	pagedata->format.col_import_array =
 		g_renew(gboolean, pagedata->format.col_import_array,
 			pagedata->format.col_import_array_len);
@@ -505,13 +530,15 @@ format_page_update_preview (StfDialogData *pagedata)
 		if (pagedata->format.col_import_array[i])
 			pagedata->format.col_import_count++;
 	for (i = old_part;
-	     i < pagedata->format.col_import_array_len; i++)
+	     i < pagedata->format.col_import_array_len; i++) {
 		if (pagedata->format.col_import_count < GNM_MAX_COLS) {
 			pagedata->format.col_import_array[i] = TRUE;
 			pagedata->format.col_import_count++;
 		} else {
 			pagedata->format.col_import_array[i] = FALSE;
 		}
+		pagedata->format.col_autofit_array[i] = TRUE;
+	}
 
 	format_page_update_column_selection (pagedata);
 
@@ -525,19 +552,18 @@ format_page_update_preview (StfDialogData *pagedata)
 			stf_preview_get_column (renderdata, i);
 
 		if (NULL == g_object_get_data (G_OBJECT (column), "checkbox")) {
-			GtkWidget *box = gtk_hbox_new (FALSE,5);
 			GtkWidget *vbox = gtk_vbox_new (FALSE,5);
-			GtkWidget *check = gtk_check_button_new ();
+			GtkWidget *check, 
+				*check_autofit = gtk_check_button_new_with_label (_("Auto fit"));
 			char * label_text = g_strdup_printf
 				(pagedata->format.col_header, i+1);
-			GtkWidget *label = gtk_label_new (label_text);
 			GOFormat const *gf = go_format_general ();
 			GtkWidget *format_label = gtk_label_new
 				(go_format_sel_format_classification (gf));
 
+			check = gtk_check_button_new_with_label (label_text);
 			g_free (label_text);
 			gtk_misc_set_alignment (GTK_MISC (format_label), 0, 0);
-			gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
 
 			g_object_set (G_OBJECT (stf_preview_get_cell_renderer
 						(pagedata->format.renderdata, i)),
@@ -546,21 +572,33 @@ format_page_update_preview (StfDialogData *pagedata)
 			gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(check),
 						      pagedata->
 						      format.col_import_array[i]);
+			label_text = g_strdup_printf
+				(_("If this checkbox is selected, "
+				   "column %i will be imported into "
+				   "Gnumeric."), i+1);
 			go_widget_set_tooltip_text
 				(check,
-				 _("If this checkbox is selected, the "
-				   "column will be imported into "
-				   "Gnumeric."));
+				 label_text);
+			go_widget_set_tooltip_text
+				(check_autofit,
+				 _("If this checkbox is selected, "
+				   "the width of the column will be adjusted "
+				   "to the longest entry."));
+			g_free (label_text);
+			gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(check_autofit),
+						      pagedata->
+						      format.col_autofit_array[i]);
 			g_object_set_data (G_OBJECT (check), "pagedata", pagedata);
-			gtk_box_pack_start (GTK_BOX(box), check, FALSE, FALSE, 0);
-			gtk_box_pack_start (GTK_BOX(box), label, TRUE, TRUE, 0);
-			gtk_box_pack_start (GTK_BOX(vbox), box, FALSE, FALSE, 0);
+			g_object_set_data (G_OBJECT (check_autofit), "pagedata", pagedata);
+			gtk_box_pack_start (GTK_BOX(vbox), check, FALSE, FALSE, 0);
 			gtk_box_pack_start (GTK_BOX(vbox), format_label, TRUE, TRUE, 0);
+			gtk_box_pack_start (GTK_BOX(vbox), check_autofit, TRUE, TRUE, 0);
 			gtk_widget_show_all (vbox);
 
 			gtk_tree_view_column_set_widget (column, vbox);
 			g_object_set_data (G_OBJECT (column), "pagedata", pagedata);
 			g_object_set_data (G_OBJECT (column), "checkbox", check);
+			g_object_set_data (G_OBJECT (column), "checkbox-autofit", check_autofit);
 			g_object_set_data (G_OBJECT (column), "formatlabel", format_label);
 			g_object_set_data (G_OBJECT (column->button),
 					   "pagedata", pagedata);
@@ -574,6 +612,10 @@ format_page_update_preview (StfDialogData *pagedata)
 					  "toggled",
 					  G_CALLBACK (cb_col_check_clicked),
 					  GINT_TO_POINTER (i));
+			g_signal_connect (G_OBJECT (check_autofit),
+					  "toggled",
+					  G_CALLBACK (cb_col_check_autofit_clicked),
+					  GINT_TO_POINTER (i));
 			g_signal_connect (G_OBJECT (column->button),
 					  "event",
 					  G_CALLBACK (cb_col_event),
@@ -684,7 +726,9 @@ stf_dialog_format_page_cleanup (StfDialogData *pagedata)
 
 	stf_preview_free (pagedata->format.renderdata);
 	g_free (pagedata->format.col_import_array);
+	g_free (pagedata->format.col_autofit_array);
 	pagedata->format.col_import_array = NULL;
+	pagedata->format.col_autofit_array = NULL;
 	pagedata->format.col_import_array_len = 0;
 	pagedata->format.col_import_count = 0;
 }
@@ -699,6 +743,7 @@ stf_dialog_format_page_init (GladeXML *gui, StfDialogData *pagedata)
 
         /* Create/get object and fill information struct */
 	pagedata->format.col_import_array = NULL;
+	pagedata->format.col_autofit_array = NULL;
 	pagedata->format.col_import_array_len = 0;
 	pagedata->format.col_import_count = 0;
 	pagedata->format.col_header = _("Column %d");
diff --git a/src/dialogs/dialog-stf.c b/src/dialogs/dialog-stf.c
index c03cbf9..693b70c 100644
--- a/src/dialogs/dialog-stf.c
+++ b/src/dialogs/dialog-stf.c
@@ -334,6 +334,9 @@ stf_dialog (WBCGtk *wbcg,
 		dialogresult->parseoptions->col_import_array_len
 			=  pagedata.format.col_import_array_len;
 		pagedata.format.col_import_array = NULL;
+		dialogresult->parseoptions->col_autofit_array
+			=  pagedata.format.col_autofit_array;
+		pagedata.format.col_autofit_array = NULL;
 		pagedata.format.col_import_count = 0;
 		pagedata.format.col_import_array_len = 0;
 	} else {
diff --git a/src/dialogs/dialog-stf.h b/src/dialogs/dialog-stf.h
index c073aa1..9784ea3 100644
--- a/src/dialogs/dialog-stf.h
+++ b/src/dialogs/dialog-stf.h
@@ -70,6 +70,7 @@ typedef struct {
 	int                index;
 	gboolean           manual_change;
 	gboolean           sublist_select;
+        gboolean          *col_autofit_array;
         gboolean          *col_import_array;
         int                col_import_count;
         int                col_import_array_len;
diff --git a/src/stf-parse.c b/src/stf-parse.c
index 3e32712..a1d4971 100644
--- a/src/stf-parse.c
+++ b/src/stf-parse.c
@@ -151,6 +151,7 @@ stf_parse_options_new (void)
 	parseoptions->sep.str = NULL;
 	parseoptions->sep.chr = NULL;
 
+	parseoptions->col_autofit_array = NULL;
 	parseoptions->col_import_array = NULL;
 	parseoptions->col_import_array_len = 0;
 	parseoptions->formats = NULL;
@@ -173,6 +174,7 @@ stf_parse_options_free (StfParseOptions_t *parseoptions)
 	g_return_if_fail (parseoptions != NULL);
 
 	g_free (parseoptions->col_import_array);
+	g_free (parseoptions->col_autofit_array);
 	g_free (parseoptions->locale);
 	g_free (parseoptions->sep.chr);
 
@@ -1244,6 +1246,8 @@ stf_parse_sheet (StfParseOptions_t *parseoptions,
 	GStringChunk *lines_chunk;
 	GPtrArray *lines;
 	gboolean result = TRUE;
+	int col;
+	unsigned int lcol;
 
 	SETUP_LOCALE_SWITCH;
 
@@ -1266,9 +1270,7 @@ stf_parse_sheet (StfParseOptions_t *parseoptions,
 	     result && lrow < lines->len;
 	     row++, lrow++) {
 		GPtrArray *line;
-		int col;
-		unsigned int lcol;
-
+	
 		if (row >= gnm_sheet_get_max_rows (sheet)) {
 			if (!parseoptions->rows_exceeded) {
 				/* FIXME: What locale?  */
@@ -1312,6 +1314,23 @@ stf_parse_sheet (StfParseOptions_t *parseoptions,
 	}
 	END_LOCALE_SWITCH;
 
+	for (lcol = 0, col = start_col; 
+	     lcol < parseoptions->col_import_array_len  && col < gnm_sheet_get_max_cols (sheet); 
+	     lcol++)
+		if (parseoptions->col_import_array == NULL ||
+		    parseoptions->col_import_array_len <= lcol ||
+		    parseoptions->col_import_array[lcol]) {
+			if (parseoptions->col_autofit_array == NULL ||
+			    parseoptions->col_autofit_array[lcol]) {
+				ColRowIndexList *list = colrow_get_index_list (col, col, NULL);
+				ColRowStateGroup  *state = colrow_set_sizes (sheet, TRUE, list, -1);
+				colrow_index_list_destroy (list);
+				g_slist_free (state);
+			}
+			col++;
+		}
+
+
 	if (lines)
 		stf_parse_general_free (lines);
 	g_string_chunk_free (lines_chunk);
diff --git a/src/stf-parse.h b/src/stf-parse.h
index ff87e5f..d093a77 100644
--- a/src/stf-parse.h
+++ b/src/stf-parse.h
@@ -46,6 +46,8 @@ typedef struct {
 
 	int                  rowcount;              /* Number of rows parsed */
 	int                  colcount;              /* Number of columns parsed */
+        gboolean             *col_autofit_array;    /* 0/1 array indicating  */
+	                                            /* which col widths to autofit  */
         gboolean             *col_import_array;     /* 0/1 array indicating  */
 	                                            /* which cols to import  */
 	unsigned int         col_import_array_len;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]