[gnumeric] scenario: switch dialog to new creation api.
- From: Morten Welinder <mortenw src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnumeric] scenario: switch dialog to new creation api.
- Date: Wed, 25 Nov 2009 15:04:24 +0000 (UTC)
commit 280607c5c8cee51482dfecd4e2be24d1d030d916
Author: Morten Welinder <terra gnome org>
Date: Wed Nov 25 10:04:03 2009 -0500
scenario: switch dialog to new creation api.
src/dialogs/dialog-scenarios.c | 31 ++++++++--------------------
src/tools/scenarios.c | 43 ----------------------------------------
src/tools/scenarios.h | 5 ----
3 files changed, 9 insertions(+), 70 deletions(-)
---
diff --git a/src/dialogs/dialog-scenarios.c b/src/dialogs/dialog-scenarios.c
index 435800b..63837ee 100644
--- a/src/dialogs/dialog-scenarios.c
+++ b/src/dialogs/dialog-scenarios.c
@@ -363,17 +363,13 @@ scenario_add_ok_clicked_cb (G_GNUC_UNUSED GtkWidget *button,
GtkWidget *entry, *comment_view;
GtkTextBuffer *buf;
GtkTextIter start, end;
- GnmRangeRef const *rr = NULL;
- gboolean res;
- GnmScenario *scenario;
+ GnmScenario *sc;
+ GnmSheetRange sr;
cell_range = gnm_expr_entry_parse_as_value
(GNM_EXPR_ENTRY (state->base.input_entry), state->base.sheet);
- if (cell_range != NULL)
- rr = value_get_rangeref (cell_range);
-
- if (rr == NULL) {
+ if (!cell_range || !gnm_sheet_range_from_value (&sr, cell_range)) {
go_gtk_notice_dialog (GTK_WINDOW (state->base.dialog),
GTK_MESSAGE_ERROR,
_("Invalid changing cells"));
@@ -381,7 +377,7 @@ scenario_add_ok_clicked_cb (G_GNUC_UNUSED GtkWidget *button,
return;
}
- if (rr->a.sheet != state->base.sheet) {
+ if (sr.sheet && sr.sheet != state->base.sheet) {
go_gtk_notice_dialog (GTK_WINDOW (state->base.dialog),
GTK_MESSAGE_ERROR,
_("Changing cells should be on the current "
@@ -418,21 +414,12 @@ scenario_add_ok_clicked_cb (G_GNUC_UNUSED GtkWidget *button,
wbc = WORKBOOK_CONTROL (state->base.wbcg);
- res = scenario_add_new (name, cell_range,
- (gchar *) gnm_expr_entry_get_text
- (GNM_EXPR_ENTRY (state->base.input_entry)),
- comment, state->base.sheet, &scenario);
+ sc = gnm_sheet_scenario_new (state->base.sheet, name);
+ if (comment && comment[0])
+ gnm_scenario_set_comment (sc, comment);
+ gnm_scenario_add_area (sc, &sr, TRUE);
- cmd_scenario_add (wbc, scenario, state->base.sheet);
-
- if (res)
- go_gtk_notice_dialog (GTK_WINDOW (state->base.dialog),
- GTK_MESSAGE_WARNING,
- _("Changing cells contain at least one "
- "expression that is not just a value. "
- "Note that showing the scenario will "
- "overwrite the formula with its current "
- "value."));
+ cmd_scenario_add (wbc, sc, state->base.sheet);
g_free (name);
g_free (comment);
diff --git a/src/tools/scenarios.c b/src/tools/scenarios.c
index 794c9b3..f6113fa 100644
--- a/src/tools/scenarios.c
+++ b/src/tools/scenarios.c
@@ -245,49 +245,6 @@ collect_cb (int col, int row, GnmValue *v, collect_cb_t *p)
return value_dup (cell->value);
}
-/*
- * Collects cell values of a scenario. If any of the cells contain an
- * expression return TRUE so that the user can be warned about it.
- */
-static gboolean
-collect_values (Sheet *sheet, GnmScenario *s, GnmValueRange *range)
-{
- int cols, rows;
- collect_cb_t cb;
-
- range_init_value (&s->range, (GnmValue *) range);
-
- rows = s->range.end.row - s->range.start.row + 1;
- cols = s->range.end.col - s->range.start.col + 1;
- s->changing_cells = g_new0 (GnmValue *, rows * cols);
-
- cb.expr_flag = FALSE;
- cb.sheet = sheet;
- scenario_for_each_value (s, (ScenarioValueCB) collect_cb, &cb);
-
- return cb.expr_flag;
-}
-
-/* Doesn't actually add the new scenario into the sheet's scenario list. */
-gboolean
-scenario_add_new (gchar const *name,
- GnmValue *changing_cells,
- gchar const *cell_sel_str,
- gchar const *comment,
- Sheet *sheet,
- GnmScenario **new_scenario)
-{
- GnmScenario *scenario = gnm_sheet_scenario_new (sheet, name);
- gboolean res = collect_values (sheet, scenario, (GnmValueRange *) changing_cells);
-
- gnm_scenario_set_comment (scenario, comment);
- scenario->cell_sel_str = g_strdup (cell_sel_str);
- sheet_redraw_all (sheet, TRUE);
-
- *new_scenario = scenario;
- return res;
-}
-
/* Scenario: Duplicate sheet ***********************************************/
typedef struct {
diff --git a/src/tools/scenarios.h b/src/tools/scenarios.h
index 3326df8..ffbde80 100644
--- a/src/tools/scenarios.h
+++ b/src/tools/scenarios.h
@@ -66,10 +66,5 @@ typedef struct _scenario_cmd_t {
GnmScenario *scenario_show (GnmScenario *scenario,
GnmScenario *old_values,
data_analysis_output_t *dao);
-gboolean scenario_add_new (gchar const *name,
- GnmValue *changing_cells,
- gchar const *cell_sel_str,
- gchar const *comment,
- Sheet *sheet, GnmScenario **new_scenario);
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]