Author: rgheck
Date: Wed Jun  8 02:53:19 2011
New Revision: 38983
URL: http://www.lyx.org/trac/changeset/38983

Log:
Fix bug #7517. This restores some code removed when we started adding basic 
layouts we didn't recognize.

Modified:
   lyx-devel/branches/BRANCH_2_0_X/src/CutAndPaste.cpp
   lyx-devel/branches/BRANCH_2_0_X/src/Text.cpp
   lyx-devel/branches/BRANCH_2_0_X/src/TextClass.cpp
   lyx-devel/branches/BRANCH_2_0_X/src/TextClass.h
   lyx-devel/branches/BRANCH_2_0_X/status.20x

Modified: lyx-devel/branches/BRANCH_2_0_X/src/CutAndPaste.cpp
==============================================================================
--- lyx-devel/branches/BRANCH_2_0_X/src/CutAndPaste.cpp Wed Jun  8 02:44:55 
2011        (r38982)
+++ lyx-devel/branches/BRANCH_2_0_X/src/CutAndPaste.cpp Wed Jun  8 02:53:19 
2011        (r38983)
@@ -647,13 +647,25 @@
        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<docstring> 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());

Modified: lyx-devel/branches/BRANCH_2_0_X/src/Text.cpp
==============================================================================
--- lyx-devel/branches/BRANCH_2_0_X/src/Text.cpp        Wed Jun  8 02:44:55 
2011        (r38982)
+++ lyx-devel/branches/BRANCH_2_0_X/src/Text.cpp        Wed Jun  8 02:53:19 
2011        (r38983)
@@ -357,6 +357,13 @@
                // 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]);
 

Modified: lyx-devel/branches/BRANCH_2_0_X/src/TextClass.cpp
==============================================================================
--- lyx-devel/branches/BRANCH_2_0_X/src/TextClass.cpp   Wed Jun  8 02:44:55 
2011        (r38982)
+++ lyx-devel/branches/BRANCH_2_0_X/src/TextClass.cpp   Wed Jun  8 02:53:19 
2011        (r38983)
@@ -1199,10 +1199,13 @@
 }
 
 
-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;
 }
 
 

Modified: lyx-devel/branches/BRANCH_2_0_X/src/TextClass.h
==============================================================================
--- lyx-devel/branches/BRANCH_2_0_X/src/TextClass.h     Wed Jun  8 02:44:55 
2011        (r38982)
+++ lyx-devel/branches/BRANCH_2_0_X/src/TextClass.h     Wed Jun  8 02:53:19 
2011        (r38983)
@@ -373,7 +373,8 @@
        /// 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

Modified: lyx-devel/branches/BRANCH_2_0_X/status.20x
==============================================================================
--- lyx-devel/branches/BRANCH_2_0_X/status.20x  Wed Jun  8 02:44:55 2011        
(r38982)
+++ lyx-devel/branches/BRANCH_2_0_X/status.20x  Wed Jun  8 02:53:19 2011        
(r38983)
@@ -70,6 +70,8 @@
 
 - Fix output of decimally aligned columns in unviewed (on screen) tables.
 
+- Inform user of unknown layouts caused by class change (bug 7571).
+
 - Avoid LaTeX errors if font changing commands are used in the wrong mode
   by assuring to switch to the right mode on export.
 

Reply via email to