X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FCutAndPaste.C;h=395e860419e39b2a07e6c6c063f3a06961de70bf;hb=21226de2b87a86be19fff025cace3d286a75aa76;hp=f7117cb8e02827ed8f471a4ab1ef182ae24d7174;hpb=33a28bdc9cdf978601d5d40b693f13924801ad9e;p=lyx.git diff --git a/src/CutAndPaste.C b/src/CutAndPaste.C index f7117cb8e0..395e860419 100644 --- a/src/CutAndPaste.C +++ b/src/CutAndPaste.C @@ -9,18 +9,21 @@ #include +#ifdef __GNUG__ +#pragma implementation +#endif + #include "CutAndPaste.h" #include "BufferView.h" #include "buffer.h" #include "paragraph.h" -#include "insets/inseterror.h" #include "lyx_gui_misc.h" #include "lyxcursor.h" #include "gettext.h" +#include "iterators.h" +#include "lyxtextclasslist.h" -#ifdef __GNUG__ -#pragma implementation -#endif +#include "insets/inseterror.h" using std::pair; using lyx::pos_type; @@ -262,9 +265,35 @@ bool CutAndPaste::pasteSelection(Paragraph ** par, Paragraph ** endpar, tmpbuf2->next()->previous(tmpbuf2); tmpbuf2 = tmpbuf2->next(); } + + // now remove all out of the buffer which is NOT allowed in the + // new environment and set also another font if that is required + tmpbuf = buf; + while(tmpbuf) { + for(pos_type i = 0; i < tmpbuf->size(); ++i) { + if (tmpbuf->getChar(i) == Paragraph::META_INSET) { + if (!(*par)->insetAllowed(tmpbuf->getInset(i)->lyxCode())) + { + tmpbuf->erase(i--); + } + } else { + LyXFont f1 = tmpbuf->getFont(current_view->buffer()->params,i); + LyXFont f2 = f1; + if (!(*par)->checkInsertChar(f1)) { + tmpbuf->erase(i--); + } else if (f1 != f2) { + tmpbuf->setFont(i, f1); + } + } + } + // set the inset owner of this paragraph + tmpbuf->setInsetOwner((*par)->inInset()); + tmpbuf = tmpbuf->next(); + } // make sure there is no class difference - SwitchLayoutsBetweenClasses(textclass, tc, buf); + SwitchLayoutsBetweenClasses(textclass, tc, buf, + current_view->buffer()->params); // make the buf exactly the same layout than // the cursor paragraph @@ -338,21 +367,25 @@ int CutAndPaste::nrOfParagraphs() int CutAndPaste::SwitchLayoutsBetweenClasses(textclass_type c1, - textclass_type c2, Paragraph * par) + textclass_type c2, + Paragraph * par, + BufferParams const & bparams) { int ret = 0; if (!par || c1 == c2) return ret; - - while (par) { + + ParIterator end = ParIterator(); + for (ParIterator it = ParIterator(par); it != end; ++it) { + par = *it; string const name = textclasslist.NameOfLayout(c1, par->layout); int lay = 0; pair pp = textclasslist.NumberOfLayout(c2, name); if (pp.first) { lay = pp.second; - } else { // layout not found - // use default layout "Standard" (0) + } else { + // not found: use default layout "Standard" (0) lay = 0; } par->layout = lay; @@ -366,9 +399,10 @@ int CutAndPaste::SwitchLayoutsBetweenClasses(textclass_type c1, + textclasslist.NameOfClass(c1) + _(" to ") + textclasslist.NameOfClass(c2); InsetError * new_inset = new InsetError(s); - par->insertInset(0, new_inset); + par->insertInset(0, new_inset, + LyXFont(LyXFont::ALL_INHERIT, + bparams.language)); } - par = par->next(); } return ret; }