Use paragraph iterators in CutAndPaste::SwitchLayoutsBetweenClasses

and in BufferView::removeAutoInsets


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3166 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Dekel Tsur 2001-12-07 18:40:24 +00:00
parent b317d8341c
commit 5702f22ef0
4 changed files with 40 additions and 20 deletions

View File

@ -102,23 +102,28 @@ bool BufferView::insertLyXFile(string const & filen)
bool BufferView::removeAutoInsets()
{
Paragraph * par = buffer()->paragraph;
LyXCursor tmpcursor = text->cursor;
LyXCursor cursor;
bool found = false;
bool a = false;
while (par) {
ParIterator end = buffer()->par_iterator_end();
for (ParIterator it = buffer()->par_iterator_begin();
it != end; ++it) {
Paragraph * par = *it;
// this has to be done before the delete
text->setCursor(this, cursor, par, 0);
if (par->autoDeleteInsets()){
a = true;
text->redoParagraphs(this, cursor,
cursor.par()->next());
text->fullRebreak(this);
if (par->autoDeleteInsets()) {
found = true;
#ifdef WITH_WARNINGS
#warning FIXME
#endif
// The test it.size()==1 was needed to prevent crashes.
if (it.size() == 1) {
text->setCursor(this, cursor, par, 0);
text->redoParagraphs(this, cursor,
cursor.par()->next());
text->fullRebreak(this);
}
}
par = par->next();
}
// avoid forbidden cursor positions caused by error removing
@ -127,7 +132,7 @@ bool BufferView::removeAutoInsets()
text->setCursorIntern(this, tmpcursor.par(), tmpcursor.pos());
return a;
return found;
}

View File

@ -1,3 +1,12 @@
2001-12-07 Dekel Tsur <dekelts@tau.ac.il>
* iterators.C (operator++): Make the iterator more robust
* BufferView2.C (removeAutoInsets): Use paragraph iterators
(John's patch)
* CutAndPaste.C (SwitchLayoutsBetweenClasses): Ditto
2001-12-05 John Levon <moz@compsoc.man.ac.uk>
* lyxtext.h:

View File

@ -17,6 +17,7 @@
#include "lyx_gui_misc.h"
#include "lyxcursor.h"
#include "gettext.h"
#include "iterators.h"
#ifdef __GNUG__
#pragma implementation
@ -366,16 +367,18 @@ int CutAndPaste::SwitchLayoutsBetweenClasses(textclass_type c1,
int ret = 0;
if (!par || c1 == c2)
return ret;
while (par) {
ParIterator end = ParIterator();
for (ParIterator it = ParIterator(par); it != end; ++it) {
par = *it;
string const name = textclasslist.NameOfLayout(c1, par->layout);
int lay = 0;
pair<bool, layout_type> pp =
textclasslist.NumberOfLayout(c2, name);
if (pp.first) {
lay = pp.second;
} else { // layout not found
// use default layout "Standard" (0)
} else {
// not found: use default layout "Standard" (0)
lay = 0;
}
par->layout = lay;
@ -391,7 +394,6 @@ int CutAndPaste::SwitchLayoutsBetweenClasses(textclass_type c1,
InsetError * new_inset = new InsetError(s);
par->insertInset(0, new_inset);
}
par = par->next();
}
return ret;
}

View File

@ -2,7 +2,7 @@
#include "iterators.h"
ParIterator & ParIterator::operator++()
ParIterator & ParIterator::operator++()
{
while (!positions.empty()) {
ParPosition & p = positions.back();
@ -16,7 +16,11 @@ ParIterator & ParIterator::operator++()
return *this;
}
++p.it;
}
} else
// The following line is needed because the value of
// p.it may be invalid if inset was added/removed to
// the paragraph pointed by the iterator
p.it = p.par->inset_iterator_begin();
// Try to find the next inset that contains paragraphs
for ( ; p.it != p.par->inset_iterator_end(); ++p.it) {