From 8a6810210b3b1ce2cb82055063eee635174be637 Mon Sep 17 00:00:00 2001 From: Raphael Rosch Date: Thu, 20 Feb 2014 14:22:58 -0500 Subject: crash on cut n paste, or alt+scroll.. Fixed bugs: - https://launchpad.net/bugs/1171109 (bzr r13047) --- src/id-clash.cpp | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) (limited to 'src/id-clash.cpp') diff --git a/src/id-clash.cpp b/src/id-clash.cpp index c8eacfe02..76b8e6ff8 100644 --- a/src/id-clash.cpp +++ b/src/id-clash.cpp @@ -203,27 +203,44 @@ change_clashing_ids(SPDocument *imported_doc, SPDocument *current_doc, id_changelist_type *id_changes) { const gchar *id = elem->getId(); + bool fix_clashing_ids = true; if (id && current_doc->getObjectById(id)) { // Choose a new ID. // To try to preserve any meaningfulness that the original ID // may have had, the new ID is the old ID followed by a hyphen // and one or more digits. - std::string old_id(id); - std::string new_id(old_id + '-'); - for (;;) { - new_id += "0123456789"[std::rand() % 10]; - const char *str = new_id.c_str(); - if (current_doc->getObjectById(str) == NULL && - imported_doc->getObjectById(str) == NULL) break; + + if (SP_IS_GRADIENT(elem)) { + SPObject *cd_obj = current_doc->getObjectById(id); + + if (cd_obj && SP_IS_GRADIENT(cd_obj)) { + SPGradient *cd_gr = SP_GRADIENT(cd_obj); + if (cd_gr->isEquivalent(SP_GRADIENT(elem))) { + fix_clashing_ids = false; + } + } } - // Change to the new ID - elem->getRepr()->setAttribute("id", new_id.c_str()); - // Make a note of this change, if we need to fix up refs to it - if (refmap->find(old_id) != refmap->end()) + + if (fix_clashing_ids) { + std::string old_id(id); + std::string new_id(old_id + '-'); + for (;;) { + new_id += "0123456789"[std::rand() % 10]; + const char *str = new_id.c_str(); + if (current_doc->getObjectById(str) == NULL && + imported_doc->getObjectById(str) == NULL) break; + } + // Change to the new ID + + elem->getRepr()->setAttribute("id", new_id.c_str()); + // Make a note of this change, if we need to fix up refs to it + if (refmap->find(old_id) != refmap->end()) id_changes->push_back(id_changeitem_type(elem, old_id)); + } } + // recurse for (SPObject *child = elem->firstChild(); child; child = child->getNext() ) { -- cgit v1.2.3