From: Lars Gullik Bjønnes Date: Mon, 9 Jul 2001 09:16:00 +0000 (+0000) Subject: move getParFromID to Buffer X-Git-Tag: 1.6.10~21114 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=f6c9132899e64981284ae1e941136d8d1c97c0e4;p=features.git move getParFromID to Buffer git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2207 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/BufferView2.C b/src/BufferView2.C index d6f99fcef7..dc33aa5727 100644 --- a/src/BufferView2.C +++ b/src/BufferView2.C @@ -156,7 +156,7 @@ void BufferView::insertErrors(TeXErrors & terr) texrowpar = text->firstParagraph(); tmppos = 0; } else { - texrowpar = text->getParFromID(tmpid); + texrowpar = buffer()->getParFromID(tmpid); } if (texrowpar == 0) @@ -185,7 +185,7 @@ void BufferView::setCursorFromRow(int row) texrowpar = text->firstParagraph(); tmppos = 0; } else { - texrowpar = text->getParFromID(tmpid); + texrowpar = buffer()->getParFromID(tmpid); } text->setCursor(this, texrowpar, tmppos); } diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index b15dd9ad75..beae2eacb5 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -1149,7 +1149,7 @@ void BufferView::Pimpl::restorePosition(unsigned int i) if (b != 0 ) buffer(b); } - Paragraph * par = bv_->text->getParFromID(saved_positions[i].par_id); + Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id); if (!par) return; diff --git a/src/ChangeLog b/src/ChangeLog index e53a39a186..782f869530 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,17 @@ +2001-07-09 Lars Gullik Bjønnes + + * text2.C (getParFromID): removed + + * buffer.C (getParFromID): new method moved form lyxtext. + * BufferView2.C (insertErrors): adjust + (setCursorFromRow): adjust + * BufferView_pimpl.C (restorePosition): adjust + * lyxfunc.C (Dispatch): adjust + * undo_funcs.C (textUndo): adjust + (textRedo): adjust + (textHandleUndo): adjust + (textHandleUndo): adjust + 2001-07-08 Lars Gullik Bjønnes * buffer.C: up' the LYX_FORMAT diff --git a/src/buffer.C b/src/buffer.C index f2dcf5d428..7f9ab8ccd0 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -3689,3 +3689,21 @@ Inset * Buffer::getInsetFromID(int id_arg) const } return 0; } + + +Paragraph * Buffer::getParFromID(int id) const +{ + if (id < 0) return 0; + Paragraph * par = paragraph; + while (par) { + if (par->id() == id) { + return par; + } + Paragraph * tmp = par->getParFromID(id); + if (tmp) { + return tmp; + } + par = par->next(); + } + return 0; +} diff --git a/src/buffer.h b/src/buffer.h index bf384d4615..dedb17f273 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -128,6 +128,8 @@ public: void insertErtContents(Paragraph * par, int & pos, LyXFont const & font, bool set_inactive = true); + /// + Paragraph * getParFromID(int id) const; private: /// Parse a single inset. void readInset(LyXLex &, Paragraph *& par, int & pos, LyXFont &); diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index 8f58e1435e..96b4b29768 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -498,21 +498,25 @@ int InsetCollapsable::scroll(bool recursive) const return sx; } + Paragraph * InsetCollapsable::getParFromID(int id) const { return inset.getParFromID(id); } + Paragraph * InsetCollapsable::firstParagraph() const { return inset.firstParagraph(); } + LyXCursor const & InsetCollapsable::cursor(BufferView * bv) const { return inset.cursor(bv); } + Inset * InsetCollapsable::getInsetFromID(int id_arg) const { if (id_arg == id()) diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index a343e41cd9..2fda1bfe29 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -2392,8 +2392,8 @@ void InsetTabular::getSelection(int & srow, int & erow, int & scol, int & ecol) Paragraph * InsetTabular::getParFromID(int id) const { Paragraph * result; - for(int i=0; i < tabular->rows(); ++i) { - for(int j=0; j < tabular->columns(); ++j) { + for(int i = 0; i < tabular->rows(); ++i) { + for(int j = 0; j < tabular->columns(); ++j) { if ((result = tabular->GetCellInset(i, j)->getParFromID(id))) return result; } diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 58af552d64..5b0e3aa863 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -1826,6 +1826,7 @@ void InsetText::clearInset(Painter & pain, int baseline, bool & cleared) const need_update = FULL; } + Paragraph * InsetText::getParFromID(int id) const { Paragraph * result = par; @@ -1838,6 +1839,7 @@ Paragraph * InsetText::getParFromID(int id) const return result; } + Paragraph * InsetText::firstParagraph() const { Paragraph * result; @@ -1847,6 +1849,7 @@ Paragraph * InsetText::firstParagraph() const return par; } + LyXCursor const & InsetText::cursor(BufferView * bv) const { if (the_locking_inset) @@ -1854,11 +1857,13 @@ LyXCursor const & InsetText::cursor(BufferView * bv) const return getLyXText(bv)->cursor; } + Paragraph * InsetText::paragraph() const { return par; } + void InsetText::paragraph(Paragraph * p) { par = p; @@ -1873,6 +1878,7 @@ void InsetText::paragraph(Paragraph * p) need_update |= INIT; } + Inset * InsetText::getInsetFromID(int id_arg) const { if (id_arg == id()) diff --git a/src/lyxfunc.C b/src/lyxfunc.C index b4a1af2178..00feadb065 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -1326,7 +1326,7 @@ string const LyXFunc::Dispatch(int ac, int id; istr >> id; - Paragraph * par = TEXT()->getParFromID(id); + Paragraph * par = owner->buffer()->getParFromID(id); if (par == 0) { lyxerr[Debug::INFO] << "No matching paragraph found! [" << id << "]" << std::endl; diff --git a/src/lyxtext.h b/src/lyxtext.h index deeb79729d..e5f4275df9 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -442,9 +442,6 @@ public: /// int numberOfCell(Paragraph * par, Paragraph::size_type pos) const; - /// - Paragraph * getParFromID(int id) const; - /// void removeTableRow(LyXCursor & cursor) const; /// diff --git a/src/paragraph_pimpl.C b/src/paragraph_pimpl.C index 56b440f618..0963a4f124 100644 --- a/src/paragraph_pimpl.C +++ b/src/paragraph_pimpl.C @@ -546,11 +546,10 @@ Paragraph * Paragraph::Pimpl::TeXDeeper(Buffer const * buf, Paragraph * Paragraph::Pimpl::getParFromID(int id) const { + InsetList::const_iterator cit = owner_->insetlist.begin(); InsetList::const_iterator lend = owner_->insetlist.end(); Paragraph * result; - for (InsetList::const_iterator cit = owner_->insetlist.begin(); - cit != lend; ++cit) - { + for (; cit != lend; ++cit) { if ((result = cit->inset->getParFromID(id))) return result; } diff --git a/src/text2.C b/src/text2.C index 575405f685..70d560cc6d 100644 --- a/src/text2.C +++ b/src/text2.C @@ -2402,20 +2402,6 @@ void LyXText::deleteEmptyParagraphMechanism(BufferView * bview, } -Paragraph * LyXText::getParFromID(int id) const -{ - if (id < 0) - return 0; - Paragraph * result = firstParagraph(); - Paragraph * ires = 0; - while (result && result->id() != id) { - if ((ires = result->getParFromID(id))) - return ires; - result = result->next(); - } - return result; -} - void LyXText::toggleAppendix(BufferView * bview) { Paragraph * par = cursor.par(); @@ -2459,7 +2445,7 @@ Paragraph * LyXText::ownerParagraph(Paragraph * p) const Paragraph * LyXText::ownerParagraph(int id, Paragraph * p) const { - Paragraph * op = getParFromID(id); + Paragraph * op = bv_owner->buffer()->getParFromID(id); if (op && op->InInset()) { static_cast(op->InInset())->paragraph(p); } else { diff --git a/src/undo_funcs.C b/src/undo_funcs.C index d1b0f2ab48..0288a053c5 100644 --- a/src/undo_funcs.C +++ b/src/undo_funcs.C @@ -32,13 +32,13 @@ bool textUndo(BufferView * bv) if (undo) { finishUndo(); if (!undo_frozen) { - Paragraph * first = bv->text->getParFromID(undo->number_of_before_par); + Paragraph * first = bv->buffer()->getParFromID(undo->number_of_before_par); if (!first) first = firstUndoParagraph(bv, undo->number_of_inset_id); if (first) { bv->buffer()->redostack.push( createUndo(bv, undo->kind, first, - bv->text->getParFromID(undo->number_of_behind_par))); + bv->buffer()->getParFromID(undo->number_of_behind_par))); } } } @@ -53,13 +53,13 @@ bool textRedo(BufferView * bv) if (undo) { finishUndo(); if (!undo_frozen) { - Paragraph * first = bv->text->getParFromID(undo->number_of_before_par); + Paragraph * first = bv->buffer()->getParFromID(undo->number_of_before_par); if (!first) first = firstUndoParagraph(bv, undo->number_of_inset_id); if (first) { bv->buffer()->undostack.push( createUndo(bv, undo->kind, first, - bv->text->getParFromID(undo->number_of_behind_par))); + bv->buffer()->getParFromID(undo->number_of_behind_par))); } } } @@ -73,9 +73,9 @@ bool textHandleUndo(BufferView * bv, Undo * undo) bool result = false; if (undo) { Paragraph * before = - bv->text->getParFromID(undo->number_of_before_par); + bv->buffer()->getParFromID(undo->number_of_before_par); Paragraph * behind = - bv->text->getParFromID(undo->number_of_behind_par); + bv->buffer()->getParFromID(undo->number_of_behind_par); Paragraph * tmppar; Paragraph * tmppar2; Paragraph * endpar; @@ -158,7 +158,7 @@ bool textHandleUndo(BufferView * bv, Undo * undo) } else endpar = behind; - tmppar = bv->text->getParFromID(undo->number_of_cursor_par); + tmppar = bv->buffer()->getParFromID(undo->number_of_cursor_par); UpdatableInset* it = static_cast(tmppar3->InInset()); if (it) { it->getLyXText(bv)->redoParagraphs(bv, it->getLyXText(bv)->cursor,