From 0ce1eb6fcfa054641be8225cf65ef7d01bf0a813 Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Fri, 17 Jun 2016 14:49:21 +0530 Subject: Fix a crash while deleting when there was single selector in the style dialog (bzr r14949.1.23) --- src/ui/dialog/styledialog.cpp | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) (limited to 'src/ui/dialog/styledialog.cpp') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index 622bbcdb9..f81faec97 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -283,17 +283,44 @@ void StyleDialog::_delSelector() Gtk::TreeModel::Row row = *iter; path = _treeView.get_model()->get_path(iter); int i = atoi(path.to_string().c_str()); - selVec.erase(selVec.begin()+i); - _sValue.clear(); - for (unsigned i = 0; i < selVec.size(); ++i) + if (selVec.size() != 0) { - std::string selValue = (selVec[i].first + "{" - + selVec[i].second + " }\n"); - _sValue.append(selValue.c_str()); - } + selVec.erase(selVec.begin()+i); + _sValue.clear(); + + if (selVec.size() != 0) + { + for (unsigned i = 0; i < selVec.size(); ++i) + { + std::string selValue = (selVec[i].first + "{" + + selVec[i].second + " }\n"); + _sValue.append(selValue.c_str()); + } - _styleChild->firstChild()->setContent(_sValue.c_str()); + } + + /** + * Only if a value exists in _sValue and there is a _styleChild + * which contains the style element, then the content in style + * element is updated else the _styleChild is set and its content + * is set to an empty string. + */ + if (!_sValue.empty() && _styleChild) + _styleChild->firstChild()->setContent(_sValue.c_str()); + else + { + for ( unsigned i = 0; i < _num; ++i ) + { + if ( std::string(_document->getReprRoot()->nthChild(i)->name()) + == "svg:style" ) + { + _styleChild = _document->getReprRoot()->nthChild(i); + } + } + _styleChild->firstChild()->setContent(""); + } + } _store->erase(row); } } -- cgit v1.2.3