#include "gettext.h"
#include "undo_funcs.h"
#include "debug.h"
+#include "iterators.h"
extern BufferList bufferlist;
string const & from, string const & to)
{
bool flag = false;
- Paragraph * par = buffer()->paragraph;
LyXCursor cursor = text->cursor;
LyXCursor tmpcursor = cursor;
cursor.par(tmpcursor.par());
cursor.pos(tmpcursor.pos());
- while (par) {
+ ParIterator end = buffer()->par_iterator_end();
+ for (ParIterator it = buffer()->par_iterator_begin();
+ it != end; ++it) {
+ Paragraph * par = *it;
bool flag2 = false;
- for (Paragraph::inset_iterator it = par->inset_iterator_begin();
- it != par->inset_iterator_end(); ++it) {
- if ((*it)->lyxCode() == code) {
- InsetCommand * inset = static_cast<InsetCommand *>(*it);
+ for (Paragraph::inset_iterator it2 = par->inset_iterator_begin();
+ it2 != par->inset_iterator_end(); ++it2) {
+ if ((*it2)->lyxCode() == code) {
+ InsetCommand * inset = static_cast<InsetCommand *>(*it2);
if (inset->getContents() == from) {
inset->setContents(to);
flag2 = true;
}
if (flag2) {
flag = true;
- // this is possible now, since SetCursor takes
- // care about footnotes
- text->setCursorIntern(this, par, 0);
- text->redoParagraphs(this, text->cursor,
- text->cursor.par()->next());
- text->fullRebreak(this);
+#warning Fix me
+ // The test it.size()==1 was needed to prevent crashes.
+ // How to set the cursor corretly when it.size()>1 ??
+ if (it.size() == 1) {
+ text->setCursorIntern(this, par, 0);
+ text->redoParagraphs(this, text->cursor,
+ text->cursor.par()->next());
+ text->fullRebreak(this);
+ }
}
- par = par->next();
}
text->setCursorIntern(this, cursor.par(), cursor.pos());
return flag;
+2001-09-02 Dekel Tsur <dekelts@tau.ac.il>
+
+ * iterators.[Ch]: New files. Provide paragraph iterators.
+
+ * buffer.C (changeLanguage): Use paragraph iterators.
+ (isMultiLingual): ditto
+
+ * BufferView2.C (ChangeInsets): Use paragraph iterators.
+
2001-09-01 Dekel Tsur <dekelts@tau.ac.il>
* FontLoader.C: Support for cmr font.
importer.h \
intl.C \
intl.h \
+ iterators.C \
+ iterators.h \
kbmap.C \
kbmap.h \
kbsequence.C \
#include "converter.h"
#include "BufferView.h"
#include "ParagraphParameters.h"
+#include "iterators.h"
using std::ostream;
using std::ofstream;
void Buffer::changeLanguage(Language const * from, Language const * to)
{
- Paragraph * par = paragraph;
- while (par) {
- par->changeLanguage(params, from, to);
- par = par->next();
- }
+ ParIterator end = par_iterator_end();
+ for (ParIterator it = par_iterator_begin(); it != end; ++it)
+ (*it)->changeLanguage(params, from, to);
}
bool Buffer::isMultiLingual()
{
- Paragraph * par = paragraph;
- while (par) {
- if (par->isMultiLingual(params))
+ ParIterator end = par_iterator_end();
+ for (ParIterator it = par_iterator_begin(); it != end; ++it)
+ if ((*it)->isMultiLingual(params))
return true;
- par = par->next();
- }
+
return false;
}
}
return 0;
}
+
+
+ParIterator Buffer::par_iterator_begin()
+{
+ return ParIterator(paragraph);
+}
+
+
+ParIterator Buffer::par_iterator_end()
+{
+ return ParIterator();
+}
class TeXErrors;
class LaTeXFeatures;
class Language;
+class ParIterator;
// When lyx 1.3.x starts we should enable this
// btw. we should also test this with 1.2 so that we
inset_iterator inset_const_iterator_end() const {
return inset_iterator();
}
+
+ ///
+ ParIterator par_iterator_begin();
+ ///
+ ParIterator par_iterator_end();
+
///
Inset * getInsetFromID(int id_arg) const;
};
Buffer::inset_iterator const & iter2) {
return !(iter1 == iter2);
}
+
#endif
+2001-09-02 Dekel Tsur <dekelts@tau.ac.il>
+
+ * inset.h (getFirstParagraph): New virtual method.
+
2001-08-20 Herbert Voss <voss@perce.de>
* insetbib.C: added a option bibtotoc which is from "BIB to TOC"
in the the bibtex-database-gui for inserting a line
virtual Paragraph * firstParagraph() const {
return 0;
}
+
+ ///
+ virtual Paragraph * getFirstParagraph(int /*num*/) const {
+ return 0;
+ }
+
/// return the cursor if we own one otherwise giv'em just the
/// BufferView cursor to work with.
virtual LyXCursor const & cursor(BufferView * bview) const;
}
+Paragraph * InsetCollapsable::getFirstParagraph(int i) const
+{
+ return inset.getFirstParagraph(i);
+}
+
+
LyXCursor const & InsetCollapsable::cursor(BufferView * bv) const
{
return inset.cursor(bv);
///
Paragraph * firstParagraph() const;
///
+ Paragraph * getFirstParagraph(int) const;
+ ///
LyXCursor const & cursor(BufferView *) const;
///
bool isOpen() const { return !collapsed_; }
}
+Paragraph * InsetTabular::getFirstParagraph(int i) const
+{
+ return (i < tabular->GetNumberOfCells())
+ ? tabular->GetCellInset(i)->getFirstParagraph(0)
+ : 0;
+}
+
+
LyXCursor const & InsetTabular::cursor(BufferView * bv) const
{
if (the_locking_inset)
///
Paragraph * firstParagraph() const;
///
+ Paragraph * getFirstParagraph(int) const;
+ ///
LyXCursor const & cursor(BufferView *) const;
///
string const selectNextWord(BufferView *, float & value) const;
}
+Paragraph * InsetText::getFirstParagraph(int i) const
+{
+ return (i == 0) ? par : 0;
+}
+
+
LyXCursor const & InsetText::cursor(BufferView * bv) const
{
if (the_locking_inset)
///
Paragraph * firstParagraph() const;
///
+ Paragraph * getFirstParagraph(int) const;
+ ///
LyXCursor const & cursor(BufferView *) const;
///
Paragraph * paragraph() const;
--- /dev/null
+#include <config.h>
+
+#include "iterators.h"
+
+ParIterator & ParIterator::operator++()
+{
+ while (!positions.empty()) {
+ ParPosition & p = positions.back();
+
+ // Does the current inset contain more "cells" ?
+ if (p.index >= 0) {
+ ++p.index;
+ Paragraph * par = (*p.it)->getFirstParagraph(p.index);
+ if (par) {
+ positions.push_back(ParPosition(par));
+ return *this;
+ }
+ ++p.it;
+ }
+
+ // Try to find the next inset that contains paragraphs
+ for ( ; p.it != p.par->inset_iterator_end(); ++p.it) {
+ Paragraph * par = (*p.it)->getFirstParagraph(0);
+ if (par) {
+ p.index = 0;
+ positions.push_back(ParPosition(par));
+ return *this;
+ }
+ }
+ // Try to go to the next paragarph
+ if (p.par->next()) {
+ p = ParPosition(p.par->next());
+ return *this;
+ }
+
+ positions.pop_back();
+ }
+ return *this;
+}
--- /dev/null
+// -*- C++ -*-
+
+#ifndef ITERATORS_H
+#define ITERATORS_H
+
+#include <vector>
+
+#include "paragraph.h"
+
+class ParPosition {
+public:
+ ParPosition(Paragraph * p)
+ : par(p), it(p->inset_iterator_begin()), index(-1) {}
+ ///
+ Paragraph * par;
+ ///
+ Paragraph::inset_iterator it;
+ ///
+ int index;
+};
+
+
+inline
+bool operator==(ParPosition const & pos1, ParPosition const & pos2) {
+ return pos1.par == pos2.par &&
+ pos1.it == pos2.it &&
+ pos1.index == pos2.index;
+}
+
+inline
+bool operator!=(ParPosition const & pos1, ParPosition const & pos2) {
+ return !(pos1 == pos2);
+}
+
+
+class ParIterator {
+public:
+ ///
+ ParIterator() {}
+ //
+ ParIterator(Paragraph * par)
+ : positions(1, ParPosition(par)) {}
+ ///
+ ParIterator & operator++();
+ ///
+ Paragraph * operator*() { return positions.back().par; }
+ ///
+ vector<ParPosition>::size_type size() const
+ { return positions.size(); }
+ ///
+ friend
+ bool operator==(ParIterator const & iter1, ParIterator const & iter2);
+private:
+ ///
+ std::vector<ParPosition> positions;
+};
+
+
+///
+inline
+bool operator==(ParIterator const & iter1, ParIterator const & iter2) {
+ return iter1.positions == iter2.positions;
+}
+
+
+///
+inline
+bool operator!=(ParIterator const & iter1, ParIterator const & iter2) {
+ return !(iter1 == iter2);
+}
+
+#endif