[gnumeric] Ins/del col/row: partially fix updating of names.
- From: Morten Welinder <mortenw src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnumeric] Ins/del col/row: partially fix updating of names.
- Date: Mon, 4 May 2009 16:09:00 -0400 (EDT)
commit accc40289d96df320a4e0f01857d5565bac70129
Author: Morten Welinder <terra gnome org>
Date: Mon May 4 16:08:20 2009 -0400
Ins/del col/row: partially fix updating of names.
---
ChangeLog | 8 +++++
plugins/excel/ms-excel-write.c | 2 +-
src/dependent.c | 58 ++++++++++++++++++++++++++++++++++++---
src/workbook.c | 11 +++++---
src/workbook.h | 3 +-
5 files changed, 71 insertions(+), 11 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 7b04f29..f01b817 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2009-05-04 Morten Welinder <terra gnome org>
+
+ * src/workbook.c (workbook_foreach_name): Add extra globals_only
+ flag. Caller changed.
+
+ * src/dependent.c (dependents_relocate): Relocate sheet-local and
+ global names too. Minor issues remain.
+
2009-05-03 Andreas J. Guelzow <aguelzow pyrshep ca>
* src/gnm-so-filled.c (gnm_so_filled_draw_cairo) use
diff --git a/plugins/excel/ms-excel-write.c b/plugins/excel/ms-excel-write.c
index 6889bde..0a1850f 100644
--- a/plugins/excel/ms-excel-write.c
+++ b/plugins/excel/ms-excel-write.c
@@ -5253,7 +5253,7 @@ excel_write_WRITEACCESS (BiffPut *bp)
static void
excel_foreach_name (ExcelWriteState *ewb, GHFunc func)
{
- workbook_foreach_name (ewb->base.wb, func, ewb);
+ workbook_foreach_name (ewb->base.wb, FALSE, func, ewb);
}
static void
diff --git a/src/dependent.c b/src/dependent.c
index c1cfb35..5c645b8 100644
--- a/src/dependent.c
+++ b/src/dependent.c
@@ -1925,6 +1925,58 @@ cb_collect_names (GnmNamedExpr *nexpr,
*l = g_slist_prepend (*l, nexpr);
}
+struct cb_remote_names {
+ GSList *names;
+ Workbook *wb;
+};
+
+static void
+cb_remote_names1 (G_GNUC_UNUSED const char *name,
+ GnmNamedExpr *nexpr,
+ struct cb_remote_names *data)
+{
+ data->names = g_slist_prepend (data->names, nexpr);
+}
+
+static void
+cb_remote_names2 (GnmNamedExpr *nexpr,
+ G_GNUC_UNUSED gpointer value,
+ struct cb_remote_names *data)
+{
+ Workbook *wb =
+ nexpr->pos.sheet ? nexpr->pos.sheet->workbook : nexpr->pos.wb;
+ if (wb != data->wb)
+ data->names = g_slist_prepend (data->names, nexpr);
+}
+
+/*
+ * Get a list of all names that (may) reference data in a given sheet.
+ * This is approximated as all names in the sheet, all global names in
+ * its workbook, and all external references that actually mention the
+ * sheet explicitly.
+ */
+static GSList *
+names_referencing_sheet (Sheet *sheet)
+{
+ struct cb_remote_names data;
+
+ data.names = NULL;
+ data.wb = sheet->workbook;
+
+ workbook_foreach_name (sheet->workbook, TRUE,
+ (GHFunc)cb_remote_names1,
+ &data);
+ gnm_sheet_foreach_name (sheet, (GHFunc)cb_remote_names1, &data);
+
+ if (sheet->deps->referencing_names)
+ g_hash_table_foreach (sheet->deps->referencing_names,
+ (GHFunc)cb_remote_names2,
+ &data);
+
+ return data.names;
+}
+
+
/**
* dependents_relocate:
* @rinfo : the descriptor record for what is being moved where.
@@ -2059,12 +2111,8 @@ dependents_relocate (GnmExprRelocateInfo const *rinfo)
case GNM_EXPR_RELOCATE_COLS:
case GNM_EXPR_RELOCATE_ROWS: {
- GSList *names = NULL, *l;
+ GSList *l, *names = names_referencing_sheet (sheet);
- if (sheet->deps->referencing_names)
- g_hash_table_foreach (sheet->deps->referencing_names,
- (GHFunc)cb_collect_names,
- &names);
for (l = names; l; l = l->next) {
GnmNamedExpr *nexpr = l->data;
GnmExprTop const *newtree =
diff --git a/src/workbook.c b/src/workbook.c
index 54af5d6..787a087 100644
--- a/src/workbook.c
+++ b/src/workbook.c
@@ -536,16 +536,19 @@ workbook_local_functions (Workbook const *wb)
}
void
-workbook_foreach_name (Workbook const *wb, GHFunc func, gpointer data)
+workbook_foreach_name (Workbook const *wb, gboolean globals_only,
+ GHFunc func, gpointer data)
{
g_return_if_fail (IS_WORKBOOK (wb));
if (wb->names)
gnm_named_expr_collection_foreach (wb->names, func, data);
- WORKBOOK_FOREACH_SHEET (wb, sheet, {
- gnm_sheet_foreach_name (sheet, func, data);
- });
+ if (!globals_only) {
+ WORKBOOK_FOREACH_SHEET (wb, sheet, {
+ gnm_sheet_foreach_name (sheet, func, data);
+ });
+ }
}
diff --git a/src/workbook.h b/src/workbook.h
index fdb3b1b..ceb236f 100644
--- a/src/workbook.h
+++ b/src/workbook.h
@@ -58,7 +58,8 @@ GPtrArray *workbook_cells (Workbook *wb, gboolean comments,
GnmSheetVisibility vis);
GSList *workbook_local_functions (Workbook const *wb);
-void workbook_foreach_name (Workbook const *wb, GHFunc func, gpointer data);
+void workbook_foreach_name (Workbook const *wb, gboolean globals_only,
+ GHFunc func, gpointer data);
/* Calculation */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]