Commit 237ebd5b authored by Jody Goldberg's avatar Jody Goldberg Committed by Jody Goldberg
Browse files

fix logic to avoid adding a bogus view.


2001-05-25  Jody Goldberg <jgoldberg@home.com>

	* src/workbook-view.c (wb_view_open_custom) : fix logic to avoid
	  adding a bogus view.

2001-05-24  Jody Goldberg <jgoldberg@home.com>

	* src/eval.c (workbook_recalc) : don't clear the flag until after the
	  calc is complete in case there is a cycle.
	(cell_eval) : ditto.
parent 836fcfa6
2001-05-25 Jody Goldberg <jgoldberg@home.com>
* src/workbook-view.c (wb_view_open_custom) : fix logic to avoid
adding a bogus view.
2001-05-24 Jody Goldberg <jgoldberg@home.com>
* src/eval.c (workbook_recalc) : don't clear the flag until after the
calc is complete in case there is a cycle.
(cell_eval) : ditto.
2001-05-24 Jon K Hellan <hellan@acm.org>
* src/workbook-control-gui.c (sheet_to_page_index): Rename view to
......
2001-05-25 Jody Goldberg <jgoldberg@home.com>
* src/workbook-view.c (wb_view_open_custom) : fix logic to avoid
adding a bogus view.
2001-05-24 Jody Goldberg <jgoldberg@home.com>
* src/eval.c (workbook_recalc) : don't clear the flag until after the
calc is complete in case there is a cycle.
(cell_eval) : ditto.
2001-05-24 Jon K Hellan <hellan@acm.org>
* src/workbook-control-gui.c (sheet_to_page_index): Rename view to
......
2001-05-25 Jody Goldberg <jgoldberg@home.com>
* src/workbook-view.c (wb_view_open_custom) : fix logic to avoid
adding a bogus view.
2001-05-24 Jody Goldberg <jgoldberg@home.com>
* src/eval.c (workbook_recalc) : don't clear the flag until after the
calc is complete in case there is a cycle.
(cell_eval) : ditto.
2001-05-24 Jon K Hellan <hellan@acm.org>
* src/workbook-control-gui.c (sheet_to_page_index): Rename view to
......
2001-05-25 Jody Goldberg <jgoldberg@home.com>
* src/workbook-view.c (wb_view_open_custom) : fix logic to avoid
adding a bogus view.
2001-05-24 Jody Goldberg <jgoldberg@home.com>
* src/eval.c (workbook_recalc) : don't clear the flag until after the
calc is complete in case there is a cycle.
(cell_eval) : ditto.
2001-05-24 Jon K Hellan <hellan@acm.org>
* src/workbook-control-gui.c (sheet_to_page_index): Rename view to
......
2001-05-25 Jody Goldberg <jgoldberg@home.com>
* src/workbook-view.c (wb_view_open_custom) : fix logic to avoid
adding a bogus view.
2001-05-24 Jody Goldberg <jgoldberg@home.com>
* src/eval.c (workbook_recalc) : don't clear the flag until after the
calc is complete in case there is a cycle.
(cell_eval) : ditto.
2001-05-24 Jon K Hellan <hellan@acm.org>
* src/workbook-control-gui.c (sheet_to_page_index): Rename view to
......
......@@ -146,14 +146,15 @@ cell_destroy (Cell *cell)
* it should not be used by anyone. It is an internal
* function.
**/
void
gboolean
cell_eval_content (Cell *cell)
{
Value *v;
EvalPos pos;
int max_iterate = 100;
if (!cell_has_expr (cell))
return;
return TRUE;
#ifdef DEBUG_EVALUATION
if (dependency_debugging > 1) {
......@@ -166,8 +167,29 @@ cell_eval_content (Cell *cell)
}
#endif
v = eval_expr (eval_pos_init_cell (&pos, cell),
cell->base.expression, EVAL_STRICT);
if (cell->base.flags & DEPENDENT_BEING_CALCULATED) {
/* Init to 0 */
if (cell->value->type == VALUE_ERROR) {
value_release (cell->value);
cell->value = value_new_int (0);
} else if (cell->value == NULL)
cell->value = value_new_int (0);
cell->base.flags &= ~DEPENDENT_BEING_CALCULATED;
puts ("bottom iterate");
return FALSE;
}
eval_pos_init_cell (&pos, cell);
iterate :
cell->base.flags |= DEPENDENT_BEING_CALCULATED;
v = eval_expr (&pos, cell->base.expression, EVAL_STRICT);
if (cell->base.flags & DEPENDENT_BEING_CALCULATED)
cell->base.flags &= ~DEPENDENT_BEING_CALCULATED;
else if (max_iterate-- > 0) {
printf ("start iterate %d\n", max_iterate);
goto iterate;
}
#ifdef DEBUG_EVALUATION
if (dependency_debugging > 1) {
......@@ -184,6 +206,7 @@ cell_eval_content (Cell *cell)
cell_assign_value (cell, v, NULL);
sheet_redraw_cell (cell);
return TRUE;
}
/*
......
......@@ -41,11 +41,10 @@ struct _Cell {
/**
* Manage cells
*/
Cell *cell_copy (Cell const *cell);
void cell_destroy (Cell *cell);
void cell_relocate (Cell *cell, ExprRewriteInfo *rwinfo);
void cell_eval_content (Cell *cell);
void cell_content_changed (Cell *cell);
Cell *cell_copy (Cell const *cell);
void cell_destroy (Cell *cell);
void cell_relocate (Cell *cell, ExprRewriteInfo *rwinfo);
gboolean cell_eval_content (Cell *cell);
/**
* Cell state checking
......
......@@ -771,14 +771,17 @@ cell_drop_dependencies (Cell *cell)
cell->base.expression, REMOVE_DEPS);
}
void
gboolean
cell_eval (Cell *cell)
{
g_return_if_fail (cell != NULL);
g_return_val_if_fail (cell != NULL, TRUE);
if (cell->base.flags & DEPENDENT_NEEDS_RECALC) {
cell->base.flags &= ~DEPENDENT_NEEDS_RECALC;
cell_eval_content (cell);
if (cell_eval_content (cell))
cell->base.flags &= ~DEPENDENT_NEEDS_RECALC;
else
return FALSE;
}
return TRUE;
}
/**
......@@ -1131,15 +1134,23 @@ workbook_recalc (Workbook *wb)
if (dep->flags & DEPENDENT_NEEDS_RECALC) {
int const t = (dep->flags & DEPENDENT_TYPE_MASK);
dep->flags &= ~DEPENDENT_NEEDS_RECALC;
if (t != DEPENDENT_CELL) {
DependentClass *klass = g_ptr_array_index (dep_classes, t);
g_return_if_fail (klass);
(*klass->eval) (dep);
} else
cell_eval_content (DEP_TO_CELL (dep));
dep->flags &= ~DEPENDENT_NEEDS_RECALC;
} else {
gboolean finished = cell_eval_content (DEP_TO_CELL (dep));
/* This should always be the top of the stack */
g_return_if_fail (finished);
/* Don't clear flag until after in case we iterate */
dep->flags &= ~DEPENDENT_NEEDS_RECALC;
}
}
}
}
......
......@@ -47,9 +47,9 @@ void cb_dependent_queue_recalc (Dependent *dep, gpointer ignore);
void cell_add_dependencies (Cell *cell);
void cell_drop_dependencies (Cell *cell);
void cell_eval (Cell *cell);
void cell_queue_recalc (Cell const *cell);
void cell_foreach_dep (Cell const *cell, DepFunc func, gpointer user);
gboolean cell_eval (Cell *cell);
void sheet_region_queue_recalc (Sheet const *sheet, Range const *range);
/* Do we need this ?
......
......@@ -771,14 +771,17 @@ cell_drop_dependencies (Cell *cell)
cell->base.expression, REMOVE_DEPS);
}
void
gboolean
cell_eval (Cell *cell)
{
g_return_if_fail (cell != NULL);
g_return_val_if_fail (cell != NULL, TRUE);
if (cell->base.flags & DEPENDENT_NEEDS_RECALC) {
cell->base.flags &= ~DEPENDENT_NEEDS_RECALC;
cell_eval_content (cell);
if (cell_eval_content (cell))
cell->base.flags &= ~DEPENDENT_NEEDS_RECALC;
else
return FALSE;
}
return TRUE;
}
/**
......@@ -1131,15 +1134,23 @@ workbook_recalc (Workbook *wb)
if (dep->flags & DEPENDENT_NEEDS_RECALC) {
int const t = (dep->flags & DEPENDENT_TYPE_MASK);
dep->flags &= ~DEPENDENT_NEEDS_RECALC;
if (t != DEPENDENT_CELL) {
DependentClass *klass = g_ptr_array_index (dep_classes, t);
g_return_if_fail (klass);
(*klass->eval) (dep);
} else
cell_eval_content (DEP_TO_CELL (dep));
dep->flags &= ~DEPENDENT_NEEDS_RECALC;
} else {
gboolean finished = cell_eval_content (DEP_TO_CELL (dep));
/* This should always be the top of the stack */
g_return_if_fail (finished);
/* Don't clear flag until after in case we iterate */
dep->flags &= ~DEPENDENT_NEEDS_RECALC;
}
}
}
}
......
......@@ -47,9 +47,9 @@ void cb_dependent_queue_recalc (Dependent *dep, gpointer ignore);
void cell_add_dependencies (Cell *cell);
void cell_drop_dependencies (Cell *cell);
void cell_eval (Cell *cell);
void cell_queue_recalc (Cell const *cell);
void cell_foreach_dep (Cell const *cell, DepFunc func, gpointer user);
gboolean cell_eval (Cell *cell);
void sheet_region_queue_recalc (Sheet const *sheet, Range const *range);
/* Do we need this ?
......
......@@ -694,70 +694,68 @@ wb_view_open (WorkbookView *wbv, WorkbookControl *wbc,
*/
gboolean
wb_view_open_custom (WorkbookView *wbv, WorkbookControl *wbc,
GnumFileOpener *fo, gchar const *file_name)
GnumFileOpener const *fo, gchar const *file_name)
{
gboolean success = FALSE;
IOContext *io_context;
Workbook *new_wb = NULL;
WorkbookView *new_wbv = NULL;
g_return_val_if_fail (IS_WORKBOOK_CONTROL (wbc), FALSE);
g_return_val_if_fail (fo == NULL || IS_GNUM_FILE_OPENER (fo), FALSE);
g_return_val_if_fail (file_name != NULL, FALSE);
io_context = gnumeric_io_context_new (wbc);
if (g_file_exists (file_name)) {
IOContext *io_context = gnumeric_io_context_new (wbc);
/* Search for an applicable opener */
if (fo == NULL) {
GList *l;
for (l = get_file_openers (); l != NULL; l = l->next) {
GnumFileOpener *tmp_fo;
tmp_fo = GNUM_FILE_OPENER (l->data);
GnumFileOpener const *tmp_fo = GNUM_FILE_OPENER (l->data);
if (gnum_file_opener_probe (tmp_fo, file_name)) {
fo = tmp_fo;
break;
}
}
}
if (fo != NULL) {
Workbook *tmp_wb;
WorkbookView *tmp_wbv;
gboolean old;
tmp_wb = workbook_new ();
tmp_wbv = workbook_view_new (tmp_wb);
new_wbv = workbook_view_new (NULL);
new_wb = wb_view_workbook (new_wbv);
/* disable recursive dirtying while loading */
old = workbook_enable_recursive_dirty (tmp_wb, FALSE);
gnum_file_opener_open (fo, io_context, tmp_wbv, file_name);
workbook_enable_recursive_dirty (tmp_wb, old);
old = workbook_enable_recursive_dirty (new_wb, FALSE);
gnum_file_opener_open (fo, io_context, new_wbv, file_name);
workbook_enable_recursive_dirty (new_wb, old);
if (!gnumeric_io_error_occurred (io_context) &&
workbook_sheet_count (tmp_wb) == 0)
workbook_sheet_count (new_wb) == 0)
gnumeric_io_error_read (io_context, _("No sheets in workbook."));
if (!gnumeric_io_error_occurred (io_context)) {
workbook_set_dirty (tmp_wb, FALSE);
new_wb = tmp_wb;
} else
gtk_object_destroy (GTK_OBJECT (tmp_wb));
if (!gnumeric_io_error_occurred (io_context))
workbook_set_dirty (new_wb, FALSE);
else
gtk_object_destroy (GTK_OBJECT (new_wb));
} else
gnumeric_io_error_read (io_context, _("Unsupported file format."));
if (gnumeric_io_has_error_info (io_context))
gnumeric_io_error_info_display (io_context);
gnumeric_io_context_free (io_context);
} else {
new_wb = workbook_new_with_sheets (1);
new_wbv = workbook_view_new (new_wb);
workbook_set_saveinfo (new_wb, file_name, FILE_FL_NEW, NULL);
}
if (gnumeric_io_has_error_info (io_context))
gnumeric_io_error_info_display (io_context);
if (!gnumeric_io_error_occurred (io_context)) {
WorkbookView *new_wbv;
if (new_wbv != NULL) {
Workbook *old_wb;
g_return_val_if_fail (new_wb != NULL, FALSE);
new_wbv = workbook_view_new (new_wb);
old_wb = wb_control_workbook (wbc);
if (workbook_is_pristine (old_wb)) {
gtk_object_ref (GTK_OBJECT (wbc));
......@@ -772,12 +770,9 @@ wb_view_open_custom (WorkbookView *wbv, WorkbookControl *wbc,
g_return_val_if_fail (!workbook_is_dirty (new_wb), FALSE);
sheet_update (wb_view_cur_sheet (new_wbv));
success = TRUE;
return TRUE;
} else {
g_return_val_if_fail (new_wb == NULL, FALSE);
success = FALSE;
return FALSE;
}
gnumeric_io_context_free (io_context);
return success;
}
......@@ -80,7 +80,7 @@ gboolean wb_view_save (WorkbookView *wbv, WorkbookControl *wbc);
gboolean wb_view_open (WorkbookView *wbv, WorkbookControl *wbc,
char const *file_name);
gboolean wb_view_open_custom (WorkbookView *wbv, WorkbookControl *wbc,
GnumFileOpener *fo, char const *file_name);
GnumFileOpener const *fo, char const *file_name);
#define WORKBOOK_VIEW_FOREACH_CONTROL(wbv, control, code) \
do { \
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment