/// We also have a map from the positions where Buffers are included
/// to those Buffers and their scope (whose point RKH does not yet
/// understand).
- // FIXME Surely one of these is enough?
+ // FIXME Surely one of these is enough? The difference is that
+ // children_positions has one entry for each child Buffer, whereas
+ // position_to_children has one entry for each InsetInclude (and the
+ // same Buffer could be included twice).
struct ScopeBuffer {
ScopeBuffer() = default;
ScopeBuffer(DocIterator const & s, Buffer const * b)
return;
Buffer * buffer_clone = new Buffer(fileName().absFileName(), false, this);
+ if (!buffer_clone) {
+ LYXERR0("Buffer creation failed!");
+ LBUFERR(false);
+ }
// The clone needs its own DocumentClass, since running updateBuffer() will
// modify it, and we would otherwise be sharing it with the original Buffer.
buffer_clone->d->macro_lock = true;
buffer_clone->d->children_positions.clear();
- // FIXME (Abdel 09/01/2010): this is too complicated. The whole children_positions and
- // math macro caches need to be rethought and simplified.
- // I am not sure wether we should handle Buffer cloning here or in BufferList.
- // Right now BufferList knows nothing about buffer clones.
+ // clone the children and update the information in the InsetIncludes
for (auto const & p : d->position_to_children) {
- DocIterator dit = p.first.clone(buffer_clone);
+ // location of child in old Buffer
+ DocIterator const & olddit = p.first;
+ // a DocIterator that points to the same location in this new Buffer
+ DocIterator dit = olddit.clone(buffer_clone);
dit.setBuffer(buffer_clone);
+ // the child in the old Buffer
Buffer * child = const_cast<Buffer *>(p.second.buffer);
-
+ // clone the child
child->cloneWithChildren(bufmap, clones);
+ // we now need to find the child we just created (or the previously
+ // created one, if it was already cloned).
BufferMap::iterator const bit = bufmap.find(child);
LASSERT(bit != bufmap.end(), continue);
Buffer * child_clone = bit->second;
+ // the Buffer for this include inset is now the cloned child
Inset * inset = dit.nextInset();
LASSERT(inset && inset->lyxCode() == INCLUDE_CODE, continue);
InsetInclude * inset_inc = static_cast<InsetInclude *>(inset);
inset_inc->setChildBuffer(child_clone);
+ // set us as its parent
child_clone->d->setParent(buffer_clone);
// FIXME Do we need to do this now, or can we wait until we run updateMacros()?
- buffer_clone->setChild(dit, child_clone);
+ d->children_positions[child_clone] = dit;
}
buffer_clone->d->macro_lock = false;
}
}
-void Buffer::setChild(DocIterator const & dit, Buffer * child)
-{
- d->children_positions[child] = dit;
-}
-
-
string Buffer::latexName(bool const no_path) const
{
FileName latex_name =
double fontScalingFactor() const;
private:
- ///
+ /// map from Buffers to their clones
typedef std::map<Buffer const *, Buffer *> BufferMap;
///
void cloneWithChildren(BufferMap &, CloneList_ptr) const;
/// This function is called when the buffer is changed.
void changed(bool update_metrics) const;
///
- void setChild(DocIterator const & dit, Buffer * child);
- ///
void updateTocItem(std::string const &, DocIterator const &) const;
/// This function is called when the buffer structure is changed.
void structureChanged() const;