- LyXParagraph * tmppar;
- LyXParagraph * endpar;
-
- LyXCursor tmpcursor;
-
- // be carefull with footnotes in footnotes
- if (cursor.par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
-
- // check whether the cut_buffer includes a footnote
- tmppar = simple_cut_buffer;
- while (tmppar
- && tmppar->footnoteflag == LyXParagraph::NO_FOOTNOTE)
- tmppar = tmppar->next;
-
- if (tmppar) {
- WriteAlert(_("Impossible operation"),
- _("Can't paste float into float!"),
- _("Sorry."));
- return;
- }
- }
-
- /* table stuff -- begin */
- if (cursor.par->table) {
- if (simple_cut_buffer->next) {
- WriteAlert(_("Impossible operation"),
- _("Table cell cannot include more than one paragraph!"),
- _("Sorry."));
- return;
- }
- }
- /* table stuff -- end */
-
- SetUndo(Undo::INSERT,
- cursor.par->ParFromPos(cursor.pos)->previous,
- cursor.par->ParFromPos(cursor.pos)->next);
-
- tmpcursor = cursor;
-
- // There are two cases: cutbuffer only one paragraph or many
- if (!simple_cut_buffer->next) {
- // only within a paragraph
-
- tmppar = simple_cut_buffer->Clone();
- /* table stuff -- begin */
- bool table_too_small = false;
- if (tmpcursor.par->table) {
- while (simple_cut_buffer->size()
- && !table_too_small) {
- if (simple_cut_buffer->IsNewline(0)){
- while(tmpcursor.pos < tmpcursor.par->Last() && !tmpcursor.par->IsNewline(tmpcursor.pos))
- tmpcursor.pos++;
- simple_cut_buffer->Erase(0);
- if (tmpcursor.pos < tmpcursor.par->Last())
- tmpcursor.pos++;
- else
- table_too_small = true;
- } else {
- // This is an attempt to fix the
- // "never insert a space at the
- // beginning of a paragraph" problem.
- if (tmpcursor.pos == 0
- && simple_cut_buffer->IsLineSeparator(0)) {
- simple_cut_buffer->Erase(0);
- } else {
- simple_cut_buffer->CutIntoMinibuffer(0);
- simple_cut_buffer->Erase(0);
- tmpcursor.par->InsertFromMinibuffer(tmpcursor.pos);
- tmpcursor.pos++;
- }
- }
- }
- } else {
- /* table stuff -- end */
- // Some provisions should be done here for checking
- // if we are inserting at the beginning of a
- // paragraph. If there are a space at the beginning
- // of the text to insert and we are inserting at
- // the beginning of the paragraph the space should
- // be removed.
- while (simple_cut_buffer->size()) {
- // This is an attempt to fix the
- // "never insert a space at the
- // beginning of a paragraph" problem.
- if (tmpcursor.pos == 0
- && simple_cut_buffer->IsLineSeparator(0)) {
- simple_cut_buffer->Erase(0);
- } else {
- simple_cut_buffer->CutIntoMinibuffer(0);
- simple_cut_buffer->Erase(0);
- tmpcursor.par->InsertFromMinibuffer(tmpcursor.pos);
- tmpcursor.pos++;
- }
- }
- }
- delete simple_cut_buffer;
- simple_cut_buffer = tmppar;
- endpar = tmpcursor.par->Next();
- } else {
- // many paragraphs
- CutAndPaste cap;
-
- // make a copy of the simple cut_buffer
- tmppar = simple_cut_buffer;
- LyXParagraph * simple_cut_clone = tmppar->Clone();
- LyXParagraph * tmppar2 = simple_cut_clone;
- if (cursor.par->footnoteflag){
- tmppar->footnoteflag = cursor.par->footnoteflag;
- tmppar->footnotekind = cursor.par->footnotekind;
- }
- while (tmppar->next) {
- tmppar = tmppar->next;
- tmppar2->next = tmppar->Clone();
- tmppar2->next->previous = tmppar2;
- tmppar2 = tmppar2->next;
- if (cursor.par->footnoteflag){
- tmppar->footnoteflag = cursor.par->footnoteflag;
- tmppar->footnotekind = cursor.par->footnotekind;
- }
- }
-
- // make sure there is no class difference
- cap.SwitchLayoutsBetweenClasses(simple_cut_buffer_textclass,
- buffer->params.textclass,
- simple_cut_buffer);
-
- // make the simple_cut_buffer exactly the same layout than
- // the cursor paragraph
- simple_cut_buffer->MakeSameLayout(cursor.par);
-
- // find the end of the buffer
- LyXParagraph * lastbuffer = simple_cut_buffer;
- while (lastbuffer->Next())
- lastbuffer = lastbuffer->Next();
-
- bool paste_the_end = false;
-
- // open the paragraph for inserting the simple_cut_buffer
- // if necessary
- if (cursor.par->Last() > cursor.pos || !cursor.par->Next()){
- cursor.par->BreakParagraphConservative(cursor.pos);
- paste_the_end = true;
- }
-
- // set the end for redoing later
- endpar = cursor.par->ParFromPos(cursor.pos)->next->Next();
-
- // paste it!
- lastbuffer->ParFromPos(lastbuffer->Last())->next =
- cursor.par->ParFromPos(cursor.pos)->next;
- cursor.par->ParFromPos(cursor.pos)->next->previous =
- lastbuffer->ParFromPos(lastbuffer->Last());
-
- cursor.par->ParFromPos(cursor.pos)->next = simple_cut_buffer;
- simple_cut_buffer->previous =
- cursor.par->ParFromPos(cursor.pos);
-
- if (cursor.par->ParFromPos(cursor.pos)->Next() == lastbuffer)
- lastbuffer = cursor.par;
-
- cursor.par->ParFromPos(cursor.pos)->PasteParagraph();
-
- // store the new cursor position
- tmpcursor.par = lastbuffer;
- tmpcursor.pos = lastbuffer->Last();
-
- // maybe some pasting
- if (lastbuffer->Next() && paste_the_end) {
- if (lastbuffer->Next()->HasSameLayout(lastbuffer)) {
- lastbuffer->ParFromPos(lastbuffer->Last())->PasteParagraph();
-
- } else if (!lastbuffer->Next()->Last()) {
- lastbuffer->Next()->MakeSameLayout(lastbuffer);
- lastbuffer->ParFromPos(lastbuffer->Last())->PasteParagraph();
-
- } else if (!lastbuffer->Last()) {
- lastbuffer->MakeSameLayout(lastbuffer->next);
- lastbuffer->ParFromPos(lastbuffer->Last())->PasteParagraph();
-
- } else
- lastbuffer->Next()->StripLeadingSpaces(buffer->params.textclass);
- }