return a ParIterator from getParFromID

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6996 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2003-05-22 08:01:41 +00:00
parent d605c30d8c
commit 204a070130
10 changed files with 115 additions and 94 deletions

View File

@ -509,13 +509,13 @@ void BufferView::setCursorFromRow(int row)
buffer()->texrow.getIdFromRow(row, tmpid, tmppos); buffer()->texrow.getIdFromRow(row, tmpid, tmppos);
Paragraph * texrowpar; ParagraphList::iterator texrowpar;
if (tmpid == -1) { if (tmpid == -1) {
texrowpar = &*text->ownerParagraphs().begin(); texrowpar = text->ownerParagraphs().begin();
tmppos = 0; tmppos = 0;
} else { } else {
texrowpar = &*buffer()->getParFromID(tmpid); texrowpar = *buffer()->getParFromID(tmpid);
} }
text->setCursor(texrowpar, tmppos); text->setCursor(texrowpar, tmppos);
} }

View File

@ -642,12 +642,12 @@ void BufferView::Pimpl::restorePosition(unsigned int i)
if (b != 0) buffer(b); if (b != 0) buffer(b);
} }
Paragraph * par = &*buffer_->getParFromID(saved_positions[i].par_id); ParIterator par = buffer_->getParFromID(saved_positions[i].par_id);
if (!par) if (par == buffer_->par_iterator_end())
return; return;
bv_->text->setCursor(par, bv_->text->setCursor(*par,
min(par->size(), saved_positions[i].par_pos)); min((*par)->size(), saved_positions[i].par_pos));
update(BufferView::SELECT); update(BufferView::SELECT);
if (i > 0) if (i > 0)

View File

@ -1,3 +1,15 @@
2003-05-22 André Pönitz <poenitz@gmx.net>
* BufferView.C:
* BufferView_pimpl.C:
* buffer.[Ch]:
* lyxfunc.C:
* undo_funcs.C: return a ParIterator from getParFromID.
* iterators.[Ch]: add two const's
2003-05-21 Lars Gullik Bjønnes <larsbj@gullik.net> 2003-05-21 Lars Gullik Bjønnes <larsbj@gullik.net>
* toc.C (getTocList): adjust * toc.C (getTocList): adjust

View File

@ -2203,7 +2203,7 @@ Inset * Buffer::getInsetFromID(int id_arg) const
} }
ParagraphList::iterator Buffer::getParFromID(int id) const ParIterator Buffer::getParFromID(int id) const
{ {
#warning FIXME: const correctness! (Andre) #warning FIXME: const correctness! (Andre)
ParIterator it(const_cast<Buffer*>(this)->par_iterator_begin()); ParIterator it(const_cast<Buffer*>(this)->par_iterator_begin());
@ -2213,18 +2213,14 @@ ParagraphList::iterator Buffer::getParFromID(int id) const
if (id < 0) { if (id < 0) {
// John says this is called with id == -1 from undo // John says this is called with id == -1 from undo
lyxerr << "getParFromID(), id: " << id << endl; lyxerr << "getParFromID(), id: " << id << endl;
return 0; return end;
} }
for (; it != end; ++it) { for (; it != end; ++it)
// go on then, show me how to remove if ((*it)->id() == id)
// the cast return it;
if ((*it)->id() == id) {
return *it;
}
}
return 0; return end;
} }

View File

@ -23,6 +23,7 @@
#include "ParagraphList.h" #include "ParagraphList.h"
#include "paragraph.h" #include "paragraph.h"
#include "author.h" #include "author.h"
#include "iterators.h"
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <boost/scoped_ptr.hpp> #include <boost/scoped_ptr.hpp>
@ -122,7 +123,7 @@ public:
void insertStringAsLines(ParagraphList::iterator &, lyx::pos_type &, void insertStringAsLines(ParagraphList::iterator &, lyx::pos_type &,
LyXFont const &, string const &); LyXFont const &, string const &);
/// ///
ParagraphList::iterator getParFromID(int id) const; ParIterator getParFromID(int id) const;
/// do we have a paragraph with this id? /// do we have a paragraph with this id?
bool hasParWithID(int id) const; bool hasParWithID(int id) const;

View File

