[LyX features/cleanup/updateMacros] More comments and minor code cleanup
Richard Kimberly Heck
rikiheck at lyx.org
Mon Nov 9 21:29:59 UTC 2020
The branch, cleanup/updateMacros, has been updated.
- Log -----------------------------------------------------------------
commit f273c676ee6d4338624e88b9cfaaa8cc3e3e22ad
Author: Richard Kimberly Heck <rikiheck at lyx.org>
Date: Mon Nov 9 16:59:04 2020 -0500
More comments and minor code cleanup
diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index 600d810..91602da 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -220,7 +220,10 @@ public:
/// 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)
@@ -614,6 +617,10 @@ void Buffer::cloneWithChildren(BufferMap & bufmap, CloneList_ptr clones) const
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.
@@ -629,27 +636,32 @@ void Buffer::cloneWithChildren(BufferMap & bufmap, CloneList_ptr clones) const
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;
}
@@ -795,12 +807,6 @@ 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 =
diff --git a/src/Buffer.h b/src/Buffer.h
index a917c6e..2dbc16c 100644
--- a/src/Buffer.h
+++ b/src/Buffer.h
@@ -223,7 +223,7 @@ public:
double fontScalingFactor() const;
private:
- ///
+ /// map from Buffers to their clones
typedef std::map<Buffer const *, Buffer *> BufferMap;
///
void cloneWithChildren(BufferMap &, CloneList_ptr) const;
@@ -648,8 +648,6 @@ 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;
-----------------------------------------------------------------------
Summary of changes:
src/Buffer.cpp | 34 ++++++++++++++++++++--------------
src/Buffer.h | 4 +---
2 files changed, 21 insertions(+), 17 deletions(-)
hooks/post-receive
--
Repository for new features
More information about the lyx-cvs
mailing list