InsetText * target_inset = cur.inset().asInsetText();
if (!target_inset) {
InsetTabular * it = cur.inset().asInsetTabular();
- target_inset = it? it->cell(cur.idx())->asInsetText() : 0;
+ target_inset = it ? it->cell(cur.idx())->asInsetText() : 0;
}
LASSERT(target_inset, return PasteReturnValue(pit, pos, need_update));
if (forcePlainLayout || parLayout == defaultLayout)
par->setLayout(plainLayout);
}
- } else { // check if we need to reset from plain layout
+ } else {
+ // check if we need to reset from plain layout
Layout const & defaultLayout = newDocClass->defaultLayout();
Layout const & plainLayout = newDocClass->plainLayout();
ParagraphList::iterator const end = insertion.end();
}
-void putClipboard(ParagraphList const & paragraphs,
- DocumentClassConstPtr docclass, docstring const & plaintext)
+Buffer * copyToTempBuffer(ParagraphList const & paragraphs, DocumentClassConstPtr docclass)
{
// This used to need to be static to avoid a memory leak. It no longer needs
// to be so, but the alternative is to construct a new one of these (with a
// 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();
- LASSERT(buffer, return);
+ LASSERT(buffer, return 0);
// This needs doing every time.
+ // Since setDocumentClass() causes deletion of the old document class
+ // we need to reset all layout pointers in paragraphs (otherwise they
+ // would be dangling).
+ ParIterator const end = buffer->par_iterator_end();
+ for (ParIterator it = buffer->par_iterator_begin(); it != end; ++it) {
+ docstring const name = it->layout().name();
+ if (docclass->hasLayout(name))
+ it->setLayout((*docclass)[name]);
+ else
+ it->setPlainOrDefaultLayout(*docclass);
+ }
buffer->params().setDocumentClass(docclass);
// we will use pasteSelectionHelper to copy the paragraphs into the
ErrorList el;
pasteSelectionHelper(dit, paragraphs, docclass, buffer, el);
+ return buffer;
+}
+
+
+void putClipboard(ParagraphList const & paragraphs,
+ DocumentClassConstPtr docclass, docstring const & plaintext)
+{
+ Buffer * buffer = copyToTempBuffer(paragraphs, docclass);
+ if (!buffer) // already asserted in copyToTempBuffer()
+ return;
+
// We don't want to produce images that are not used. Therefore,
// output formulas as MathML. Even if this is not understood by all
// applications, the number that can parse it should go up in the future.
}
-docstring selection(size_t sel_index)
+docstring selection(size_t sel_index, DocumentClassConstPtr docclass)
{
- return sel_index < theCuts.size()
- ? theCuts[sel_index].first.back().asString(AS_STR_INSETS | AS_STR_NEWLINES)
- : docstring();
+ if (sel_index >= theCuts.size())
+ return docstring();
+
+ boost::scoped_ptr<Buffer> buffer(copyToTempBuffer(theCuts[sel_index].first, docclass));
+ if (!buffer)
+ return docstring();
+
+ return buffer->paragraphs().back().asString(AS_STR_INSETS | AS_STR_NEWLINES);
}