Lars Gullik BjÃnnes wrote: > Can we begin by just applying the PosIterator files? > (makes further patches easier to digest)
I need this lockPath to make all the locking dirty work, and will die with the locking stuff. Would an ugly change like this to iterators.[Ch] be accepted? (including PosIterator friendship in ParIterator for constructors) If not, how do you suggest to replace it? Thanks, Alfredo
Index: iterators.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/iterators.C,v retrieving revision 1.23 diff -u -p -u -r1.23 iterators.C --- iterators.C 29 Oct 2003 12:18:06 -0000 1.23 +++ iterators.C 1 Nov 2003 18:48:25 -0000 @@ -13,9 +13,16 @@ #include "iterators.h" #include "paragraph.h" +#include "PosIterator.h" #include "cursor.h" +#include "BufferView.h" +#include "funcrequest.h" +#include "dispatchresult.h" + #include "insets/inset.h" +#include "insets/updatableinset.h" +#include "insets/insettext.h" #include <boost/next_prior.hpp> #include <boost/optional.hpp> @@ -355,4 +362,44 @@ bool operator==(ParConstIterator const & bool operator!=(ParConstIterator const & iter1, ParConstIterator const & iter2) { return !(iter1 == iter2); +} + + +PosIterator::PosIterator(ParIterator & parit, lyx::pos_type pos) +{ + int const last = parit.size() - 1; + for (int i = 0; i < last; ++i) { + ParPosition & pp = parit.pimpl_->positions[i]; + stack_.push(PosIteratorItem(const_cast<ParagraphList *>(pp.plist), + pp.pit, (*pp.it)->pos, *pp.index + 1)); + } + ParPosition const & pp = parit.pimpl_->positions[last]; + stack_.push(PosIteratorItem(const_cast<ParagraphList *>(pp.plist), + pp.pit, pos, 0)); +} + + +void ParIterator::lockPath(BufferView * bv) const +{ + bv->insetUnlock(); + int last = size() - 1; + for (int i = 0; i < last; ++i) { + UpdatableInset * inset = dynamic_cast<UpdatableInset *>((*pimpl_->positions[i].it)->inset); + FuncRequest cmd(bv, LFUN_INSET_EDIT); + inset->dispatch(cmd); + } + + LyXText * txt = text() ? text() : bv->text; + + UpdatableInset * outer = dynamic_cast<UpdatableInset *>(inset()); + InsetText * inner = txt->inset_owner; + + // deep vodoo magic: on a table, the edit call locks the first + // inset and further lock calls go into that one. + // We have to unlock it to then lock the correct one. + if (inner != inset()) { + outer->insetUnlock(bv); + outer->lockInsetInInset(bv, inner); + inner->dispatch(FuncRequest(bv, LFUN_INSET_EDIT)); + } } Index: iterators.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/iterators.h,v retrieving revision 1.19 diff -u -p -u -r1.19 iterators.h --- iterators.h 29 Oct 2003 12:18:06 -0000 1.19 +++ iterators.h 1 Nov 2003 18:48:25 -0000 @@ -19,6 +19,7 @@ class LyXText; class InsetOld; class Cursor; +class BufferView; class ParIterator { public: @@ -56,6 +57,11 @@ public: /// friend bool operator==(ParIterator const & iter1, ParIterator const & iter2); + /// + friend class PosIterator; + /// + void lockPath(BufferView *) const; + private: struct Pimpl; boost::scoped_ptr<Pimpl> pimpl_; @@ -93,6 +99,10 @@ public: friend bool operator==(ParConstIterator const & iter1, ParConstIterator const & iter2); + /// + friend class PosIterator; + /// + void lockPath(BufferView *) const; private: struct Pimpl; boost::scoped_ptr<Pimpl> pimpl_;