]> git.lyx.org Git - features.git/blobdiff - src/CutAndPaste.cpp
Improve the local layout feature by better handling of unknown textclass, unknown...
[features.git] / src / CutAndPaste.cpp
index ac634a6d2dfc96a5dca1b29fdf35636cfc79e6f0..a9b8fc9b30acd6616cd021944d71e7c22e397020 100644 (file)
@@ -129,18 +129,18 @@ pasteSelectionHelper(Cursor & cur, ParagraphList const & parlist,
        }
 
        // 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 form empty layout
+       } else { // check if we need to reset from empty layout
                Layout const & defaultLayout = newDocClass->defaultLayout();
                Layout const & emptyLayout = newDocClass->emptyLayout();
                ParagraphList::iterator const end = insertion.end();
@@ -360,7 +360,12 @@ void putClipboard(ParagraphList const & paragraphs,
 {
        // For some strange reason gcc 3.2 and 3.3 do not accept
        // Buffer buffer(string(), false);
-       Buffer buffer("", false);
+       // This needs to be static to avoid a memory leak. When a Buffer is
+       // constructed, it constructs a BufferParams, which in turn constructs
+       // 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);
@@ -369,6 +374,8 @@ void putClipboard(ParagraphList const & paragraphs,
                theClipboard().put(lyx.str(), plaintext);
        else
                theClipboard().put(string(), plaintext);
+       // Save that memory
+       buffer.paragraphs().clear();
 }
 
 
@@ -502,26 +509,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
@@ -621,6 +617,9 @@ void cutSelection(Cursor & cur, bool doclear, bool realcut)
                                cur.selectionAsString(true));
                }
 
+               if (begpit != endpit)
+                       cur.updateFlags(Update::Force | Update::FitCursor);
+
                boost::tie(endpit, endpos) =
                        eraseSelectionHelper(bp,
                                text->paragraphs(),