* buffer.[Ch]: new function hasParWithId() to help to get rid of a

few naked Paragraph *.
* undo_funcs use getParagraphs() instead of getFirstParagraph()


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6935 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2003-05-05 17:28:21 +00:00
parent aee7213a76
commit 1badafaa40
5 changed files with 33 additions and 8 deletions

View File

@ -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 <michael.schmitt@teststep.org>
* bufferparams.C: Output warning if a document with missing

View File

@ -2293,6 +2293,25 @@ ParagraphList::iterator Buffer::getParFromID(int id) const
}
bool Buffer::hasParWithID(int id) const
{
ParIterator it(const_cast<Buffer*>(this)->par_iterator_begin());
ParIterator end(const_cast<Buffer*>(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()));

View File

@ -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.

View File

@ -5,6 +5,7 @@
* insettext.[Ch]:
* insettabular.[Ch]:
* insetcollapsable.[Ch]: remove unused function firstParagraph()
replace getFirstParagraph() by getParagraphs()
2003-05-03 John Levon <levon@movementarian.org>

View File

@ -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<InsetText*>(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<InsetText*>(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<Undo> u;
if (createUndo(bv, undo->kind, first,