]> git.lyx.org Git - lyx.git/blobdiff - src/CutAndPaste.cpp
* GuiToolbar.cpp:
[lyx.git] / src / CutAndPaste.cpp
index 8f12370a6b8c13fda861bed1b2e0d8a22463db5a..e878e30c1f4bd647bbe0c6411dabf06ba8f2faa0 100644 (file)
@@ -17,6 +17,7 @@
 
 #include "Buffer.h"
 #include "buffer_funcs.h"
+#include "BufferList.h"
 #include "BufferParams.h"
 #include "BufferView.h"
 #include "Changes.h"
@@ -123,21 +124,22 @@ pasteSelectionHelper(Cursor & cur, ParagraphList const & parlist,
                                        breakParagraphConservative(
                                                        buffer.params(),
                                                        insertion, i, j);
+                                       break;
                                }
                        }
                }
        }
 
        // set the paragraphs to empty layout if necessary
-       if (cur.inset().useEmptyLayout()) {
-               bool forceEmptyLayout = cur.inset().forceEmptyLayout();
+       if (cur.inset().usePlainLayout()) {
+               bool forcePlainLayout = cur.inset().forcePlainLayout();
                Layout const & emptyLayout = newDocClass->emptyLayout();
                Layout const & defaultLayout = newDocClass->defaultLayout();
                ParagraphList::iterator const end = insertion.end();
                ParagraphList::iterator par = insertion.begin();
                for (; par != end; ++par) {
                        Layout const & parLayout = par->layout();
-                       if (forceEmptyLayout || parLayout == defaultLayout)
+                       if (forcePlainLayout || parLayout == defaultLayout)
                                par->setLayout(emptyLayout);
                }
        } else { // check if we need to reset from empty layout
@@ -365,17 +367,19 @@ void putClipboard(ParagraphList const & paragraphs,
        // a DocumentClass, via new, that is never deleted. If we were to go to
        // some kind of garbage collection there, or a shared_ptr, then this
        // would not be needed.
-       static Buffer buffer("", false);
-       buffer.setUnnamed(true);
-       buffer.paragraphs() = paragraphs;
-       buffer.params().setDocumentClass(docclass);
+       static Buffer * buffer = theBufferList().newBuffer(
+               FileName::tempName().absFilename() + "_clipboard.internal");
+       buffer->setUnnamed(true);
+       buffer->paragraphs() = paragraphs;
+       buffer->inset().setBuffer(*buffer);
+       buffer->params().setDocumentClass(docclass);
        ostringstream lyx;
-       if (buffer.write(lyx))
+       if (buffer->write(lyx))
                theClipboard().put(lyx.str(), plaintext);
        else
                theClipboard().put(string(), plaintext);
        // Save that memory
-       buffer.paragraphs() = ParagraphList();
+       buffer->paragraphs().clear();
 }
 
 
@@ -509,26 +513,15 @@ void switchBetweenClasses(DocumentClass const * const oldone,
        ParIterator end = par_iterator_end(in);
        for (ParIterator it = par_iterator_begin(in); it != end; ++it) {
                docstring const name = it->layout().name();
-               bool hasLayout = newtc.hasLayout(name);
 
-               if (in.useEmptyLayout())
+               // 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);
+
+               if (in.usePlainLayout())
                        it->setLayout(newtc.emptyLayout());
-               else if (hasLayout)
-                       it->setLayout(newtc[name]);
                else
-                       it->setLayout(newtc.defaultLayout());
-
-               if (!hasLayout && name != oldtc.defaultLayoutName()) {
-                       docstring const s = bformat(
-                                                _("Layout had to be changed from\n%1$s to %2$s\n"
-                                               "because of class conversion from\n%3$s to %4$s"),
-                        name, it->layout().name(),
-                        from_utf8(oldtc.name()), from_utf8(newtc.name()));
-                       // To warn the user that something had to be done.
-                       errorlist.push_back(ErrorItem(_("Changed Layout"), s,
-                                                     it->id(), 0,
-                                                     it->size()));
-               }
+                       it->setLayout(newtc[name]);
        }
 
        // character styles
@@ -766,7 +759,7 @@ void saveSelection(Cursor & cur)
        if (cur.selection() 
            && cur.selBegin() == cur.bv().cursor().selBegin()
            && cur.selEnd() == cur.bv().cursor().selEnd()) {
-               LYXERR(Debug::ACTION, "'" << cur.selectionAsString(true) << "'");
+               LYXERR(Debug::SELECTION, "saveSelection: '" << cur.selectionAsString(true) << "'");
                copySelectionToStack(cur, selectionBuffer);
        }
 }