]> git.lyx.org Git - lyx.git/blobdiff - src/CutAndPaste.C
update no.po
[lyx.git] / src / CutAndPaste.C
index ba7f093c06be25c26449546e46376a4d95c4e290..5dca9f0cc40da14ca96b594d45ba840a40620103 100644 (file)
 #include "gettext.h"
 #include "iterators.h"
 #include "lyxtextclasslist.h"
+#include "undo_funcs.h"
+#include "paragraph_funcs.h"
 
 #include "insets/inseterror.h"
 
+#include "BoostFormat.h"
+
 using std::pair;
 using lyx::pos_type;
 using lyx::textclass_type;
@@ -111,13 +115,15 @@ bool CutAndPaste::cutSelection(Paragraph * startpar, Paragraph ** endpar,
                end = start - 1;
        } else {
                // more than one paragraph
-               (*endpar)->breakParagraphConservative(current_view->buffer()->params,
-                                                     end);
+               breakParagraphConservative(current_view->buffer()->params,
+                                          *endpar,
+                                          end);
                *endpar = (*endpar)->next();
                end = 0;
 
-               startpar->breakParagraphConservative(current_view->buffer()->params,
-                                                    start);
+               breakParagraphConservative(current_view->buffer()->params,
+                                          startpar,
+                                          start);
 
                // store the selection
                if (realcut) {
@@ -145,7 +151,7 @@ bool CutAndPaste::cutSelection(Paragraph * startpar, Paragraph ** endpar,
                        startpar->next()->stripLeadingSpaces();
                if (startpar->hasSameLayout(startpar->next()) ||
                    startpar->next()->empty()) {
-                       startpar->pasteParagraph(current_view->buffer()->params);
+                       mergeParagraph(current_view->buffer()->params, startpar);
                        (*endpar) = startpar; // this because endpar gets deleted here!
                }
                // this paragraph's are of noone's owner!
@@ -342,8 +348,10 @@ bool CutAndPaste::pasteSelection(Paragraph ** par, Paragraph ** endpar,
                // open the paragraph for inserting the buf
                // if necessary
                if (((*par)->size() > pos) || !(*par)->next()) {
-                       (*par)->breakParagraphConservative(current_view->buffer()->params,
-                                                          pos);
+                       breakParagraphConservative(
+                               current_view->buffer()->params,
+                               *par,
+                               pos);
                        paste_the_end = true;
                }
                // set the end for redoing later
@@ -359,20 +367,20 @@ bool CutAndPaste::pasteSelection(Paragraph ** par, Paragraph ** endpar,
                if ((*par)->next() == lastbuffer)
                        lastbuffer = *par;
 
-               (*par)->pasteParagraph(current_view->buffer()->params);
+               mergeParagraph(current_view->buffer()->params, *par);
                // 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);
+                               mergeParagraph(current_view->buffer()->params, lastbuffer);
                        } else if (lastbuffer->next()->empty()) {
                                lastbuffer->next()->makeSameLayout(lastbuffer);
-                               lastbuffer->pasteParagraph(current_view->buffer()->params);
+                               mergeParagraph(current_view->buffer()->params, lastbuffer);
                        } else if (lastbuffer->empty()) {
                                lastbuffer->makeSameLayout(lastbuffer->next());
-                               lastbuffer->pasteParagraph(current_view->buffer()->params);
+                               mergeParagraph(current_view->buffer()->params, lastbuffer);
                        } else
                                lastbuffer->next()->stripLeadingSpaces();
                }
@@ -416,17 +424,33 @@ int CutAndPaste::SwitchLayoutsBetweenClasses(textclass_type c1,
                string const name = par->layout()->name();
                bool hasLayout = tclass2.hasLayout(name);
 
-               if (!hasLayout)
+               if (hasLayout)
+                       par->layout(tclass2[name]);
+               else
                        par->layout(tclass2.defaultLayout());
 
                if (!hasLayout && name != tclass1.defaultLayoutName()) {
                        ++ret;
+#if USE_BOOST_FORMAT
+                       boost::format fmt(_("Layout had to be changed from\n"
+                                           "%1$s to %2$s\n"
+                                           "because of class conversion from\n"
+                                           "%3$s to %4$s"));
+                       fmt     % name
+                               % par->layout()->name()
+                               % tclass1.name()
+                               % tclass2.name();
+
+                       string const s = fmt.str();
+#else
                        string const s = _("Layout had to be changed from\n")
                                + name + _(" to ")
                                + par->layout()->name()
                                + _("\nbecause of class conversion from\n")
                                + tclass1.name() + _(" to ")
                                + tclass2.name();
+#endif
+                       freezeUndo();
                        InsetError * new_inset = new InsetError(s);
                        LyXText * txt = current_view->getLyXText();
                        LyXCursor cur = txt->cursor;
@@ -434,6 +458,7 @@ int CutAndPaste::SwitchLayoutsBetweenClasses(textclass_type c1,
                        txt->insertInset(current_view, new_inset);
                        txt->fullRebreak(current_view);
                        txt->setCursorIntern(current_view, cur.par(), cur.pos());
+                       unFreezeUndo();
                }
        }
        return ret;