[gnumeric] Solver: add undo support for the report.



commit 0dc8e3d9ae17e87bfa2de359d4d099936a0ffcfe
Author: Morten Welinder <terra gnome org>
Date:   Tue Jul 10 15:36:30 2012 -0400

    Solver: add undo support for the report.

 NEWS                        |    1 +
 src/dialogs/ChangeLog       |    4 ++++
 src/dialogs/dialog-solver.c |   33 +++++++++++++++++++++++++++++----
 3 files changed, 34 insertions(+), 4 deletions(-)
---
diff --git a/NEWS b/NEWS
index 7a44110..ed0cf23 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,7 @@ Morten:
 	* Speed up operations that iterate over cells in large areas.
 	* Fix problems with linear solvers and cross-sheet target.
 	* Fix python-loader vs. goffice interface problem.
+	* Add solver report.
 
 --------------------------------------------------------------------------
 Gnumeric 1.11.4
diff --git a/src/dialogs/ChangeLog b/src/dialogs/ChangeLog
index d36545c..6409bf3 100644
--- a/src/dialogs/ChangeLog
+++ b/src/dialogs/ChangeLog
@@ -1,3 +1,7 @@
+2012-07-10  Morten Welinder  <terra gnome org>
+
+	* dialog-solver.c (run_solver): Add undo support for report.
+
 2012-07-08  Morten Welinder  <terra gnome org>
 
 	* dialog-solver.c (run_solver): Create a report when requested.
diff --git a/src/dialogs/dialog-solver.c b/src/dialogs/dialog-solver.c
index 9f261a8..a4e4ddf 100644
--- a/src/dialogs/dialog-solver.c
+++ b/src/dialogs/dialog-solver.c
@@ -659,8 +659,8 @@ run_solver (SolverState *state, GnmSolverParameters *param)
 
 	sol = gnm_solver_factory_functional (param->options.algorithm,
 					     state->wbcg)
-	    ? gnm_solver_factory_create (param->options.algorithm, param)
-	    : NULL;
+		? gnm_solver_factory_create (param->options.algorithm, param)
+		: NULL;
 	if (!sol) {
 		go_gtk_notice_dialog (top, GTK_MESSAGE_ERROR,
 				      _("The chosen solver is not functional."));
@@ -810,10 +810,35 @@ run_solver (SolverState *state, GnmSolverParameters *param)
 		GOUndo *redo;
 
 		gnm_solver_store_result (sol);
-		if (param->options.program_report)
+		redo = clipboard_copy_range_undo (sr.sheet, &sr.range);
+
+		if (param->options.program_report) {
+			Workbook *wb = param->sheet->workbook;
+			GOUndo *undo_report, *redo_report;
+
+			/* This is a bit of overkill -- it just removes the
+			   sheet that create_report will add.  However, if
+			   in the future we add multiple sheets then this
+			   should still be good.  */
+			undo_report = go_undo_binary_new
+				(wb,
+				 workbook_sheet_state_new (wb),
+				 (GOUndoBinaryFunc)workbook_sheet_state_restore,
+				 NULL,
+				 (GFreeFunc)workbook_sheet_state_free);
+			undo = go_undo_combine (undo, undo_report);
+
 			create_report (sol, state);
 
-		redo = clipboard_copy_range_undo (sr.sheet, &sr.range);
+			redo_report = go_undo_binary_new
+				(wb,
+				 workbook_sheet_state_new (wb),
+				 (GOUndoBinaryFunc)workbook_sheet_state_restore,
+				 NULL,
+				 (GFreeFunc)workbook_sheet_state_free);
+			redo = go_undo_combine (redo, redo_report);
+		}
+
 		cmd_generic (WORKBOOK_CONTROL (state->wbcg),
 			     _("Running solver"),
 			     undo, redo);



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