Commit 87ac5117 authored by Morten Welinder's avatar Morten Welinder

ssdiff: fix handling of hyperlinks.

This checks whether the links are actually changed instead of using
pointer identify which never was right and now will always be false.
parent 5ed500b9
2017-03-17 Morten Welinder <terra@gnome.org>
* src/mstyle.c (gnm_style_find_differences): New function.
* src/ssdiff.c (xml_style_changed): Use
gnm_style_find_differences.
* src/ssdiff.c (cb_diff_sheets_styles_2): Use relaxed
gnm_style_find_differences, not gnm_style_equal.
* src/hlink.c (gnm_hlink_equal): New function.
2017-03-13 Morten Welinder <terra@gnome.org>
* src/hlink.c (gnm_hlink_cur_wb_set_target): Improve parsing of
......
......@@ -16,6 +16,7 @@ Morten:
* Hyperlinks improvements. [#706671]
* Plug leaks.
* Fix issues with sheet-local names.
* ssdiff improvements with hyperlinks.
--------------------------------------------------------------------------
Gnumeric 1.12.33
......
......@@ -227,6 +227,27 @@ gnm_hlink_dup (GnmHLink *lnk)
return new_lnk;
}
/**
* gnm_hlink_equal:
* @a: a #GnmHLink
* @b: a #GnmHLink
* @relax_sheet: if %TRUE, ignore differences solely caused by being linked into different sheets.
*
* Returns: %TRUE, if links are equal
*/
gboolean
gnm_hlink_equal (GnmHLink const *a, GnmHLink const *b, gboolean relax_sheet)
{
g_return_val_if_fail (GNM_IS_HLINK (a), NULL);
g_return_val_if_fail (GNM_IS_HLINK (b), NULL);
if (!relax_sheet && a->sheet != b->sheet)
return FALSE;
return (g_strcmp0 (a->target, b->target) == 0 &&
g_strcmp0 (a->tip, b->tip) == 0);
}
/***************************************************************************/
/* Link to named regions within the current workbook */
typedef struct { GnmHLinkClass hlink; } GnmHLinkCurWBClass;
......
......@@ -23,6 +23,8 @@ GType gnm_hlink_get_type (void);
GnmHLink *gnm_hlink_new (GType typ, Sheet *sheet);
GnmHLink *gnm_hlink_dup (GnmHLink *lnk);
gboolean gnm_hlink_equal (GnmHLink const *a, GnmHLink const *b, gboolean relax_sheet);
gboolean gnm_hlink_activate (GnmHLink *lnk, WBCGtk *wbcg);
const char *gnm_hlink_get_target (GnmHLink const *lnk);
......
......@@ -540,6 +540,45 @@ gnm_style_find_conflicts (GnmStyle *accum, GnmStyle const *overlay,
return conflicts;
}
/**
* gnm_style_find_differences:
* @a: A #GnmStyle
* @b: A #GnmStyle
* @relax_sheet: if %TRUE, ignore differences solely caused by being linked into different sheets.
*
* Determine how two fully-qualified styles differ.
*
* Returns differences as a bitset of #GnmStyleElement.
**/
unsigned int
gnm_style_find_differences (GnmStyle const *a, GnmStyle const *b,
gboolean relax_sheet)
{
int i;
unsigned int diffs = 0;
g_assert (MSTYLE_ELEMENT_MAX <= CHAR_BIT * sizeof (diffs));
for (i = 0; i < MSTYLE_ELEMENT_MAX; i++) {
if (elem_is_set (a, i) != elem_is_set (b, i) ||
(elem_is_set (a, i) && !elem_is_eq (a, b, i)))
diffs |= (1u << i);
}
if (relax_sheet) {
if (a->hlink && b->hlink &&
gnm_hlink_equal (a->hlink, b->hlink, relax_sheet))
diffs &= ~(1u << MSTYLE_HLINK);
// FIXME: Validations
// FIXME: Conditions
}
return diffs;
}
static inline void
gnm_style_clear_pango (GnmStyle *style)
{
......
......@@ -90,6 +90,9 @@ int gnm_style_cmp (GnmStyle const *a, GnmStyle const *b);
unsigned int gnm_style_find_conflicts (GnmStyle *accum, GnmStyle const *overlay,
unsigned int conflicts);
unsigned int gnm_style_find_differences (GnmStyle const *a, GnmStyle const *b,
gboolean relax_sheet);
gboolean gnm_style_is_complete (GnmStyle const *style);
gboolean gnm_style_is_element_set (GnmStyle const *style, GnmStyleElement elem);
void gnm_style_unset_element (GnmStyle *style, GnmStyleElement elem);
......
......@@ -487,7 +487,6 @@ xml_style_changed (GnmDiffState *state, GnmRange const *r,
{
unsigned int conflicts;
GnmStyleElement e;
GnmStyle *os_copy;
xml_close_cells (state);
......@@ -502,9 +501,7 @@ xml_style_changed (GnmDiffState *state, GnmRange const *r,
gsf_xml_out_add_uint (state->xml, "endCol", r->end.col);
gsf_xml_out_add_uint (state->xml, "endRow", r->end.row);
os_copy = gnm_style_dup (os);
conflicts = gnm_style_find_conflicts (os_copy, ns, 0);
gnm_style_unref (os_copy);
conflicts = gnm_style_find_differences (os, ns, TRUE);
for (e = 0; e < MSTYLE_ELEMENT_MAX; e++) {
if ((conflicts & (1u << e)) == 0)
continue;
......@@ -943,7 +940,7 @@ cb_diff_sheets_styles_2 (G_GNUC_UNUSED gpointer key,
struct cb_diff_sheets_styles *data = user_data;
GnmRange r = sr->range;
if (gnm_style_equal (data->old_style, sr->style))
if (gnm_style_find_differences (data->old_style, sr->style, TRUE) == 0)
return;
data->state->actions->style_changed (data->state, &r,
......
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