CutStack theCuts(10);
// persistent selection, cleared until the next selection
CutStack selectionBuffer(1);
+// temporary scratch area
+CutStack tempCut(1);
// store whether the tabular stack is newer than the normal copy stack
// FIXME: this is a workaround for bug 1919. Should be removed for 1.5,
PasteReturnValue
pasteSelectionHelper(DocIterator const & cur, ParagraphList const & parlist,
- DocumentClassConstPtr oldDocClass, Buffer * tmpbuffer,
+ DocumentClassConstPtr oldDocClass, cap::BranchAction branchAction,
ErrorList & errorlist)
{
Buffer const & buffer = *cur.buffer();
// 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();
|| (is_child && (branchlist.find(name)
|| buffer.masterBuffer()->params().branchlist().find(name))))
break;
- if (tmpbuffer) {
+ switch(branchAction) {
+ case cap::BRANCH_ADD: {
// This is for a temporary buffer, so simply create the branch.
// Must not use lyx::dispatch(), since tmpbuffer has no view.
DispatchResult dr;
- tmpbuffer->dispatch(FuncRequest(LFUN_BRANCH_ADD, name), dr);
- } else {
+ const_cast<Buffer&>(buffer).dispatch(FuncRequest(LFUN_BRANCH_ADD, name), dr);
+ break;
+ }
+ case cap::BRANCH_ASK: {
docstring text = bformat(
_("The pasted branch \"%1$s\" is undefined.\n"
"Do you want to add it to the document's branch list?"),
text, 0, 1, _("&Add"), _("&Don't Add")) != 0)
break;
lyx::dispatch(FuncRequest(LFUN_BRANCH_ADD, name));
+ break;
+ }
+ case cap::BRANCH_IGNORE:
+ break;
}
// We need to update the list of branches.
need_update = true;
// 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();
// temporary Buffer, since it does a lot of things to fix them up.
DocIterator dit = doc_iterator_begin(buffer, &buffer->inset());
ErrorList el;
- pasteSelectionHelper(dit, paragraphs, docclass, buffer, el);
+ pasteSelectionHelper(dit, paragraphs, docclass, cap::BRANCH_ADD, el);
return buffer;
}
// are not linked to something else.
it = copy_pars.begin();
for (; it != it_end; ++it) {
- it->setBuffer(*static_cast<Buffer *>(0));
+ it->resetBuffer();
it->setInsetOwner(0);
}
if (added_one || newlayouts.find(name) != newlayouts.end()) {
// Warn the user.
docstring const s = bformat(_("Layout `%1$s' was not found."), name);
- errorlist.push_back(
- ErrorItem(_("Layout Not Found"), s, it->id(), 0, it->size()));
+ errorlist.push_back(ErrorItem(_("Layout Not Found"), s,
+ {it->id(), 0}, {it->id(), -1}));
}
if (in.usePlainLayout())
layoutName, oldname, newname);
// To warn the user that something had to be done.
errorlist.push_back(ErrorItem(
- _("Undefined flex inset"),
- s, it.paragraph().id(), it.pos(), it.pos() + 1));
+ _("Undefined flex inset"), s,
+ {it.paragraph().id(), it.pos()},
+ {it.paragraph().id(), it.pos()+1}));
} else if (code == TABULAR_CODE) {
// The recursion above does not catch paragraphs in "hidden" cells,
// i.e., ones that are part of a multirow or multicolum. So we need
return theCuts.size();
}
+namespace {
-void cutSelection(Cursor & cur, bool doclear, bool realcut)
+void cutSelectionHelper(Cursor & cur, CutStack & cuts, bool doclear, bool realcut, bool putclip)
{
// This doesn't make sense, if there is no selection
if (!cur.selection())
*text,
begpit, endpit,
cur.selBegin().pos(), endpos,
- bp.documentClassPtr(), theCuts);
+ bp.documentClassPtr(), cuts);
// Stuff what we got on the clipboard.
// Even if there is no selection.
- putClipboard(theCuts[0].first, theCuts[0].second,
- cur.selectionAsString(true));
+ if (putclip)
+ putClipboard(cuts[0].first, cuts[0].second,
+ cur.selectionAsString(true));
}
if (begpit != endpit)
}
}
+}
+
+void cutSelection(Cursor & cur, bool doclear, bool realcut)
+{
+ cutSelectionHelper(cur, theCuts, doclear, realcut, true);
+}
+
+
+void cutSelectionToTemp(Cursor & cur, bool doclear, bool realcut)
+{
+ cutSelectionHelper(cur, tempCut, doclear, realcut, false);
+}
+
void copySelection(Cursor const & cur)
{
void clearCutStack()
{
theCuts.clear();
+ tempCut.clear();
}
void pasteParagraphList(Cursor & cur, ParagraphList const & parlist,
- DocumentClassConstPtr docclass, ErrorList & errorList)
+ DocumentClassConstPtr docclass, ErrorList & errorList,
+ cap::BranchAction branchAction)
{
if (cur.inTexted()) {
Text * text = cur.text();
LBUFERR(text);
PasteReturnValue prv =
- pasteSelectionHelper(cur, parlist, docclass, 0, errorList);
+ pasteSelectionHelper(cur, parlist, docclass, branchAction, errorList);
cur.forceBufferUpdate();
cur.clearSelection();
text->setCursor(cur, prv.pit, prv.pos);
cur.recordUndo();
pasteParagraphList(cur, theCuts[sel_index].first,
- theCuts[sel_index].second, errorList);
+ theCuts[sel_index].second, errorList, BRANCH_ASK);
+ return true;
+}
+
+
+bool pasteFromTemp(Cursor & cur, ErrorList & errorList)
+{
+ // this does not make sense, if there is nothing to paste
+ if (tempCut.empty() || tempCut[0].first.empty())
+ return false;
+
+ cur.recordUndo();
+ pasteParagraphList(cur, tempCut[0].first,
+ tempCut[0].second, errorList, BRANCH_IGNORE);
return true;
}