From b436d85783257a8d6233a0f55a420c6c6d2d507b Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Wed, 8 Jun 2011 00:12:57 +0000 Subject: [PATCH] Fix bug #7517. This restores some code removed when we started adding basic layouts we didn't recognize. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@38981 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/CutAndPaste.cpp | 16 ++++++++++++++-- src/Text.cpp | 7 +++++++ src/TextClass.cpp | 9 ++++++--- src/TextClass.h | 3 ++- 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/CutAndPaste.cpp b/src/CutAndPaste.cpp index 39b732fea6..2bac66f8a6 100644 --- a/src/CutAndPaste.cpp +++ b/src/CutAndPaste.cpp @@ -647,13 +647,25 @@ void switchBetweenClasses(DocumentClass const * const oldone, DocumentClass const & newtc = *newone; // layouts + ParIterator it = par_iterator_begin(in); ParIterator end = par_iterator_end(in); - for (ParIterator it = par_iterator_begin(in); it != end; ++it) { + // for remembering which layouts we've had to add + set newlayouts; + for (; it != end; ++it) { docstring const name = it->layout().name(); // the pasted text will keep their own layout name. If this layout does // not exist in the new document, it will behave like a standard layout. - newtc.addLayoutIfNeeded(name); + bool const added_one = newtc.addLayoutIfNeeded(name); + if (added_one) + newlayouts.insert(name); + + if (added_one || newlayouts.find(name) != newlayouts.end()) { + // Warn the user. + docstring const s = bformat(_("Layout `%1$s' was not found."), name); + errorlist.push_back( + ErrorItem(_("Layout Not Found"), s, it->id(), 0, it->size())); + } if (in.usePlainLayout()) it->setLayout(newtc.plainLayout()); diff --git a/src/Text.cpp b/src/Text.cpp index fad29a7459..7c6fa5a233 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -357,6 +357,13 @@ void Text::readParToken(Paragraph & par, Lexer & lex, // all unknown layouts such as frame will be added to document class article so that // these layouts can keep their original names. tclass.addLayoutIfNeeded(layoutname); + bool const added_one = tclass.addLayoutIfNeeded(layoutname); + if (added_one) { + // Warn the user. + docstring const s = bformat(_("Layout `%1$s' was not found."), layoutname); + errorList.push_back( + ErrorItem(_("Layout Not Found"), s, par.id(), 0, par.size())); + } par.setLayout(bp.documentClass()[layoutname]); diff --git a/src/TextClass.cpp b/src/TextClass.cpp index 32976c35d7..0ab0c5ce88 100644 --- a/src/TextClass.cpp +++ b/src/TextClass.cpp @@ -1221,10 +1221,13 @@ bool TextClass::load(string const & path) const } -void DocumentClass::addLayoutIfNeeded(docstring const & n) const +bool DocumentClass::addLayoutIfNeeded(docstring const & n) const { - if (!hasLayout(n)) - layoutlist_.push_back(createBasicLayout(n, true)); + if (hasLayout(n)) + return false; + + layoutlist_.push_back(createBasicLayout(n, true)); + return true; } diff --git a/src/TextClass.h b/src/TextClass.h index 24ee2aa1f2..c1e99e950a 100644 --- a/src/TextClass.h +++ b/src/TextClass.h @@ -377,7 +377,8 @@ public: /// a plain inset layout for use as a default static InsetLayout const & plainInsetLayout() { return plain_insetlayout_; } /// add a new layout \c name if it does not exist in layoutlist_ - void addLayoutIfNeeded(docstring const & name) const; + /// \return whether we had to add one. + bool addLayoutIfNeeded(docstring const & name) const; /////////////////////////////////////////////////////////////////// // accessors