Fix multipart document background compilation. I am not fully satisfied with this solution (see FIXME in Buffer::clone()). There might be some memory leaks...

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@32910 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2010-01-09 14:47:47 +00:00
parent ecc2b2f2e0
commit cda980db51
6 changed files with 67 additions and 3 deletions

View File

@ -380,9 +380,28 @@ Buffer::~Buffer()
Buffer * Buffer::clone() const
{
// FIXME for asynchronous export and preview: We must also clone all
// the child buffers!
return new Buffer(fileName().absFilename(), false, this);
Buffer * buffer_clone = new Buffer(fileName().absFilename(), false, this);
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.
Impl::BufferPositionMap::iterator it = d->children_positions.begin();
Impl::BufferPositionMap::iterator end = d->children_positions.end();
for (; it != end; ++it) {
DocIterator dit = it->second.clone(buffer_clone);
dit.setBuffer(buffer_clone);
Buffer * child = const_cast<Buffer *>(it->first);
Buffer * child_clone = child->clone();
Inset * inset = dit.nextInset();
LASSERT(inset && inset->lyxCode() == INCLUDE_CODE, continue);
InsetInclude * inset_inc = static_cast<InsetInclude *>(inset);
inset_inc->setChildBuffer(child_clone);
child_clone->d->setParent(buffer_clone);
buffer_clone->setChild(dit, child_clone);
}
return buffer_clone;
}
@ -484,6 +503,12 @@ Undo & Buffer::undo()
}
void Buffer::setChild(DocIterator const & dit, Buffer * child)
{
d->children_positions[child] = dit;
}
string Buffer::latexName(bool const no_path) const
{
FileName latex_name =

View File

@ -474,6 +474,8 @@ public:
/// 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;

View File

@ -72,6 +72,24 @@ DocIterator doc_iterator_end(const Buffer * buf0, const Inset * inset0)
}
DocIterator DocIterator::clone(Buffer * buffer) const
{
LASSERT(buffer->isClone(), return DocIterator());
Inset * inset = &buffer->inset();
DocIterator dit = *this;
dit.buffer_ = buffer;
dit.inset_ = inset;
size_t const n = slices_.size();
for (size_t i = 0 ; i != n; ++i) {
LASSERT(inset, /**/);
dit.top().inset_ = inset;
if (i + 1 != n)
inset = dit.nextInset();
}
return dit;
}
bool DocIterator::inRegexped() const
{
InsetMathHull * i = dynamic_cast<InsetMathHull *>(inset().asInsetMath());

View File

@ -51,6 +51,10 @@ public:
/// access to owning buffer
void setBuffer(Buffer * buf) { buffer_ = buf; }
/// Clone this for given \p buffer.
/// \p buffer must be a clone of buffer_.
DocIterator clone(Buffer * buffer) const;
/// access slice at position \p i
CursorSlice const & operator[](size_t i) const { return slices_[i]; }
/// access slice at position \p i

View File

@ -200,6 +200,12 @@ void InsetInclude::setBuffer(Buffer & buffer)
}
void InsetInclude::setChildBuffer(Buffer * buffer)
{
child_buffer_ = buffer;
}
ParamInfo const & InsetInclude::findInfo(string const & /* cmdName */)
{
// FIXME
@ -382,6 +388,11 @@ Buffer * InsetInclude::getChildBuffer() const
Buffer * InsetInclude::loadIfNeeded() const
{
// This is for background export and preview. We don't want to load the
// cloned child document again.
if (child_buffer_ && child_buffer_->isClone())
return child_buffer_;
// Don't try to load it again if we failed before.
if (failedtoload_ || isVerbatim(params()) || isListings(params()))
return 0;

View File

@ -50,6 +50,10 @@ public:
DisplayType display() const;
///
InsetCode lyxCode() const { return INCLUDE_CODE; }
///
void setChildBuffer(Buffer * buffer);
/** Fills \c keys
* \param buffer the Buffer containing this inset.
* \param keys the list of bibkeys in the child buffer.