Am Donnerstag, 9. November 2006 13:40 schrieb Abdelrazak Younes: > Georg Baum wrote: > > Abdelrazak Younes wrote: > > > >> Georg Baum wrote: > >>> This patch adds support for the esint package: > >> Georg, could you post an updated patch for the multi-document toc? > > > > I never had it in 1.5 so far. If you can tell me what happened to > > updateCounters() and where I can find the replacement code I can create a > > patch. > > updateLabels()
Thanks, here is the patch. In the 1.4 version I was able to make addToToc a virtual function of InsetBase, but in trunk that is not possible anymore because it would create a circular include dependency (insetbase.h -> toc.h -> pariterator.h -> ... -> insetbase.h). Navigating to a different buffer does not really work (LFUN_PARAGRAPH_GOTO in BufferView::dispatch). The buffer is found, but it seems that the setBuffer call does not work. This worked in 1.4 and has certainly something to do with the multiple views stuff, so it is probably easy for you to fix that. Georg
Index: src/buffer_funcs.h =================================================================== --- src/buffer_funcs.h (Revision 15835) +++ src/buffer_funcs.h (Arbeitskopie) @@ -58,17 +58,17 @@ lyx::docstring expandLabel(Buffer const /** A full updateLabels(Buffer const &) will be called if not possible. */ -void updateLabels(Buffer const & buf, ParIterator & it); +void updateLabels(Buffer const & buf, ParIterator & it, bool childonly = false); /// update labels between "from" and "to" if possible. /** A full updateLabels(Buffer const &) will be called if not possible. */ void updateLabels(Buffer const & buf, - ParIterator & from, ParIterator & to); + ParIterator & from, ParIterator & to, bool childonly = false); /// updates all counters -void updateLabels(Buffer const &); +void updateLabels(Buffer const &, bool childonly = false); } // namespace lyx Index: src/insets/insetinclude.h =================================================================== --- src/insets/insetinclude.h (Revision 15835) +++ src/insets/insetinclude.h (Arbeitskopie) @@ -17,6 +17,8 @@ #include "render_button.h" #include "mailinset.h" +#include "toc.h" + #include <boost/scoped_ptr.hpp> namespace lyx { @@ -92,6 +94,10 @@ public: /// void addPreview(graphics::PreviewLoader &) const; /// + void addToToc(toc::TocList &, Buffer const &) const; + /// + void updateLabels(Buffer const & buffer) const; + /// bool getStatus(LCursor &, FuncRequest const &, FuncStatus &) const; protected: InsetInclude(InsetInclude const &); Index: src/insets/insetinclude.C =================================================================== --- src/insets/insetinclude.C (Revision 15835) +++ src/insets/insetinclude.C (Arbeitskopie) @@ -772,6 +772,33 @@ void InsetInclude::addPreview(graphics:: } +void InsetInclude::addToToc(toc::TocList & toclist, Buffer const & buffer) const +{ + if (!loadIfNeeded(buffer, params_)) + return; + + string const included_file = includedFilename(buffer, params_); + Buffer const * const childbuffer = theBufferList().getBuffer(included_file); + toc::TocList const childtoclist = toc::getTocList(*childbuffer); + toc::TocList::const_iterator it = childtoclist.begin(); + toc::TocList::const_iterator const end = childtoclist.end(); + for(; it != end; ++it) + toclist[it->first].insert(toclist[it->first].end(), + it->second.begin(), it->second.end()); +} + + +void InsetInclude::updateLabels(Buffer const & buffer) const +{ + if (!loadIfNeeded(buffer, params_)) + return; + + string const included_file = includedFilename(buffer, params_); + Buffer const * const childbuffer = theBufferList().getBuffer(included_file); + lyx::updateLabels(*childbuffer, true); +} + + string const InsetIncludeMailer::name_("include"); InsetIncludeMailer::InsetIncludeMailer(InsetInclude & inset) Index: src/TocBackend.C =================================================================== --- src/TocBackend.C (Revision 15835) +++ src/TocBackend.C (Arbeitskopie) @@ -26,6 +26,7 @@ #include "frontends/LyXView.h" #include "insets/insetfloat.h" +#include "insets/insetinclude.h" #include "insets/insetoptarg.h" #include "insets/insetwrap.h" @@ -175,6 +176,10 @@ void TocBackend::update() static_cast<InsetFloat*>(it->inset) ->addToToc(tocs_, *buffer_); break; + case InsetBase::INCLUDE_CODE: + static_cast<InsetInclude*>(it->inset) + ->addToToc(tocs_, *buffer_); + break; case InsetBase::WRAP_CODE: static_cast<InsetWrap*>(it->inset) ->addToToc(tocs_, *buffer_); Index: src/BufferView.C =================================================================== --- src/BufferView.C (Revision 15835) +++ src/BufferView.C (Arbeitskopie) @@ -727,21 +727,32 @@ bool BufferView::dispatch(FuncRequest co case LFUN_PARAGRAPH_GOTO: { int const id = convert<int>(to_utf8(cmd.argument())); - ParIterator par = buffer_->getParFromID(id); - if (par == buffer_->par_iterator_end()) { - lyxerr[Debug::INFO] << "No matching paragraph found! [" - << id << ']' << endl; - break; - } else { - lyxerr[Debug::INFO] << "Paragraph " << par->id() - << " found." << endl; + int i = 0; + for (Buffer * b = buffer_; i == 0 || b != buffer_; b = theBufferList().next(b)) { + ParIterator par = b->getParFromID(id); + if (par == b->par_iterator_end()) { + lyxerr[Debug::INFO] + << "No matching paragraph found! [" + << id << "'], buffer `" + << b->fileName() << "'." << endl; + } else { + lyxerr[Debug::INFO] + << "Paragraph " << par->id() + << " found in buffer `" + << b->fileName() << "'." << endl; + + if (b != buffer_) + setBuffer(b); + + // Set the cursor + setCursor(makeDocIterator(par, 0)); + + update(); + switchKeyMap(); + break; + } + ++i; } - - // Set the cursor - setCursor(makeDocIterator(par, 0)); - - update(); - switchKeyMap(); break; } Index: src/buffer_funcs.C =================================================================== --- src/buffer_funcs.C (Revision 15835) +++ src/buffer_funcs.C (Arbeitskopie) @@ -38,6 +38,7 @@ #include "frontends/Alert.h" #include "insets/insetbibitem.h" +#include "insets/insetinclude.h" #include "support/filetools.h" #include "support/fs_extras.h" @@ -349,11 +350,9 @@ bool needEnumCounterReset(ParIterator co // set the label of a paragraph. This includes the counters. -void setLabel(Buffer const & buf, ParIterator & it) +void setLabel(Buffer const & buf, ParIterator & it, LyXTextClass const & textclass) { Paragraph & par = *it; - BufferParams const & bufparams = buf.params(); - LyXTextClass const & textclass = bufparams.getLyXTextClass(); LyXLayout_ptr const & layout = par.layout(); Counters & counters = textclass.counters(); @@ -395,7 +394,7 @@ void setLabel(Buffer const & buf, ParIte // At some point of time we should do something more // clever here, like: // par.params().labelString( - // bufparams.user_defined_bullet(par.itemdepth).getText()); + // buf.params().user_defined_bullet(par.itemdepth).getText()); // for now, use a simple hardcoded label docstring itemlabel; switch (par.itemdepth) { @@ -528,7 +527,7 @@ bool updateCurrentLabel(Buffer const & b case LABEL_CENTERED_TOP_ENVIRONMENT: case LABEL_STATIC: case LABEL_ITEMIZE: - setLabel(buf, it); + setLabel(buf, it, buf.params().getLyXTextClass()); return true; case LABEL_SENSITIVE: @@ -544,33 +543,44 @@ bool updateCurrentLabel(Buffer const & b void updateLabels(Buffer const & buf, - ParIterator & from, ParIterator & to) + ParIterator & from, ParIterator & to, bool childonly) { for (ParIterator it = from; it != to; ++it) { if (it.pit() > it.lastpit()) return; if (!updateCurrentLabel (buf, it)) { - updateLabels(buf); + updateLabels(buf, childonly); return; } } } -void updateLabels(Buffer const & buf, - ParIterator & iter) +void updateLabels(Buffer const & buf, ParIterator & iter, bool childonly) { if (updateCurrentLabel(buf, iter)) return; - updateLabels(buf); + updateLabels(buf, childonly); } -void updateLabels(Buffer const & buf) +void updateLabels(Buffer const & buf, bool childonly) { - // start over the counters - buf.params().getLyXTextClass().counters().reset(); + // Use the master text class also for child documents + LyXTextClass const & textclass = buf.params().getLyXTextClass(); + + if (!childonly) { + // If this is a child document start with the master + Buffer const * const master = buf.getMasterBuffer(); + if (master != &buf) { + updateLabels(*master); + return; + } + + // start over the counters + textclass.counters().reset(); + } ParIterator const end = par_iterator_end(buf.inset()); @@ -584,7 +594,16 @@ void updateLabels(Buffer const & buf) it->params().depth(0); // set the counter for this paragraph - setLabel(buf, it); + setLabel(buf, it, textclass); + + // Now included docs + InsetList::const_iterator iit = it->insetlist.begin(); + InsetList::const_iterator end = it->insetlist.end(); + for (; iit != end; ++iit) { + if (iit->inset->lyxCode() == InsetBase::INCLUDE_CODE) + static_cast<InsetInclude const *>(iit->inset) + ->updateLabels(buf); + } } toc::updateToc(buf);