]> git.lyx.org Git - lyx.git/blobdiff - src/CutAndPaste.cpp
Remove direct calls of exit()
[lyx.git] / src / CutAndPaste.cpp
index 7329c248918f95b0e60b446626c4e0a6dcd38a52..f41ce3641830e5d2be38e554440ee7737410e5ec 100644 (file)
@@ -125,7 +125,7 @@ pasteSelectionHelper(DocIterator const & cur, ParagraphList const & parlist,
        InsetText * target_inset = cur.inset().asInsetText();
        if (!target_inset) {
                InsetTabular * it = cur.inset().asInsetTabular();
-               target_inset = it? it->cell(cur.idx())->asInsetText() : 0;
+               target_inset = it ? it->cell(cur.idx())->asInsetText() : 0;
        }
        LASSERT(target_inset, return PasteReturnValue(pit, pos, need_update));
 
@@ -170,7 +170,8 @@ pasteSelectionHelper(DocIterator const & cur, ParagraphList const & parlist,
                        if (forcePlainLayout || parLayout == defaultLayout)
                                par->setLayout(plainLayout);
                }
-       }       else { // check if we need to reset from plain layout
+       } else {
+               // check if we need to reset from plain layout
                Layout const & defaultLayout = newDocClass->defaultLayout();
                Layout const & plainLayout = newDocClass->plainLayout();
                ParagraphList::iterator const end = insertion.end();
@@ -502,6 +503,17 @@ void putClipboard(ParagraphList const & paragraphs,
        LASSERT(buffer, return);
 
        // This needs doing every time.
+       // Since setDocumentClass() causes deletion of the old document class
+       // we need to reset all layout pointers in paragraphs (otherwise they
+       // would be dangling).
+       ParIterator const end = buffer->par_iterator_end();
+       for (ParIterator it = buffer->par_iterator_begin(); it != end; ++it) {
+               docstring const name = it->layout().name();
+               if (docclass->hasLayout(name))
+                       it->setLayout((*docclass)[name]);
+               else
+                       it->setPlainOrDefaultLayout(*docclass);
+       }
        buffer->params().setDocumentClass(docclass);
 
        // we will use pasteSelectionHelper to copy the paragraphs into the