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);
Paragraph * texrowpar;
ParagraphList::iterator texrowpar;
if (tmpid == -1) {
texrowpar = &*text->ownerParagraphs().begin();
texrowpar = text->ownerParagraphs().begin();
tmppos = 0;
} else {
texrowpar = &*buffer()->getParFromID(tmpid);
texrowpar = *buffer()->getParFromID(tmpid);
}
text->setCursor(texrowpar, tmppos);
}

View File

@ -642,12 +642,12 @@ void BufferView::Pimpl::restorePosition(unsigned int i)
if (b != 0) buffer(b);
}
Paragraph * par = &*buffer_->getParFromID(saved_positions[i].par_id);
if (!par)
ParIterator par = buffer_->getParFromID(saved_positions[i].par_id);
if (par == buffer_->par_iterator_end())
return;
bv_->text->setCursor(par,
min(par->size(), saved_positions[i].par_pos));
bv_->text->setCursor(*par,
min((*par)->size(), saved_positions[i].par_pos));
update(BufferView::SELECT);
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>
* 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)
ParIterator it(const_cast<Buffer*>(this)->par_iterator_begin());
@ -2213,18 +2213,14 @@ ParagraphList::iterator Buffer::getParFromID(int id) const
if (id < 0) {
// John says this is called with id == -1 from undo
lyxerr << "getParFromID(), id: " << id << endl;
return 0;
return end;
}
for (; it != end; ++it) {
// go on then, show me how to remove
// the cast
if ((*it)->id() == id) {
return *it;
}
}
for (; it != end; ++it)
if ((*it)->id() == id)
return it;
return 0;
return end;
}

View File

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

View File

@ -63,23 +63,23 @@ void ControlErrorList::goTo(int item)
if (err.par_id == -1)
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;
return;
}
int range = err.pos_end - err.pos_start;
if (err.pos_end > pit->size() || range <= 0)
range = pit->size() - err.pos_start;
if (err.pos_end > (*pit)->size() || range <= 0)
range = (*pit)->size() - err.pos_start;
// Now make the selection.
bv->insetUnlock();
bv->toggleSelection();
bv->text->clearSelection();
bv->text->setCursor(pit, err.pos_start);
bv->text->setCursor(*pit, err.pos_start);
bv->text->setSelectionRange(range);
bv->toggleSelection(false);
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;
}
ParagraphList::iterator ParIterator::operator->()
ParagraphList::iterator ParIterator::operator->() const
{
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;
}
ParagraphList::iterator ParConstIterator::operator->()
ParagraphList::iterator ParConstIterator::operator->() const
{
return pimpl_->positions.top().pit;
}

View File

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

View File

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

View File

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