mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-26 11:16:55 +00:00
Paragraph iterators
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2649 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
7c9de3222e
commit
0233b6753d
@ -32,6 +32,7 @@
|
|||||||
#include "gettext.h"
|
#include "gettext.h"
|
||||||
#include "undo_funcs.h"
|
#include "undo_funcs.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
#include "iterators.h"
|
||||||
|
|
||||||
extern BufferList bufferlist;
|
extern BufferList bufferlist;
|
||||||
|
|
||||||
@ -494,18 +495,20 @@ bool BufferView::ChangeInsets(Inset::Code code,
|
|||||||
string const & from, string const & to)
|
string const & from, string const & to)
|
||||||
{
|
{
|
||||||
bool flag = false;
|
bool flag = false;
|
||||||
Paragraph * par = buffer()->paragraph;
|
|
||||||
LyXCursor cursor = text->cursor;
|
LyXCursor cursor = text->cursor;
|
||||||
LyXCursor tmpcursor = cursor;
|
LyXCursor tmpcursor = cursor;
|
||||||
cursor.par(tmpcursor.par());
|
cursor.par(tmpcursor.par());
|
||||||
cursor.pos(tmpcursor.pos());
|
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;
|
bool flag2 = false;
|
||||||
for (Paragraph::inset_iterator it = par->inset_iterator_begin();
|
for (Paragraph::inset_iterator it2 = par->inset_iterator_begin();
|
||||||
it != par->inset_iterator_end(); ++it) {
|
it2 != par->inset_iterator_end(); ++it2) {
|
||||||
if ((*it)->lyxCode() == code) {
|
if ((*it2)->lyxCode() == code) {
|
||||||
InsetCommand * inset = static_cast<InsetCommand *>(*it);
|
InsetCommand * inset = static_cast<InsetCommand *>(*it2);
|
||||||
if (inset->getContents() == from) {
|
if (inset->getContents() == from) {
|
||||||
inset->setContents(to);
|
inset->setContents(to);
|
||||||
flag2 = true;
|
flag2 = true;
|
||||||
@ -514,14 +517,16 @@ bool BufferView::ChangeInsets(Inset::Code code,
|
|||||||
}
|
}
|
||||||
if (flag2) {
|
if (flag2) {
|
||||||
flag = true;
|
flag = true;
|
||||||
// this is possible now, since SetCursor takes
|
#warning Fix me
|
||||||
// care about footnotes
|
// The test it.size()==1 was needed to prevent crashes.
|
||||||
text->setCursorIntern(this, par, 0);
|
// How to set the cursor corretly when it.size()>1 ??
|
||||||
text->redoParagraphs(this, text->cursor,
|
if (it.size() == 1) {
|
||||||
text->cursor.par()->next());
|
text->setCursorIntern(this, par, 0);
|
||||||
text->fullRebreak(this);
|
text->redoParagraphs(this, text->cursor,
|
||||||
|
text->cursor.par()->next());
|
||||||
|
text->fullRebreak(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
par = par->next();
|
|
||||||
}
|
}
|
||||||
text->setCursorIntern(this, cursor.par(), cursor.pos());
|
text->setCursorIntern(this, cursor.par(), cursor.pos());
|
||||||
return flag;
|
return flag;
|
||||||
|
@ -1,3 +1,12 @@
|
|||||||
|
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>
|
2001-09-01 Dekel Tsur <dekelts@tau.ac.il>
|
||||||
|
|
||||||
* FontLoader.C: Support for cmr font.
|
* FontLoader.C: Support for cmr font.
|
||||||
|
@ -124,6 +124,8 @@ lyx_SOURCES = \
|
|||||||
importer.h \
|
importer.h \
|
||||||
intl.C \
|
intl.C \
|
||||||
intl.h \
|
intl.h \
|
||||||
|
iterators.C \
|
||||||
|
iterators.h \
|
||||||
kbmap.C \
|
kbmap.C \
|
||||||
kbmap.h \
|
kbmap.h \
|
||||||
kbsequence.C \
|
kbsequence.C \
|
||||||
|
30
src/buffer.C
30
src/buffer.C
@ -107,6 +107,7 @@
|
|||||||
#include "converter.h"
|
#include "converter.h"
|
||||||
#include "BufferView.h"
|
#include "BufferView.h"
|
||||||
#include "ParagraphParameters.h"
|
#include "ParagraphParameters.h"
|
||||||
|
#include "iterators.h"
|
||||||
|
|
||||||
using std::ostream;
|
using std::ostream;
|
||||||
using std::ofstream;
|
using std::ofstream;
|
||||||
@ -3755,22 +3756,19 @@ void Buffer::redraw()
|
|||||||
void Buffer::changeLanguage(Language const * from, Language const * to)
|
void Buffer::changeLanguage(Language const * from, Language const * to)
|
||||||
{
|
{
|
||||||
|
|
||||||
Paragraph * par = paragraph;
|
ParIterator end = par_iterator_end();
|
||||||
while (par) {
|
for (ParIterator it = par_iterator_begin(); it != end; ++it)
|
||||||
par->changeLanguage(params, from, to);
|
(*it)->changeLanguage(params, from, to);
|
||||||
par = par->next();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Buffer::isMultiLingual()
|
bool Buffer::isMultiLingual()
|
||||||
{
|
{
|
||||||
Paragraph * par = paragraph;
|
ParIterator end = par_iterator_end();
|
||||||
while (par) {
|
for (ParIterator it = par_iterator_begin(); it != end; ++it)
|
||||||
if (par->isMultiLingual(params))
|
if ((*it)->isMultiLingual(params))
|
||||||
return true;
|
return true;
|
||||||
par = par->next();
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3831,3 +3829,15 @@ Paragraph * Buffer::getParFromID(int id) const
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ParIterator Buffer::par_iterator_begin()
|
||||||
|
{
|
||||||
|
return ParIterator(paragraph);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ParIterator Buffer::par_iterator_end()
|
||||||
|
{
|
||||||
|
return ParIterator();
|
||||||
|
}
|
||||||
|
@ -30,6 +30,7 @@ class LyXRC;
|
|||||||
class TeXErrors;
|
class TeXErrors;
|
||||||
class LaTeXFeatures;
|
class LaTeXFeatures;
|
||||||
class Language;
|
class Language;
|
||||||
|
class ParIterator;
|
||||||
|
|
||||||
// When lyx 1.3.x starts we should enable this
|
// When lyx 1.3.x starts we should enable this
|
||||||
// btw. we should also test this with 1.2 so that we
|
// btw. we should also test this with 1.2 so that we
|
||||||
@ -451,6 +452,12 @@ public:
|
|||||||
inset_iterator inset_const_iterator_end() const {
|
inset_iterator inset_const_iterator_end() const {
|
||||||
return inset_iterator();
|
return inset_iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
ParIterator par_iterator_begin();
|
||||||
|
///
|
||||||
|
ParIterator par_iterator_end();
|
||||||
|
|
||||||
///
|
///
|
||||||
Inset * getInsetFromID(int id_arg) const;
|
Inset * getInsetFromID(int id_arg) const;
|
||||||
};
|
};
|
||||||
@ -600,4 +607,5 @@ bool operator!=(Buffer::inset_iterator const & iter1,
|
|||||||
Buffer::inset_iterator const & iter2) {
|
Buffer::inset_iterator const & iter2) {
|
||||||
return !(iter1 == iter2);
|
return !(iter1 == iter2);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
2001-09-02 Dekel Tsur <dekelts@tau.ac.il>
|
||||||
|
|
||||||
|
* inset.h (getFirstParagraph): New virtual method.
|
||||||
|
|
||||||
2001-08-20 Herbert Voss <voss@perce.de>
|
2001-08-20 Herbert Voss <voss@perce.de>
|
||||||
* insetbib.C: added a option bibtotoc which is from "BIB to TOC"
|
* insetbib.C: added a option bibtotoc which is from "BIB to TOC"
|
||||||
in the the bibtex-database-gui for inserting a line
|
in the the bibtex-database-gui for inserting a line
|
||||||
|
@ -264,6 +264,12 @@ public:
|
|||||||
virtual Paragraph * firstParagraph() const {
|
virtual Paragraph * firstParagraph() const {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
virtual Paragraph * getFirstParagraph(int /*num*/) const {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/// return the cursor if we own one otherwise giv'em just the
|
/// return the cursor if we own one otherwise giv'em just the
|
||||||
/// BufferView cursor to work with.
|
/// BufferView cursor to work with.
|
||||||
virtual LyXCursor const & cursor(BufferView * bview) const;
|
virtual LyXCursor const & cursor(BufferView * bview) const;
|
||||||
|
@ -577,6 +577,12 @@ Paragraph * InsetCollapsable::firstParagraph() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Paragraph * InsetCollapsable::getFirstParagraph(int i) const
|
||||||
|
{
|
||||||
|
return inset.getFirstParagraph(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
LyXCursor const & InsetCollapsable::cursor(BufferView * bv) const
|
LyXCursor const & InsetCollapsable::cursor(BufferView * bv) const
|
||||||
{
|
{
|
||||||
return inset.cursor(bv);
|
return inset.cursor(bv);
|
||||||
|
@ -165,6 +165,8 @@ public:
|
|||||||
///
|
///
|
||||||
Paragraph * firstParagraph() const;
|
Paragraph * firstParagraph() const;
|
||||||
///
|
///
|
||||||
|
Paragraph * getFirstParagraph(int) const;
|
||||||
|
///
|
||||||
LyXCursor const & cursor(BufferView *) const;
|
LyXCursor const & cursor(BufferView *) const;
|
||||||
///
|
///
|
||||||
bool isOpen() const { return !collapsed_; }
|
bool isOpen() const { return !collapsed_; }
|
||||||
|
@ -2458,6 +2458,14 @@ Paragraph * InsetTabular::firstParagraph() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Paragraph * InsetTabular::getFirstParagraph(int i) const
|
||||||
|
{
|
||||||
|
return (i < tabular->GetNumberOfCells())
|
||||||
|
? tabular->GetCellInset(i)->getFirstParagraph(0)
|
||||||
|
: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
LyXCursor const & InsetTabular::cursor(BufferView * bv) const
|
LyXCursor const & InsetTabular::cursor(BufferView * bv) const
|
||||||
{
|
{
|
||||||
if (the_locking_inset)
|
if (the_locking_inset)
|
||||||
|
@ -208,6 +208,8 @@ public:
|
|||||||
///
|
///
|
||||||
Paragraph * firstParagraph() const;
|
Paragraph * firstParagraph() const;
|
||||||
///
|
///
|
||||||
|
Paragraph * getFirstParagraph(int) const;
|
||||||
|
///
|
||||||
LyXCursor const & cursor(BufferView *) const;
|
LyXCursor const & cursor(BufferView *) const;
|
||||||
///
|
///
|
||||||
string const selectNextWord(BufferView *, float & value) const;
|
string const selectNextWord(BufferView *, float & value) const;
|
||||||
|
@ -2122,6 +2122,12 @@ Paragraph * InsetText::firstParagraph() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Paragraph * InsetText::getFirstParagraph(int i) const
|
||||||
|
{
|
||||||
|
return (i == 0) ? par : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
LyXCursor const & InsetText::cursor(BufferView * bv) const
|
LyXCursor const & InsetText::cursor(BufferView * bv) const
|
||||||
{
|
{
|
||||||
if (the_locking_inset)
|
if (the_locking_inset)
|
||||||
|
@ -221,6 +221,8 @@ public:
|
|||||||
///
|
///
|
||||||
Paragraph * firstParagraph() const;
|
Paragraph * firstParagraph() const;
|
||||||
///
|
///
|
||||||
|
Paragraph * getFirstParagraph(int) const;
|
||||||
|
///
|
||||||
LyXCursor const & cursor(BufferView *) const;
|
LyXCursor const & cursor(BufferView *) const;
|
||||||
///
|
///
|
||||||
Paragraph * paragraph() const;
|
Paragraph * paragraph() const;
|
||||||
|
39
src/iterators.C
Normal file
39
src/iterators.C
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
#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;
|
||||||
|
}
|
72
src/iterators.h
Normal file
72
src/iterators.h
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
// -*- 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
|
Loading…
Reference in New Issue
Block a user