- delete buf;
- buf = tmpbuf;
- *endpar = tmppar->next();
- pos = tmppos;
- } else {
- // many paragraphs
-
- // make a copy of the simple cut_buffer
- Paragraph * tmpbuf = buf;
- Paragraph * simple_cut_clone = new Paragraph(*tmpbuf);
- Paragraph * tmpbuf2 = simple_cut_clone;
-
- while (tmpbuf->next()) {
- tmpbuf = tmpbuf->next();
- tmpbuf2->next(new Paragraph(*tmpbuf));
- tmpbuf2->next()->previous(tmpbuf2);
- tmpbuf2 = tmpbuf2->next();
- }
-
- // make sure there is no class difference
- SwitchLayoutsBetweenClasses(textclass, tc, buf);
-
- // make the buf exactly the same layout than
- // the cursor paragraph
- buf->makeSameLayout(*par);
-
- // find the end of the buffer
- Paragraph * lastbuffer = buf;
- while (lastbuffer->next())
- lastbuffer = lastbuffer->next();
-
- bool paste_the_end = false;
-
- // open the paragraph for inserting the buf
- // if necessary
- if (((*par)->size() > pos) || !(*par)->next()) {
- (*par)->breakParagraphConservative(current_view->buffer()->params,
- pos);
- paste_the_end = true;
- }
- // set the end for redoing later
- *endpar = (*par)->next()->next();
-
- // paste it!
- lastbuffer->next((*par)->next());
- (*par)->next()->previous(lastbuffer);
-
- (*par)->next(buf);
- buf->previous(*par);
-
- if ((*par)->next() == lastbuffer)
- lastbuffer = *par;
-
- (*par)->pasteParagraph(current_view->buffer()->params);
- // store the new cursor position
- *par = lastbuffer;
- pos = lastbuffer->size();
- // maybe some pasting
- if (lastbuffer->next() && paste_the_end) {
- if (lastbuffer->next()->hasSameLayout(lastbuffer)) {
- lastbuffer->pasteParagraph(current_view->buffer()->params);
- } else if (!lastbuffer->next()->size()) {
- lastbuffer->next()->makeSameLayout(lastbuffer);
- lastbuffer->pasteParagraph(current_view->buffer()->params);
- } else if (!lastbuffer->size()) {
- lastbuffer->makeSameLayout(lastbuffer->next());
- lastbuffer->pasteParagraph(current_view->buffer()->params);
- } else
- lastbuffer->next()->stripLeadingSpaces(tc);
+ }
+
+ // Make the buf exactly the same layout than
+ // the cursor paragraph.
+ simple_cut_clone.begin()->makeSameLayout(*pit);
+
+ // Prepare the paragraphs and insets for insertion
+ // A couple of insets store buffer references so need
+ // updating
+ ParIterator fpit(simple_cut_clone.begin(), simple_cut_clone);
+ ParIterator fend(simple_cut_clone.end(), simple_cut_clone);
+
+ for (; fpit != fend; ++fpit) {
+ InsetList::iterator lit = fpit->insetlist.begin();
+ InsetList::iterator eit = fpit->insetlist.end();
+
+ for (; lit != eit; ++lit) {
+ switch (lit->inset->lyxCode()) {
+ case InsetOld::INCLUDE_CODE: {
+ InsetInclude * ii = static_cast<InsetInclude*>(lit->inset);
+ InsetInclude::Params ip = ii->params();
+ ip.masterFilename_ = buffer.fileName();
+ ii->set(ip);
+ break;
+ }
+
+ case InsetOld::TABULAR_CODE: {
+ InsetTabular * it = static_cast<InsetTabular*>(lit->inset);
+ it->buffer(const_cast<Buffer*>(&buffer));
+ break;
+ }
+
+ default:
+ break; // nothing
+ }