@ -63,23 +63,23 @@ void ControlErrorList::goTo(int item)
if (err.par_id == -1) if (err.par_id == -1)
return; return;
ParagraphList::iterator pit = buf->getParFromID(err.par_id); ParIterator pit = buf->getParFromID(err.par_id);
if (pit == bv->text->ownerParagraphs().end()) { if (pit == buf->par_iterator_end()) {
lyxerr << "par id not found" << endl; lyxerr << "par id not found" << endl;
return; return;
} }
int range = err.pos_end - err.pos_start; int range = err.pos_end - err.pos_start;
if (err.pos_end > pit->size() || range <= 0) if (err.pos_end > (*pit)->size() || range <= 0)
range = pit->size() - err.pos_start; range = (*pit)->size() - err.pos_start;
// Now make the selection. // Now make the selection.
bv->insetUnlock(); bv->insetUnlock();
bv->toggleSelection(); bv->toggleSelection();
bv->text->clearSelection(); bv->text->clearSelection();
bv->text->setCursor(pit, err.pos_start); bv->text->setCursor(*pit, err.pos_start);
bv->text->setSelectionRange(range); bv->text->setSelectionRange(range);
bv->toggleSelection(false); bv->toggleSelection(false);
bv->fitCursor(); bv->fitCursor();

View File

@ -136,13 +136,13 @@ ParIterator & ParIterator::operator++()
} }
ParagraphList::iterator ParIterator::operator*() ParagraphList::iterator ParIterator::operator*() const
{ {
return pimpl_->positions.top().pit; return pimpl_->positions.top().pit;
} }
ParagraphList::iterator ParIterator::operator->() ParagraphList::iterator ParIterator::operator->() const
{ {
return pimpl_->positions.top().pit; return pimpl_->positions.top().pit;
} }
@ -243,13 +243,13 @@ ParConstIterator & ParConstIterator::operator++()
} }
ParagraphList::iterator ParConstIterator::operator*() ParagraphList::iterator ParConstIterator::operator*() const
{ {
return pimpl_->positions.top().pit; return pimpl_->positions.top().pit;
} }
ParagraphList::iterator ParConstIterator::operator->() ParagraphList::iterator ParConstIterator::operator->() const
{ {
return pimpl_->positions.top().pit; return pimpl_->positions.top().pit;
} }

View File

@ -27,9 +27,9 @@ public:
/// ///
ParIterator & operator++(); ParIterator & operator++();
/// ///
ParagraphList::iterator operator*(); ParagraphList::iterator operator*() const;
/// ///
ParagraphList::iterator operator->(); ParagraphList::iterator operator->() const;
/// ///
size_t size() const; size_t size() const;
/// ///
@ -58,10 +58,9 @@ public:
/// ///
ParConstIterator & operator++(); ParConstIterator & operator++();
/// ///
ParagraphList::iterator operator*(); ParagraphList::iterator operator*() const;
/// ///
ParagraphList::iterator operator->(); ParagraphList::iterator operator->() const;
/// ///
size_t size() const; size_t size() const;

View File

@ -1353,24 +1353,24 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
int id; int id;
istr >> id; istr >> id;
Paragraph * par = &*owner->buffer()->getParFromID(id); ParIterator par = owner->buffer()->getParFromID(id);
if (par == 0) { if (par == owner->buffer()->par_iterator_end()) {
lyxerr[Debug::INFO] << "No matching paragraph found! [" lyxerr[Debug::INFO] << "No matching paragraph found! ["
<< id << ']' << endl; << id << ']' << endl;
break; break;
} else { } else {
lyxerr[Debug::INFO] << "Paragraph " << par->id() lyxerr[Debug::INFO] << "Paragraph " << (*par)->id()
<< " found." << endl; << " found." << endl;
} }
if (view()->theLockingInset()) if (view()->theLockingInset())
view()->unlockInset(view()->theLockingInset()); view()->unlockInset(view()->theLockingInset());
if (par->inInset()) { if ((*par)->inInset()) {
FuncRequest cmd(view(), LFUN_INSET_EDIT, "left"); FuncRequest cmd(view(), LFUN_INSET_EDIT, "left");
par->inInset()->localDispatch(cmd); (*par)->inInset()->localDispatch(cmd);
} }
// Set the cursor // Set the cursor
view()->getLyXText()->setCursor(par, 0); view()->getLyXText()->setCursor(*par, 0);
view()->switchKeyMap(); view()->switchKeyMap();
owner->view_state_changed(); owner->view_state_changed();

View File

