#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 <boost/tuple/tuple.hpp>
-
#include <string>
+#include <tuple>
using namespace std;
using namespace lyx::support;
struct PasteReturnValue {
- PasteReturnValue(pit_type r_par, pos_type r_pos, bool r_nu) :
- par(r_par), pos(r_pos), needupdate(r_nu)
+ PasteReturnValue(pit_type r_pit, pos_type r_pos, bool r_nu) :
+ pit(r_pit), pos(r_pos), needupdate(r_nu)
{}
- pit_type par;
+ pit_type pit;
pos_type pos;
bool needupdate;
};
// 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();
// 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();
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)
LBUFERR(text);
// ok we have a selection. This is always between cur.selBegin()
// and sel_end cursor
-
- // copy behind a space if there is one
- ParagraphList & pars = text->paragraphs();
- pos_type pos = cur.selBegin().pos();
- pit_type par = cur.selBegin().pit();
- while (pos < pars[par].size() &&
- pars[par].isLineSeparator(pos) &&
- (par != cur.selEnd().pit() || pos < cur.selEnd().pos()))
- ++pos;
-
- copySelectionHelper(*cur.buffer(), *text, par, cur.selEnd().pit(),
- pos, cur.selEnd().pos(),
- cur.buffer()->params().documentClassPtr(), cutstack);
-
+ copySelectionHelper(*cur.buffer(), *text,
+ cur.selBegin().pit(), cur.selEnd().pit(),
+ cur.selBegin().pos(), cur.selEnd().pos(),
+ cur.buffer()->params().documentClassPtr(),
+ cutstack);
// Reset the dirty_tabular_stack_ flag only when something
// is copied to the clipboard (not to the selectionBuffer).
if (&cutstack == &theCuts)
if (sel_index >= theCuts.size())
return docstring();
- boost::scoped_ptr<Buffer> buffer(copyToTempBuffer(theCuts[sel_index].first, docclass));
+ unique_ptr<Buffer> buffer(copyToTempBuffer(theCuts[sel_index].first,
+ docclass));
if (!buffer)
return docstring();
pasteSelectionHelper(cur, parlist, docclass, 0, errorList);
cur.forceBufferUpdate();
cur.clearSelection();
- text->setCursor(cur, prv.par, prv.pos);
+ text->setCursor(cur, prv.pit, prv.pos);
}
// mathed is handled in InsetMathNest/InsetMathGrid
cur.text()->insertStringAsParagraphs(cur, text, cur.current_font);
else
cur.text()->insertStringAsLines(cur, text, cur.current_font);
+ cur.forceBufferUpdate();
return true;
}
if (lyxrc.auto_region_delete)
selDel(cur);
else
- cur.setSelection(false);
+ cur.selection(false);
}