- if (inset_owner)
- return false;
- // returns false if no undo possible
- bool result = false;
- if (undo) {
- LyXParagraph * before =
- GetParFromID(undo->number_of_before_par);
- LyXParagraph * behind =
- GetParFromID(undo->number_of_behind_par);
- LyXParagraph * tmppar;
- LyXParagraph * tmppar2;
- LyXParagraph * endpar;
- LyXParagraph * tmppar5;
-
- // if there's no before take the beginning
- // of the document for redoing
- if (!before)
- SetCursorIntern(bview, FirstParagraph(), 0);
-
- // replace the paragraphs with the undo informations
-
- LyXParagraph * tmppar3 = undo->par;
- undo->par = 0; // otherwise the undo destructor would delete the paragraph
- LyXParagraph * tmppar4 = tmppar3;
- if (tmppar4){
- while (tmppar4->next)
- tmppar4 = tmppar4->next;
- } // get last undo par
-
- // now remove the old text if there is any
- if (before != behind || (!behind && !before)){
- if (before)
- tmppar5 = before->next;
- else
- tmppar5 = OwnerParagraph();
- tmppar2 = tmppar3;
- while (tmppar5 && tmppar5 != behind){
- tmppar = tmppar5;
- tmppar5 = tmppar5->next;
- // a memory optimization for edit: Only layout information
- // is stored in the undo. So restore the text informations.
- if (undo->kind == Undo::EDIT) {
- tmppar2->setContentsFromPar(tmppar);
- tmppar->clearContents();
- tmppar2 = tmppar2->next;
- }
- }
- }
-
- // put the new stuff in the list if there is one
- if (tmppar3){
- if (before)
- before->next = tmppar3;
- else
- OwnerParagraph(tmppar3);
- tmppar3->previous = before;
- }
- else {
- if (!before)
- OwnerParagraph(behind);
- }
- if (tmppar4) {
- tmppar4->next = behind;
- if (behind)
- behind->previous = tmppar4;
- }
-
-
- // Set the cursor for redoing
- if (before) {
- SetCursorIntern(bview, before->FirstSelfrowPar(), 0);
- // check wether before points to a closed float and open it if necessary
- if (before && before->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE
- && before->next && before->next->footnoteflag != LyXParagraph::NO_FOOTNOTE){
- tmppar4 = before;
- while (tmppar4->previous &&
- tmppar4->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
- tmppar4 = tmppar4->previous;
- while (tmppar4 && tmppar4->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE){
- tmppar4->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
- tmppar4 = tmppar4->next;
- }
- }
- }
-
- // open a cosed footnote at the end if necessary
- if (behind && behind->previous &&
- behind->previous->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
- behind->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE){
- while (behind && behind->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE){
- behind->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
- behind = behind->next;
- }
- }
-
- // calculate the endpar for redoing the paragraphs.
- if (behind) {
- if (behind->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
- endpar = behind->LastPhysicalPar()->Next();
- else
- endpar = behind->NextAfterFootnote()->LastPhysicalPar()->Next();
- } else
- endpar = behind;
-
- tmppar = GetParFromID(undo->number_of_cursor_par);
- RedoParagraphs(bview, cursor, endpar);
- if (tmppar){
- SetCursorIntern(bview, tmppar, undo->cursor_pos);
- UpdateCounters(bview, cursor.row());
- }
- result = true;
- delete undo;