[gnumeric] Fix autofilter handling of column deletion undo. [#625702]



commit f06519c97254437be6d9be4767655b2538a48628
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Sat Jun 16 22:39:44 2012 -0600

    Fix autofilter handling of column deletion undo. [#625702]
    
    2012-06-16  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* src/sheet-filter.c (gnm_filter_set_range): new
    	(gnm_sheet_filter_insdel_colrow): preserve range of to-be-killed filter
    	an d set range on undo

 ChangeLog          |    6 ++++++
 NEWS               |    1 +
 src/sheet-filter.c |   36 ++++++++++++++++++++++++++++++++----
 3 files changed, 39 insertions(+), 4 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index cee2846..22a1a35 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2012-06-16  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* src/sheet-filter.c (gnm_filter_set_range): new
+	(gnm_sheet_filter_insdel_colrow): preserve range of to-be-killed filter
+	and set range on undo
+
 2012-06-15  Morten Welinder  <terra gnome org>
 
 	* src/style-color.c (style_color_new_gdk): Improve roundtrip.
diff --git a/NEWS b/NEWS
index a871620..39ff6cd 100644
--- a/NEWS
+++ b/NEWS
@@ -25,6 +25,7 @@ Andreas:
 	* Improve Mann-Whitney test to allow for two separate data ranges.
 	* Fix custom colour combos for conditional format selection. [#677967]
 	* Fix cell-clearing/autofilter interaction. [#674814]
+	* Fix autofilter handling of column deletion undo. [#625702]
 
 Jean:
 	* Fix graph series headers when a multiple selection is used. [#675913]
diff --git a/src/sheet-filter.c b/src/sheet-filter.c
index 1b9b944..85079e0 100644
--- a/src/sheet-filter.c
+++ b/src/sheet-filter.c
@@ -602,7 +602,6 @@ gnm_filter_attach (GnmFilter *filter, Sheet *sheet)
 
 	for (i = 0 ; i < range_width (&(filter->r)); i++)
 		gnm_filter_add_field (filter, i);
-
 }
 
 
@@ -886,8 +885,8 @@ gnm_sheet_filter_intersect_rows (Sheet const *sheet, int from, int to)
 }
 
 GnmRange *
-gnm_sheet_filter_can_be_extended (Sheet const *sheet, GnmFilter const *f,
-				  GnmRange const *r)
+gnm_sheet_filter_can_be_extended (G_GNUC_UNUSED Sheet const *sheet, 
+				  GnmFilter const *f, GnmRange const *r)
 {
 	if (r->start.row < f->r.start.row || r->end.row > f->r.end.row)
 		return NULL;
@@ -916,7 +915,8 @@ cb_remove_col_undo_free (struct cb_remove_col_undo *r)
 }
 
 static void
-cb_remove_col_undo (GnmFilter *filter, struct cb_remove_col_undo *r, gpointer data)
+cb_remove_col_undo (GnmFilter *filter, struct cb_remove_col_undo *r, 
+		    G_GNUC_UNUSED gpointer data)
 {
 	while (filter->fields->len <= r->col)
 		gnm_filter_add_field (filter, filter->fields->len);
@@ -946,6 +946,20 @@ remove_col (GnmFilter *filter, unsigned col, GOUndo **pundo)
 	g_ptr_array_remove_index (filter->fields, col);
 }
 
+static void
+gnm_filter_set_range (GnmFilter *filter, GnmRange *r)
+{
+	GnmRange old_r = filter->r;
+	int i;
+	int start = r->start.col;
+
+	filter->r = *r;
+	for (i = start; i < old_r.start.col; i++) 
+		gnm_filter_add_field (filter, i - start);
+	for (i = old_r.end.col + 1; i <= r->end.col; i++) 
+		gnm_filter_add_field (filter, i - start);
+}
+
 /**
  * gnm_sheet_filter_insdel_colrow :
  * @sheet :
@@ -972,6 +986,7 @@ gnm_sheet_filter_insdel_colrow (Sheet *sheet,
 		GnmFilter *filter = ptr->data;
 		gboolean kill_filter = FALSE;
 		gboolean reapply_filter = FALSE;
+		GnmRange r = filter->r;
 
 		if (is_cols) {
 			if (start > filter->r.end.col)	/* a */
@@ -1060,7 +1075,9 @@ gnm_sheet_filter_insdel_colrow (Sheet *sheet,
 					    filter->fields->len - 1,
 					    pundo);
 
+			/* Restore the filters range */
 			gnm_filter_remove (filter);
+			filter->r = r;
 
 			if (pundo) {
 				GOUndo *u = go_undo_binary_new
@@ -1073,6 +1090,17 @@ gnm_sheet_filter_insdel_colrow (Sheet *sheet,
 			}
 			gnm_filter_unref (filter);
 		} else if (reapply_filter) {
+			GnmRange *range = g_new (GnmRange, 1);
+			*range = r;
+			if (pundo) {
+				GOUndo *u = go_undo_binary_new
+					(gnm_filter_ref (filter),
+					 range,
+					 (GOUndoBinaryFunc)gnm_filter_set_range,
+					 (GFreeFunc)gnm_filter_unref,
+					 g_free);
+				*pundo = go_undo_combine (*pundo, u);
+			}			
 			gnm_filter_update_active (filter);
 			gnm_filter_reapply (filter);
 		}



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