+void pasteFromStack(LCursor & cur, ErrorList & errorList, size_t sel_index)
+{
+ // this does not make sense, if there is nothing to paste
+ if (!checkPastePossible(sel_index))
+ return;
+
+ recordUndo(cur);
+ pasteParagraphList(cur, theCuts[sel_index].first,
+ theCuts[sel_index].second, errorList);
+ cur.setSelection();
+ saveSelection(cur);
+}
+
+
+void pasteClipboard(LCursor & cur, ErrorList & errorList, bool asParagraphs)
+{
+ // Use internal clipboard if it is the most recent one
+ if (theClipboard().isInternal()) {
+ pasteFromStack(cur, errorList, 0);
+ return;
+ }
+
+ // First try LyX format
+ if (theClipboard().hasLyXContents()) {
+ string lyx = theClipboard().getAsLyX();
+ if (!lyx.empty()) {
+ // For some strange reason gcc 3.2 and 3.3 do not accept
+ // Buffer buffer(string(), false);
+ Buffer buffer("", false);
+ buffer.setUnnamed(true);
+ if (buffer.readString(lyx)) {
+ recordUndo(cur);
+ pasteParagraphList(cur, buffer.paragraphs(),
+ buffer.params().textclass, errorList);
+ cur.setSelection();
+ return;
+ }
+ }
+ }
+
+ // Then try plain text
+ docstring const text = theClipboard().getAsText();
+ if (text.empty())
+ return;
+ recordUndo(cur);
+ if (asParagraphs)
+ cur.text()->insertStringAsParagraphs(cur, text);
+ else
+ cur.text()->insertStringAsLines(cur, text);
+}
+
+
+void pasteSelection(LCursor & cur, ErrorList & errorList)