[gnumeric] scenarios: fix life cycle in undo/redo.
- From: Morten Welinder <mortenw src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnumeric] scenarios: fix life cycle in undo/redo.
- Date: Thu, 26 Nov 2009 02:22:47 +0000 (UTC)
commit 931d6f2cc6b42161a88707601f6e494c54ded6ac
Author: Morten Welinder <terra gnome org>
Date: Wed Nov 25 21:22:26 2009 -0500
scenarios: fix life cycle in undo/redo.
ChangeLog | 5 +++++
plugins/openoffice/openoffice-write.c | 2 +-
src/commands.c | 18 ++++++------------
src/dialogs/dialog-scenarios.c | 2 +-
src/tools/scenarios.c | 26 +++++++++++++++++++++++---
src/tools/scenarios.h | 4 ++--
6 files changed, 38 insertions(+), 19 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index c50443e..585e3b7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2009-11-25 Morten Welinder <terra gnome org>
+
+ * src/commands.c (cmd_scenario_add_redo, cmd_scenario_add_undo):
+ fix life cycle.
+
2009-11-21 Andreas J. Guelzow <aguelzow pyrshep ca>
* component/Gnumeric-embed.xml.in: add "Normality Test..." menu item
diff --git a/plugins/openoffice/openoffice-write.c b/plugins/openoffice/openoffice-write.c
index 6acf17f..c5fab3f 100644
--- a/plugins/openoffice/openoffice-write.c
+++ b/plugins/openoffice/openoffice-write.c
@@ -57,7 +57,7 @@
#include <sheet-filter.h>
#include <print-info.h>
#include <parse-util.h>
-#include <tools/scenarios.h>
+#include <tools/dao.h>
#include <gutils.h>
#include <style-conditions.h>
diff --git a/src/commands.c b/src/commands.c
index 16b5cf1..7361839 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -5967,7 +5967,7 @@ cmd_remove_name (WorkbookControl *wbc, GnmNamedExpr *nexpr)
typedef struct {
GnmCommand cmd;
- GnmScenario *scenario;
+ GnmScenario *scenario;
} CmdScenarioAdd;
MAKE_GNM_COMMAND (CmdScenarioAdd, cmd_scenario_add, NULL)
@@ -5976,24 +5976,18 @@ static gboolean
cmd_scenario_add_redo (GnmCommand *cmd, WorkbookControl *wbc)
{
CmdScenarioAdd *me = CMD_SCENARIO_ADD (cmd);
- GnmScenario *sc = gnm_scenario_dup (me->scenario, me->cmd.sheet);
-
+ GnmScenario *sc = g_object_ref (me->scenario);
gnm_sheet_scenario_add (sc->sheet, sc);
-
return FALSE;
}
static gboolean
cmd_scenario_add_undo (GnmCommand *cmd,
- G_GNUC_UNUSED WorkbookControl *wbc)
+ G_GNUC_UNUSED WorkbookControl *wbc)
{
CmdScenarioAdd *me = CMD_SCENARIO_ADD (cmd);
- GnmScenario *sc = gnm_sheet_scenario_find (me->cmd.sheet,
- me->scenario->name);
-
- if (sc)
- gnm_sheet_scenario_remove (sc->sheet, sc);
-
+ GnmScenario *sc = me->scenario;
+ gnm_sheet_scenario_remove (sc->sheet, sc);
return FALSE;
}
@@ -6016,7 +6010,7 @@ cmd_scenario_add (WorkbookControl *wbc, GnmScenario *s, Sheet *sheet)
me = g_object_new (CMD_SCENARIO_ADD_TYPE, NULL);
- me->scenario = s;
+ me->scenario = s; /* Take ownership */
me->cmd.sheet = sheet;
me->cmd.size = 1;
me->cmd.cmd_descriptor = g_strdup (_("Add scenario"));
diff --git a/src/dialogs/dialog-scenarios.c b/src/dialogs/dialog-scenarios.c
index 3beb9e7..be81739 100644
--- a/src/dialogs/dialog-scenarios.c
+++ b/src/dialogs/dialog-scenarios.c
@@ -534,7 +534,7 @@ find_scenario_strs (GList *scenarios, gchar *name,
g_free (buf1);
g_free (buf2);
- *cells = buf1 = g_strdup (scenario->cell_sel_str);
+ *cells = buf1 = gnm_scenario_get_range_str (scenario);
*comment = buf2 = g_strdup (scenario->comment);
return FALSE;
}
diff --git a/src/tools/scenarios.c b/src/tools/scenarios.c
index f63fd17..15305c0 100644
--- a/src/tools/scenarios.c
+++ b/src/tools/scenarios.c
@@ -143,8 +143,6 @@ gnm_scenario_finalize (GObject *obj)
go_slist_free_custom (sc->items, (GFreeFunc)gnm_scenario_item_free);
- g_free (sc->cell_sel_str);
-
scenario_for_each_value (sc, cb_value_free, NULL);
g_free (sc->changing_cells);
@@ -266,6 +264,29 @@ gnm_scenario_apply (GnmScenario *sc)
return undo;
}
+char *
+gnm_scenario_get_range_str (GnmScenario *sc)
+{
+ GString *str;
+ GSList *l;
+
+ g_return_val_if_fail (GNM_IS_SCENARIO (sc), NULL);
+
+ str = g_string_new (NULL);
+ for (l = sc->items; l; l = l->next) {
+ GnmScenarioItem const *sci = l->data;
+ GnmValue const *vrange;
+ if (sci->value || !gnm_scenario_item_valid (sci, NULL))
+ continue;
+ if (str->len)
+ g_string_append_c (str, ',');
+ vrange = gnm_expr_top_get_constant (sci->dep.texpr);
+ g_string_append (str, value_peek_string (vrange));
+ }
+
+ return g_string_free (str, FALSE);
+}
+
/* ------------------------------------------------------------------------- */
typedef struct {
@@ -311,7 +332,6 @@ gnm_scenario_dup (GnmScenario *src, Sheet *new_sheet)
dst = gnm_scenario_new (src->name, new_sheet);
gnm_scenario_set_comment (dst, src->comment);
- dst->cell_sel_str = g_strdup (src->cell_sel_str);
dst->range = src->range;
cb.rows = src->range.end.row - src->range.start.row + 1;
diff --git a/src/tools/scenarios.h b/src/tools/scenarios.h
index 4b3819e..6289375 100644
--- a/src/tools/scenarios.h
+++ b/src/tools/scenarios.h
@@ -38,8 +38,6 @@ struct GnmScenario_ {
GnmValue **changing_cells;
GnmRange range;
-
- gchar *cell_sel_str;
};
typedef struct {
@@ -58,6 +56,8 @@ void gnm_scenario_add_area (GnmScenario *sc, const GnmSheetRange *sr);
GOUndo *gnm_scenario_apply (GnmScenario *sc);
+char *gnm_scenario_get_range_str (GnmScenario *sc);
+
/* ------------------------------------------------------------------------- */
GnmScenario *scenario_show (GnmScenario *scenario,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]