diff --git a/src/ChangeLog b/src/ChangeLog index bf6a53afaf..903eb5b7ab 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -4,6 +4,9 @@ * iterator.C: * undo_funcs.C: use getParagraphs() instead of getFirstParagraph() + * buffer.[Ch]: new function hasParWithId() to help to get rid of a + few naked Paragraph *. + 2003-05-02 Michael Schmitt * bufferparams.C: Output warning if a document with missing diff --git a/src/buffer.C b/src/buffer.C index ebf5700814..faa21353eb 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -2293,6 +2293,25 @@ ParagraphList::iterator Buffer::getParFromID(int id) const } +bool Buffer::hasParWithID(int id) const +{ + ParIterator it(const_cast(this)->par_iterator_begin()); + ParIterator end(const_cast(this)->par_iterator_end()); + + if (id < 0) { + // John says this is called with id == -1 from undo + lyxerr << "hasParWithID(), id: " << id << endl; + return 0; + } + + for (; it != end; ++it) + if ((*it)->id() == id) + return true; + + return false; +} + + ParIterator Buffer::par_iterator_begin() { return ParIterator(&*(paragraphs.begin())); diff --git a/src/buffer.h b/src/buffer.h index 2b324c0fb9..c6a2cb8901 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -123,6 +123,8 @@ public: LyXFont const &, string const &); /// ParagraphList::iterator getParFromID(int id) const; + /// do we have a paragraph with this id? + bool hasParWithID(int id) const; public: /** Save file. diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 9920510543..8f663e758a 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -5,6 +5,7 @@ * insettext.[Ch]: * insettabular.[Ch]: * insetcollapsable.[Ch]: remove unused function firstParagraph() + replace getFirstParagraph() by getParagraphs() 2003-05-03 John Levon diff --git a/src/undo_funcs.C b/src/undo_funcs.C index 71467a6daf..63cbe37fc9 100644 --- a/src/undo_funcs.C +++ b/src/undo_funcs.C @@ -46,15 +46,15 @@ LyXCursor const & undoCursor(BufferView * bv) * we are so it will return the first paragraph of the buffer or the * first paragraph of the textinset we're in. */ -Paragraph * firstUndoParagraph(BufferView * bv, int inset_id) +ParagraphList undoParagraphs(BufferView * bv, int inset_id) { Inset * inset = bv->buffer()->getInsetFromID(inset_id); if (inset) { ParagraphList * result = inset->getParagraphs(0); if (result && !result->empty()) - return &result->front(); + return *result; } - return &bv->text->ownerParagraphs().front(); + return bv->text->ownerParagraphs(); } @@ -93,7 +93,7 @@ bool textHandleUndo(BufferView * bv, Undo & undo) num = -1; } } - t->setCursorIntern(firstUndoParagraph(bv, num), 0); + t->setCursorIntern(undoParagraphs(bv, num).begin(), 0); } // Set the right(new) inset-owner of the paragraph if there is any. @@ -116,7 +116,7 @@ bool textHandleUndo(BufferView * bv, Undo & undo) if (before) deletepar = before->next(); else - deletepar = firstUndoParagraph(bv, undo.number_of_inset_id); + deletepar = &undoParagraphs(bv, undo.number_of_inset_id).front(); // this surprisingly fills the undo! (Andre') size_t par = 0; while (deletepar && deletepar != behind) { @@ -152,7 +152,7 @@ bool textHandleUndo(BufferView * bv, Undo & undo) if (before) before->next(undopar); else { - int id = firstUndoParagraph(bv, undo.number_of_inset_id)->id(); + int id = undoParagraphs(bv, undo.number_of_inset_id).front().id(); Paragraph * op = &*bv->buffer()->getParFromID(id); if (op && op->inInset()) { static_cast(op->inInset())->paragraph(undopar); @@ -165,7 +165,7 @@ bool textHandleUndo(BufferView * bv, Undo & undo) // have to substitue the second paragraph with the // first if the removed one is the first. if (!before && behind) { - int id = firstUndoParagraph(bv, undo.number_of_inset_id)->id(); + int id = undoParagraphs(bv, undo.number_of_inset_id).front().id(); Paragraph * op = &*bv->buffer()->getParFromID(id); if (op && op->inInset()) { static_cast(op->inInset())->paragraph(behind); @@ -382,7 +382,7 @@ bool textUndoOrRedo(BufferView * bv, if (first && first->next()) first = first->next(); else if (!first) - first = firstUndoParagraph(bv, undo->number_of_inset_id); + first = &*undoParagraphs(bv, undo->number_of_inset_id).begin(); if (first) { shared_ptr u; if (createUndo(bv, undo->kind, first,