@ -78,12 +78,13 @@ bool textHandleUndo(BufferView * bv, Undo & undo)
{ {
Buffer * b = bv->buffer(); Buffer * b = bv->buffer();
Paragraph * const before = &*b->getParFromID(undo.number_of_before_par); ParIterator const before = b->getParFromID(undo.number_of_before_par);
Paragraph * const behind = &*b->getParFromID(undo.number_of_behind_par); ParIterator const behind = b->getParFromID(undo.number_of_behind_par);
ParIterator const end = b->par_iterator_end();
// If there's no before take the beginning // If there's no before take the beginning
// of the document for redoing. // of the document for redoing.
if (!before) { if (before == end) {
LyXText * t = bv->text; LyXText * t = bv->text;
int num = undo.number_of_inset_id; int num = undo.number_of_inset_id;
if (undo.number_of_inset_id >= 0) { if (undo.number_of_inset_id >= 0) {
@ -100,7 +101,7 @@ bool textHandleUndo(BufferView * bv, Undo & undo)
// Set the right(new) inset-owner of the paragraph if there is any. // Set the right(new) inset-owner of the paragraph if there is any.
if (!undo.pars.empty()) { if (!undo.pars.empty()) {
Inset * in = 0; Inset * in = 0;
if (before) if (before != end)
in = before->inInset(); in = before->inInset();
else if (undo.number_of_inset_id >= 0) else if (undo.number_of_inset_id >= 0)
in = bv->buffer()->getInsetFromID(undo.number_of_inset_id); in = bv->buffer()->getInsetFromID(undo.number_of_inset_id);
@ -112,17 +113,20 @@ bool textHandleUndo(BufferView * bv, Undo & undo)
vector<Paragraph *> deletelist; vector<Paragraph *> deletelist;
// Now add old paragraphs to be deleted. // Now add old paragraphs to be deleted.
if (before != behind || (!behind && !before)) { if (before != behind || (behind == end && before == end)) {
Paragraph * deletepar; ParagraphList::iterator deletepar;
if (before) if (before != end) {
deletepar = before->next(); deletepar = *before;
else ++deletepar;
deletepar = &undoParagraphs(bv, undo.number_of_inset_id).front(); } else {
deletepar = undoParagraphs(bv, undo.number_of_inset_id).begin();
}
// this surprisingly fills the undo! (Andre') // this surprisingly fills the undo! (Andre')
size_t par = 0; size_t par = 0;
while (deletepar && deletepar != behind) { //while (deletepar && deletepar != *behind) {
deletelist.push_back(deletepar); while (deletepar != *behind) {
deletepar = deletepar->next(); deletelist.push_back(&*deletepar);
++deletepar;
// A memory optimization for edit: // A memory optimization for edit:
// Only layout information // Only layout information
@ -141,21 +145,21 @@ bool textHandleUndo(BufferView * bv, Undo & undo)
// Thread the end of the undo onto the par in front if any. // Thread the end of the undo onto the par in front if any.
if (!undo.pars.empty()) { if (!undo.pars.empty()) {
undo.pars.back()->next(behind); undo.pars.back()->next(&**behind);
if (behind) if (behind != end)
behind->previous(undo.pars.back()); (&**behind)->previous(undo.pars.back());
} }
// Put the new stuff in the list if there is one. // Put the new stuff in the list if there is one.
Paragraph * undopar = undo.pars.empty() ? 0 : undo.pars.front(); Paragraph * undopar = undo.pars.empty() ? 0 : undo.pars.front();
if (!undo.pars.empty()) { if (!undo.pars.empty()) {
undo.pars.front()->previous(before); undo.pars.front()->previous(&**before);
if (before) if (before != end)
before->next(undopar); (&**before)->next(undopar);
else { else {
int id = undoParagraphs(bv, undo.number_of_inset_id).front().id(); int id = undoParagraphs(bv, undo.number_of_inset_id).front().id();
Paragraph * op = &*bv->buffer()->getParFromID(id); ParIterator op = bv->buffer()->getParFromID(id);
if (op && op->inInset()) { if (op != end && op->inInset()) {
static_cast<InsetText*>(op->inInset())->paragraph(undopar); static_cast<InsetText*>(op->inInset())->paragraph(undopar);
} else { } else {
bv->buffer()->paragraphs.set(undopar); bv->buffer()->paragraphs.set(undopar);
@ -165,27 +169,27 @@ bool textHandleUndo(BufferView * bv, Undo & undo)
// We enter here on DELETE undo operations where we // We enter here on DELETE undo operations where we
// have to substitue the second paragraph with the // have to substitue the second paragraph with the
// first if the removed one is the first. // first if the removed one is the first.
if (!before && behind) { if (before == end && behind != end) {
int id = undoParagraphs(bv, undo.number_of_inset_id).front().id(); int id = undoParagraphs(bv, undo.number_of_inset_id).front().id();
Paragraph * op = &*bv->buffer()->getParFromID(id); ParIterator op = bv->buffer()->getParFromID(id);
if (op && op->inInset()) { if (op != end && op->inInset()) {
static_cast<InsetText*>(op->inInset())->paragraph(behind); static_cast<InsetText*>(op->inInset())->paragraph(&**behind);
} else { } else {
bv->buffer()->paragraphs.set(behind); bv->buffer()->paragraphs.set(&**behind);
} }
undopar = behind; undopar = &**behind;
} }
} }
// Set the cursor for redoing. // Set the cursor for redoing.
// If we have a par before the undopar. // If we have a par before the undopar.
if (before) { if (before != end) {
Inset * it = before->inInset(); Inset * it = before->inInset();
if (it) if (it)
it->getLyXText(bv)->setCursorIntern(before, 0); it->getLyXText(bv)->setCursorIntern(*before, 0);
else else
bv->text->setCursorIntern(before, 0); bv->text->setCursorIntern(*before, 0);
} }
// we are not ready for this we cannot set the cursor for a paragraph // we are not ready for this we cannot set the cursor for a paragraph
@ -200,24 +204,28 @@ bool textHandleUndo(BufferView * bv, Undo & undo)
} }
#endif #endif
Paragraph * endpar = 0;
// Calculate the endpar for redoing the paragraphs.
if (behind)
endpar = behind->next();
UpdatableInset * it = 0; UpdatableInset * it = 0;
if (undopar) if (undopar)
it = static_cast<UpdatableInset*>(undopar->inInset()); it = static_cast<UpdatableInset*>(undopar->inInset());
LyXText * text = it ? it->getLyXText(bv) : bv->text;
ParagraphList::iterator endpar = text->ownerParagraphs().end();
// Calculate the endpar for redoing the paragraphs.
if (behind != end) {
endpar = *behind;
++endpar;
}
text->redoParagraphs(text->cursor, endpar);
ParIterator tmppar =
bv->buffer()->getParFromID(undo.number_of_cursor_par);
if (it) { if (it) {
it->getLyXText(bv)->redoParagraphs( if (tmppar != end) {
it->getLyXText(bv)->cursor,
endpar);
Paragraph * tmppar =
&*bv->buffer()->getParFromID(undo.number_of_cursor_par);
if (tmppar) {
it = static_cast<UpdatableInset*>(tmppar->inInset());
LyXText * t; LyXText * t;
Inset * it = tmppar->inInset();
if (it) { if (it) {
FuncRequest cmd(bv, LFUN_INSET_EDIT, "left"); FuncRequest cmd(bv, LFUN_INSET_EDIT, "left");
it->localDispatch(cmd); it->localDispatch(cmd);
@ -225,7 +233,7 @@ bool textHandleUndo(BufferView * bv, Undo & undo)
} else { } else {
t = bv->text; t = bv->text;
} }
t->setCursorIntern(tmppar, undo.cursor_pos); t->setCursorIntern(*tmppar, undo.cursor_pos);
// Clear any selection and set the selection // Clear any selection and set the selection
// cursor for an evt. new selection. // cursor for an evt. new selection.
t->clearSelection(); t->clearSelection();
@ -237,10 +245,7 @@ bool textHandleUndo(BufferView * bv, Undo & undo)
bv->text->setCursorIntern(bv->text->cursor.par(), bv->text->setCursorIntern(bv->text->cursor.par(),
bv->text->cursor.pos()); bv->text->cursor.pos());
} else { } else {
bv->text->redoParagraphs(bv->text->cursor, endpar); if (tmppar != end) {
Paragraph * tmppar =
&*bv->buffer()->getParFromID(undo.number_of_cursor_par);
if (tmppar) {
LyXText * t; LyXText * t;
Inset * it = tmppar->inInset(); Inset * it = tmppar->inInset();
if (it) { if (it) {
@ -250,7 +255,7 @@ bool textHandleUndo(BufferView * bv, Undo & undo)
} else { } else {
t = bv->text; t = bv->text;
} }
t->setCursorIntern(tmppar, undo.cursor_pos); t->setCursorIntern(*tmppar, undo.cursor_pos);
// Clear any selection and set the selection // Clear any selection and set the selection
// cursor for an evt. new selection. // cursor for an evt. new selection.
t->clearSelection(); t->clearSelection();
@ -381,17 +386,25 @@ bool textUndoOrRedo(BufferView * bv,
finishUndo(); finishUndo();
if (!undo_frozen) { if (!undo_frozen) {
Paragraph * first = &*b->getParFromID(undo->number_of_before_par); /*
if (first && first->next()) ParIterator p = b->getParFromID(undo->number_of_before_par);
bool ok = false;
ParagraphList::iterator first;
// default constructed?
ParIterator const end = b->par_iterator_end();
if (p != end) {
first = p.par();
if (first->next())
first = first->next(); first = first->next();
else if (!first) } else
first = &*undoParagraphs(bv, undo->number_of_inset_id).begin(); first = undoParagraphs(bv, undo->number_of_inset_id).begin();
if (first) { if (first) {
shared_ptr<Undo> u; shared_ptr<Undo> u;
if (createUndo(bv, undo->kind, first, ParIterator behind = b->getParFromID(undo->number_of_behind_par);
b->getParFromID(undo->number_of_behind_par), u)) if (createUndo(bv, undo->kind, first, behind.par(), u))
otherstack.push(u); otherstack.push(u);
} }
*/
} }
// Now we can unlock the inset for saftey because the inset // Now we can unlock the inset for saftey because the inset