[gnumeric] Names: introduce expr_name_set_is_placeholder.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] Names: introduce expr_name_set_is_placeholder.
- Date: Sun, 22 May 2011 19:01:03 +0000 (UTC)
commit 55cbadbace5bce53d8e8514ab5a3aeeafbd48965
Author: Morten Welinder <terra gnome org>
Date: Sun May 22 15:00:46 2011 -0400
Names: introduce expr_name_set_is_placeholder.
ChangeLog | 4 +++
plugins/excel/ChangeLog | 2 +
plugins/excel/ms-excel-write.c | 2 +-
plugins/openoffice/openoffice-read.c | 2 +-
src/expr-name.c | 35 +++++++++++++++++++++++----------
src/expr-name.h | 4 ++-
6 files changed, 35 insertions(+), 14 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 52aba27..288cd47 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2011-05-22 Morten Welinder <terra gnome org>
+ * src/expr-name.c (expr_name_set_is_placeholder): New function.
+ (expr_name_downgrade_to_placeholder): Simplify using
+ expr_name_set_is_placeholder.
+
* src/workbook.h (WORKBOOK_FOREACH_SHEET): Move from
workbook-priv.h
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index 21beded..b050569 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -2,6 +2,8 @@
* ms-excel-write.c (excel_write_autofilter_names): Use proper
ctor/dtor methods for GnmNamedExpr.
+ (excel_write_autofilter_names): Use new
+ expr_name_set_is_placeholder.
2011-05-21 Morten Welinder <terra gnome org>
diff --git a/plugins/excel/ms-excel-write.c b/plugins/excel/ms-excel-write.c
index 7e3d9f8..c8bcad4 100644
--- a/plugins/excel/ms-excel-write.c
+++ b/plugins/excel/ms-excel-write.c
@@ -3866,7 +3866,7 @@ excel_write_autofilter_names (ExcelWriteState *ewb)
nexpr = expr_name_new ("_FilterDatabase");
nexpr->is_hidden = TRUE;
- nexpr->is_placeholder = FALSE;
+ expr_name_set_is_placeholder (nexpr, FALSE);
for (i = 0; i < ewb->esheets->len; i++) {
ExcelWriteSheet const *esheet =
g_ptr_array_index (ewb->esheets, i);
diff --git a/plugins/openoffice/openoffice-read.c b/plugins/openoffice/openoffice-read.c
index 1b69bc5..24d8cd8 100644
--- a/plugins/openoffice/openoffice-read.c
+++ b/plugins/openoffice/openoffice-read.c
@@ -5258,7 +5258,7 @@ oo_db_range_start (GsfXMLIn *xin, xmlChar const **attrs)
if (name != NULL
&& (NULL == (nexpr = expr_name_lookup
(parse_pos_init (&pp, state->pos.wb, NULL, 0, 0), name)) ||
- nexpr->is_placeholder)) {
+ expr_name_is_placeholder (nexpr))) {
GnmExprTop const *texpr = gnm_expr_top_new (expr);
expr_name_add (&pp, name, texpr, NULL, TRUE, NULL);
} else
diff --git a/src/expr-name.c b/src/expr-name.c
index e956855..2b0bb04 100644
--- a/src/expr-name.c
+++ b/src/expr-name.c
@@ -798,22 +798,12 @@ expr_name_eval (GnmNamedExpr const *nexpr, GnmEvalPos const *pos,
void
expr_name_downgrade_to_placeholder (GnmNamedExpr *nexpr)
{
- GnmNamedExprCollection *scope;
-
g_return_if_fail (nexpr != NULL);
- g_return_if_fail (nexpr->pos.sheet != NULL || nexpr->pos.wb != NULL);
- g_return_if_fail (nexpr->scope != NULL);
- g_return_if_fail (!nexpr->is_placeholder);
-
- scope = nexpr->scope;
-
- g_hash_table_steal (scope->names, nexpr->name->str);
- nexpr->is_placeholder = TRUE;
+ expr_name_set_is_placeholder (nexpr, TRUE);
expr_name_set_expr
(nexpr,
gnm_expr_top_new_constant (value_new_error_NAME (NULL)));
- gnm_named_expr_collection_insert (scope, nexpr);
}
/*******************************************************************
@@ -945,6 +935,29 @@ expr_name_is_placeholder (GnmNamedExpr const *nexpr)
gnm_expr_top_is_err (nexpr->texpr, GNM_ERROR_NAME));
}
+void
+expr_name_set_is_placeholder (GnmNamedExpr *nexpr, gboolean is_placeholder)
+{
+ const char *name;
+
+ g_return_if_fail (nexpr != NULL);
+
+ name = expr_name_name (nexpr);
+
+ is_placeholder = !!is_placeholder;
+ if (nexpr->is_placeholder == is_placeholder)
+ return;
+ nexpr->is_placeholder = is_placeholder;
+
+ if (nexpr->scope) {
+ g_hash_table_steal (is_placeholder
+ ? nexpr->scope->names
+ : nexpr->scope->placeholders,
+ name);
+ gnm_named_expr_collection_insert (nexpr->scope, nexpr);
+ }
+}
+
gboolean
expr_name_is_active (GnmNamedExpr const *nexpr)
{
diff --git a/src/expr-name.h b/src/expr-name.h
index e07689e..2976fbb 100644
--- a/src/expr-name.h
+++ b/src/expr-name.h
@@ -42,13 +42,15 @@ GnmValue*expr_name_eval (GnmNamedExpr const *ne, GnmEvalPos const *ep,
const char *expr_name_name (GnmNamedExpr const *nexpr);
gboolean expr_name_set_name (GnmNamedExpr *nexpr, const char *new_name);
+gboolean expr_name_is_placeholder (GnmNamedExpr const *ne);
+void expr_name_set_is_placeholder (GnmNamedExpr *ne, gboolean is_placeholder);
+
char *expr_name_as_string (GnmNamedExpr const *ne, GnmParsePos const *pp,
GnmConventions const *fmt);
char *expr_name_set_pos (GnmNamedExpr *ne, GnmParsePos const *pp);
void expr_name_set_expr (GnmNamedExpr *ne, GnmExprTop const *texpr);
void expr_name_add_dep (GnmNamedExpr *ne, GnmDependent *dep);
void expr_name_remove_dep (GnmNamedExpr *ne, GnmDependent *dep);
-gboolean expr_name_is_placeholder (GnmNamedExpr const *ne);
gboolean expr_name_is_active (GnmNamedExpr const *ne);
void expr_name_downgrade_to_placeholder (GnmNamedExpr *nexpr);
gboolean expr_name_in_use (GnmNamedExpr *nexpr);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]