[gnumeric] Fix validation import from ODF. [#725321]



commit 753c5b8d28d8b3d241b703349d4f1edfc04106ba
Author: Andreas J. Guelzow <aguelzow pyrshep ca>
Date:   Sat Mar 1 20:10:26 2014 -0700

    Fix validation import from ODF. [#725321]
    
    2014-03-01  Andreas J. Guelzow <aguelzow pyrshep ca>
    
        * openoffice-read.c (odf_validation_new_single_expr): only force
        explicit sheet namees if the base address is on a different sheet
        (odf_validation_new_pair_expr): ditto
        (odf_validations_analyze): also strip parentheses

 NEWS                                 |    1 +
 plugins/openoffice/ChangeLog         |    7 +++++++
 plugins/openoffice/openoffice-read.c |   33 +++++++++++++++++++--------------
 3 files changed, 27 insertions(+), 14 deletions(-)
---
diff --git a/NEWS b/NEWS
index ab7b706..d258173 100644
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,7 @@ Andreas:
        * Export row and column visibility to ODF. [#725115]
        * Export frozen panes info to and import from ODF. [#725228]
        * Export and import more sheet properties to/from ODF. [#725258]
+       * Fix validation import from ODF. [#725321]
 
 Jean:
        * Fix persistence of hyperlinks tips. [see #724108]
diff --git a/plugins/openoffice/ChangeLog b/plugins/openoffice/ChangeLog
index 72865c3..a767518 100644
--- a/plugins/openoffice/ChangeLog
+++ b/plugins/openoffice/ChangeLog
@@ -1,3 +1,10 @@
+2014-03-01  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+       * openoffice-read.c (odf_validation_new_single_expr): only force
+       explicit sheet namees if the base address is on a different sheet
+       (odf_validation_new_pair_expr): ditto
+       (odf_validations_analyze): also strip parentheses
+
 2014-02-28  Andreas J. Guelzow <aguelzow pyrshep ca>
 
        * openoffice-read.c (oo_table_start): handle new style fields
diff --git a/plugins/openoffice/openoffice-read.c b/plugins/openoffice/openoffice-read.c
index 40f4215..2e48259 100644
--- a/plugins/openoffice/openoffice-read.c
+++ b/plugins/openoffice/openoffice-read.c
@@ -2372,12 +2372,14 @@ odf_validation_new_single_expr (GsfXMLIn *xin, odf_validation_t *val,
        OOParseState *state = (OOParseState *)xin->user_state;
        GnmExprTop const *texpr = NULL;
        GnmParsePos pp;
+       GnmExprParseFlags flag;
 
        odf_init_pp (&pp, xin, val->base_cell_address);
+       flag = (pp.sheet == NULL || state->pos.sheet == pp.sheet)
+               ? GNM_EXPR_PARSE_DEFAULT 
+               : GNM_EXPR_PARSE_FORCE_EXPLICIT_SHEET_REFERENCES;
 
-       texpr = oo_expr_parse_str (xin, start, &pp,
-                                  GNM_EXPR_PARSE_FORCE_EXPLICIT_SHEET_REFERENCES,
-                                  val->f_type);
+       texpr = oo_expr_parse_str (xin, start, &pp, flag, val->f_type);
 
        if (texpr != NULL)
                return gnm_validation_new (val->style,
@@ -2402,6 +2404,7 @@ odf_validation_new_pair_expr (GsfXMLIn *xin, odf_validation_t *val,
 {
        OOParseState *state = (OOParseState *)xin->user_state;
        GnmParsePos pp;
+       GnmExprParseFlags flag;
        GnmExprTop const *texpr_a = NULL, *texpr_b = NULL;
        char *pair = NULL;
        guint len = strlen (start);
@@ -2413,6 +2416,9 @@ odf_validation_new_pair_expr (GsfXMLIn *xin, odf_validation_t *val,
        pair = g_strndup (start, len);
 
        odf_init_pp (&pp, xin, val->base_cell_address);
+       flag = (pp.sheet == NULL || state->pos.sheet == pp.sheet)
+               ? GNM_EXPR_PARSE_DEFAULT 
+               : GNM_EXPR_PARSE_FORCE_EXPLICIT_SHEET_REFERENCES;
 
        while (1) {
                gchar * try = g_strrstr_len (pair, len, ",");
@@ -2421,10 +2427,7 @@ odf_validation_new_pair_expr (GsfXMLIn *xin, odf_validation_t *val,
                if (try == NULL || try == pair)
                        goto pair_error;
 
-               texpr = oo_expr_parse_str
-                       (xin, try + 1, &pp,
-                        GNM_EXPR_PARSE_FORCE_EXPLICIT_SHEET_REFERENCES,
-                        val->f_type);
+               texpr = oo_expr_parse_str (xin, try + 1, &pp, flag, val->f_type);
                if (texpr != NULL) {
                        texpr_b = texpr;
                        *try = '\0';
@@ -2432,10 +2435,7 @@ odf_validation_new_pair_expr (GsfXMLIn *xin, odf_validation_t *val,
                }
                len = try - pair - 1;
        }
-       texpr_a = oo_expr_parse_str
-               (xin, pair, &pp,
-                GNM_EXPR_PARSE_FORCE_EXPLICIT_SHEET_REFERENCES,
-                val->f_type);
+       texpr_a = oo_expr_parse_str (xin, pair, &pp, flag, val->f_type);
 
        if (texpr_b != NULL)
                return gnm_validation_new (val->style,
@@ -2545,16 +2545,21 @@ odf_validations_analyze (GsfXMLIn *xin, odf_validation_t *val, guint offset,
                return odf_validations_analyze
                        (xin, val, str - val->condition + strlen ("cell-content-is-time() and"),
                         GNM_VALIDATION_TYPE_AS_TIME, f_type);
-       else if (g_str_has_prefix (str, "is-true-formula")) {
+       else if (g_str_has_prefix (str, "is-true-formula(") && g_str_has_suffix (str, ")")) {
+               GString *gstr = g_string_new (str + strlen ("is-true-formula("));
+               GnmValidation *validation;
+               g_string_truncate (gstr, gstr->len - 1);
                if (vtype != GNM_VALIDATION_TYPE_ANY) {
                        oo_warning
                        (xin, _("Validation condition '%s' is not supported. "
                                "It has been changed to '%s'."),
                         val->condition, str);
                }
-               return odf_validation_new_single_expr
-                       (xin, val, str + strlen ("is-true-formula"), GNM_VALIDATION_TYPE_CUSTOM,
+               validation = odf_validation_new_single_expr
+                       (xin, val, gstr->str, GNM_VALIDATION_TYPE_CUSTOM,
                         GNM_VALIDATION_OP_NONE);
+               g_string_free (gstr, TRUE);
+               return validation;
        } else if (g_str_has_prefix (str, "cell-content()"))
                return odf_validation_new_op
                        (xin, val, str - val->condition + strlen ("cell-content()"),


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]