X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FCutAndPaste.cpp;h=4ec9811d90bb8fd086e2e30be20ecb958bf1b620;hb=0a603c5d0e370c8b9c9e0f5dfa024b6e500b2dd4;hp=44bcb5e962c56bc420bbb7faa093f3f05ffd36d4;hpb=b917c4e40f9f5cd3d101444600eddafcca54d6e3;p=lyx.git diff --git a/src/CutAndPaste.cpp b/src/CutAndPaste.cpp index 44bcb5e962..4ec9811d90 100644 --- a/src/CutAndPaste.cpp +++ b/src/CutAndPaste.cpp @@ -62,14 +62,14 @@ #include "support/lstrings.h" #include "support/lyxalgo.h" #include "support/TempFile.h" +#include "support/unique_ptr.h" #include "frontends/alert.h" #include "frontends/Clipboard.h" #include "frontends/Selection.h" -#include - #include +#include using namespace std; using namespace lyx::support; @@ -160,7 +160,7 @@ pasteSelectionHelper(DocIterator const & cur, ParagraphList const & parlist, // set the paragraphs to plain layout if necessary DocumentClassConstPtr newDocClass = buffer.params().documentClassPtr(); if (cur.inset().usePlainLayout()) { - bool forcePlainLayout = cur.inset().forcePlainLayout(); + bool forcePlainLayout = target_inset->forcePlainLayout(); Layout const & plainLayout = newDocClass->plainLayout(); Layout const & defaultLayout = newDocClass->defaultLayout(); ParagraphList::iterator const end = insertion.end(); @@ -486,16 +486,18 @@ Buffer * copyToTempBuffer(ParagraphList const & paragraphs, DocumentClassConstPt // to be so, but the alternative is to construct a new one of these (with a // new temporary directory, etc) every time, and then to destroy it. So maybe // it's worth just keeping this one around. - // FIXME THREAD static TempFile tempfile("clipboard.internal"); tempfile.setAutoRemove(false); - static Buffer * staticbuffer = theBufferList().newInternalBuffer( - tempfile.name().absFileName()); - - // These two things only really need doing the first time. - staticbuffer->setUnnamed(true); - staticbuffer->inset().setBuffer(*staticbuffer); - + // The initialization of staticbuffer is thread-safe. Using a lambda + // guarantees that the properties are set only once. + static Buffer * staticbuffer = [&](){ + Buffer * b = + theBufferList().newInternalBuffer(tempfile.name().absFileName()); + b->setUnnamed(true); + b->inset().setBuffer(*b); + //initialize staticbuffer with b + return b; + }(); // Use a clone for the complicated stuff so that we do not need to clean // up in order to avoid a crash. Buffer * buffer = staticbuffer->cloneBufferOnly(); @@ -875,11 +877,9 @@ void cutSelection(Cursor & cur, bool doclear, bool realcut) if (begpit != endpit) cur.screenUpdateFlags(Update::Force | Update::FitCursor); - boost::tie(endpit, endpos) = - eraseSelectionHelper(bp, - text->paragraphs(), - begpit, endpit, - cur.selBegin().pos(), endpos); + tie(endpit, endpos) = + eraseSelectionHelper(bp, text->paragraphs(), begpit, endpit, + cur.selBegin().pos(), endpos); // cutSelection can invalidate the cursor so we need to set // it anew. (Lgb) @@ -1055,7 +1055,8 @@ docstring selection(size_t sel_index, DocumentClassConstPtr docclass) if (sel_index >= theCuts.size()) return docstring(); - boost::scoped_ptr buffer(copyToTempBuffer(theCuts[sel_index].first, docclass)); + unique_ptr buffer(copyToTempBuffer(theCuts[sel_index].first, + docclass)); if (!buffer) return docstring(); @@ -1169,6 +1170,7 @@ bool pasteClipboardText(Cursor & cur, ErrorList & errorList, bool asParagraphs, cur.text()->insertStringAsParagraphs(cur, text, cur.current_font); else cur.text()->insertStringAsLines(cur, text, cur.current_font); + cur.forceBufferUpdate(); return true; }