This patch solves this crash (due to an assertion):

1) Open EmbeddedObject.lyx
2) Open Toc
3) Click on section 7.2.2 which is in the second child document
4) assertion.

This commit adds proper support for multi-part documents. With this each child document has access to the _full_ TOC tree (including LOT and LOF). This enables to switch between master and child document using the TOC.

* buffer_funcs.cpp:
  - updateLabels(): do not emit Buffer::structureChanged() signal for child document
  - checkBufferStructure(): update the structure of the master document.

* ControlToc.cpp: always use the TocBackend of the master document.

* LyXView::connectBuffer(): connect structureChanged() of master document.

* TocBackend:
  - TocItem: get rid of child_ member.
  - TocBackend::item(): only compare items from the same document.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18386 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2007-05-17 19:19:37 +00:00
parent f827bcd96e
commit 9092bffc32
5 changed files with 26 additions and 23 deletions

View File

@ -37,8 +37,8 @@ using std::string;
// TocItem implementation
TocItem::TocItem(ParConstIterator const & par_it, int d,
docstring const & s, bool child)
: par_it_(par_it), depth_(d), str_(s), child_(child)
docstring const & s)
: par_it_(par_it), depth_(d), str_(s)
{
/*
if (!uid_.empty())
@ -170,9 +170,6 @@ void TocBackend::update()
BufferParams const & bufparams = buffer_->params();
const int min_toclevel = bufparams.getTextClass().min_toclevel();
// Is this a child document?
bool const child_document = buffer_->getMasterBuffer() != buffer_;
Toc & toc = tocs_["tableofcontents"];
ParConstIterator pit = buffer_->par_iterator_begin();
ParConstIterator end = buffer_->par_iterator_end();
@ -212,14 +209,14 @@ void TocBackend::update()
if (tocstring.empty())
tocstring = pit->asString(*buffer_, true);
toc.push_back(TocItem(pit, toclevel - min_toclevel,
tocstring, child_document));
tocstring));
}
}
}
TocIterator const TocBackend::item(
std::string const & type, ParConstIterator const & par_it) const
TocIterator const TocBackend::item(std::string const & type,
ParConstIterator const & par_it) const
{
TocList::const_iterator toclist_it = tocs_.find(type);
// Is the type supported?
@ -242,7 +239,10 @@ TocIterator const TocBackend::item(
par_it_text.backwardPos();
for (; it != last; --it) {
if (it->child_)
// We verify that we don't compare contents of two
// different document. This happens when you
// have parent and child documents.
if (&it->par_it_[0].inset() != &par_it_text[0].inset())
continue;
if (it->par_it_ <= par_it_text)
return it;

View File

@ -41,8 +41,7 @@ public:
///
TocItem(ParConstIterator const & par_it = ParConstIterator(),
int d = -1,
docstring const & s = docstring(),
bool child = false
docstring const & s = docstring()
);
///
~TocItem() {}
@ -69,9 +68,6 @@ protected:
/// Full item string
docstring str_;
/// Set to true if the item comes from a child document.
bool child_;
};
@ -110,7 +106,10 @@ public:
///
Toc const & toc(std::string const & type) const;
/// Return the first Toc Item before the cursor
TocIterator const item(std::string const & type, ParConstIterator const &) const;
TocIterator const item(
std::string const & type, ///< Type of Toc.
ParConstIterator const & ///< The cursor location in the document.
) const;
void writePlaintextTocList(std::string const & type, odocstream & os) const;

View File

@ -698,7 +698,8 @@ void updateLabels(Buffer const & buf, bool childonly)
Buffer & cbuf = const_cast<Buffer &>(buf);
cbuf.tocBackend().update();
cbuf.structureChanged();
if (!childonly)
cbuf.structureChanged();
}
@ -706,8 +707,9 @@ void checkBufferStructure(Buffer & buffer, ParIterator const & par_it)
{
if (par_it->layout()->labeltype == LABEL_COUNTER
&& par_it->layout()->toclevel != Layout::NOT_IN_TOC) {
buffer.tocBackend().updateItem(par_it);
buffer.structureChanged();
Buffer * master = buffer.getMasterBuffer();
master->tocBackend().updateItem(par_it);
master->structureChanged();
}
}

View File

@ -196,7 +196,7 @@ void LyXView::connectBuffer(Buffer & buf)
boost::bind(&WorkArea::redraw, work_area_));
bufferStructureChangedConnection_ =
buf.structureChanged.connect(
buf.getMasterBuffer()->structureChanged.connect(
boost::bind(&LyXView::updateToc, this));
errorsConnection_ =

View File

@ -42,7 +42,7 @@ ControlToc::ControlToc(Dialog & d)
TocList const & ControlToc::tocs() const
{
return kernel().buffer().tocBackend().tocs();
return kernel().buffer().getMasterBuffer()->tocBackend().tocs();
}
@ -53,7 +53,8 @@ bool ControlToc::initialiseParams(string const & data)
types_.clear();
type_names_.clear();
TocList const & tocs = kernel().buffer().tocBackend().tocs();
TocList const & tocs = kernel().buffer().getMasterBuffer()->
tocBackend().tocs();
TocList::const_iterator it = tocs.begin();
TocList::const_iterator end = tocs.end();
for (; it != end; ++it) {
@ -116,7 +117,7 @@ void ControlToc::outlineOut()
void ControlToc::updateBackend()
{
kernel().buffer().tocBackend().update();
kernel().buffer().getMasterBuffer()->tocBackend().update();
kernel().buffer().structureChanged();
}
@ -125,7 +126,8 @@ TocIterator const ControlToc::getCurrentTocItem(size_t type) const
{
BOOST_ASSERT(kernel().bufferview());
ParConstIterator it(kernel().bufferview()->cursor());
return kernel().buffer().tocBackend().item(types_[type], it);
Buffer const * master = kernel().buffer().getMasterBuffer();
return master->tocBackend().item(types_[type], it);
}