* \author unknown
* \author Lars Gullik Bjønnes
*
- * Full author contact details are available in file CREDITS
+ * Full author contact details are available in file CREDITS.
*/
#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>
-// it's conceptionally a stack, but undo needs random access...
-//#include <stack>
-#include <vector>
-
using boost::next;
using boost::optional;
using std::vector;
ParPosition::ParPosition(ParagraphList::iterator p, ParagraphList const & pl)
: pit(p), plist(&pl)
{
- if (p != pl.end()) {
+ if (p != const_cast<ParagraphList&>(pl).end()) {
it.reset(p->insetlist.begin());
}
}
}
// Try to go to the next paragarph
- if (next(p.pit) != p.plist->end()
+ if (next(p.pit) != const_cast<ParagraphList*>(p.plist)->end()
|| pimpl_->positions.size() == 1) {
++p.pit;
p.index.reset();
}
+LyXText * ParIterator::text() const
+{
+ //lyxerr << "positions.size: " << pimpl_->positions.size() << std::endl;
+ if (pimpl_->positions.size() <= 1)
+ return 0;
+
+ ParPosition const & pos = pimpl_->positions[pimpl_->positions.size() - 2];
+ return (*pos.it)->inset->getText(*pos.index);
+}
+
+
+InsetOld * ParIterator::inset() const
+{
+ //lyxerr << "positions.size: " << pimpl_->positions.size() << std::endl;
+ if (pimpl_->positions.size() <= 1)
+ return 0;
+
+ ParPosition const & pos = pimpl_->positions[pimpl_->positions.size() - 2];
+ return (*pos.it)->inset;
+}
+
+
+int ParIterator::index() const
+{
+ if (pimpl_->positions.size() <= 1)
+ return 0;
+
+ return *(pimpl_->positions[pimpl_->positions.size() - 2].index);
+}
+
+
+void ParIterator::asCursor(Cursor & cursor) const
+{
+ cursor.data_.clear();
+ for (size_t i = 1, n = size(); i < n; ++i) {
+ ParPosition const & pos = pimpl_->positions[i - 1];
+ CursorItem item;
+ item.inset_ = (*pos.it)->inset;
+ item.idx_ = (*pos.index);
+ item.text_ = (*pos.it)->inset->getText(*pos.index);
+ item.par_ = 0;
+ item.pos_ = 0;
+ cursor.data_.push_back(item);
+ }
+}
+
+
Paragraph & ParIterator::operator*() const
{
return *pimpl_->positions.back().pit;
}
// Try to go to the next paragarph
- if (next(p.pit) != p.plist->end()
+ if (next(p.pit) != const_cast<ParagraphList*>(p.plist)->end()
|| pimpl_->positions.size() == 1) {
++p.pit;
p.index.reset();
}
+ParagraphList const & ParConstIterator::plist() const
+{
+ return *pimpl_->positions.back().plist;
+}
+
+
size_t ParConstIterator::size() const
{
return pimpl_->positions.size();
{
return !(iter1 == iter2);
}
+
+
+PosIterator ParIterator::asPosIterator(lyx::pos_type pos) const
+{
+ PosIterator p;
+
+ int const last = size() - 1;
+ for (int i = 0; i < last; ++i) {
+ ParPosition & pp = pimpl_->positions[i];
+ p.stack_.push(PosIteratorItem(const_cast<ParagraphList *>(pp.plist), pp.pit, (*pp.it)->pos, *pp.index + 1));
+ }
+ ParPosition const & pp = pimpl_->positions[last];
+ p.stack_.push(PosIteratorItem(const_cast<ParagraphList *>(pp.plist),
+ pp.pit, pos, 0));
+ return p;
+}
+
+
+void ParIterator::lockPath(BufferView * bv) const
+{
+ bv->insetUnlock();
+ int last = size() - 1;
+ for (int i = 0; i < last; ++i) {
+ UpdatableInset * outer = dynamic_cast<UpdatableInset *>((*pimpl_->positions[i].it)->inset);
+ FuncRequest cmd(bv, LFUN_INSET_EDIT);
+ outer->dispatch(cmd);
+ LyXText * txt = outer->getText(*pimpl_->positions[i].index);
+ InsetText * inner = txt->inset_owner;
+ // deep vodoo magic: on a table, the edit call locks the first
+ // cell and further lock calls get lost there.
+ // We have to unlock it to then lock the correct one.
+ if (outer != inner) {
+ outer->insetUnlock(bv);
+ outer->lockInsetInInset(bv, inner);
+ inner->dispatch(FuncRequest(bv, LFUN_INSET_EDIT));
+ }
+ }
+}