From: Bo Peng Date: Tue, 5 Jun 2007 17:24:11 +0000 (+0000) Subject: addToToc, pass parent ParConstIterator, fix bug 3711 X-Git-Tag: 1.6.10~9475 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=d3e30f8d9b68d51141290c7f4888040e9cfbaffa;p=features.git addToToc, pass parent ParConstIterator, fix bug 3711 git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18680 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/TocBackend.cpp b/src/TocBackend.cpp index 5adc71d486..db72abdff3 100644 --- a/src/TocBackend.cpp +++ b/src/TocBackend.cpp @@ -184,7 +184,7 @@ void TocBackend::update() InsetList::const_iterator end = pit->insetlist.end(); for (; it != end; ++it) { Inset & inset = *it->inset; - inset.addToToc(tocs_, *buffer_); + inset.addToToc(tocs_, *buffer_, pit); switch (inset.lyxCode()) { case Inset::OPTARG_CODE: { if (!tocstring.empty()) diff --git a/src/insets/Inset.h b/src/insets/Inset.h index a6b5090ef4..c98dcc3a97 100644 --- a/src/insets/Inset.h +++ b/src/insets/Inset.h @@ -30,6 +30,7 @@ namespace lyx { class Buffer; class BufferParams; class BufferView; +class ParConstIterator; class CursorSlice; class FuncRequest; class FuncStatus; @@ -425,7 +426,8 @@ public: */ virtual void addPreview(graphics::PreviewLoader &) const {} /// Add an entry to the TocList - virtual void addToToc(TocList &, Buffer const &) const {} + /// pit is the ParConstIterator of the paragraph containing the inset + virtual void addToToc(TocList &, Buffer const &, ParConstIterator & pit) const {} public: /// returns LyX code associated with the inset. Used for TOC, ...) diff --git a/src/insets/InsetCaption.cpp b/src/insets/InsetCaption.cpp index 81643de19f..831032b039 100644 --- a/src/insets/InsetCaption.cpp +++ b/src/insets/InsetCaption.cpp @@ -115,7 +115,7 @@ void InsetCaption::setCustomLabel(docstring const & label) } -void InsetCaption::addToToc(TocList & toclist, Buffer const & buf) const +void InsetCaption::addToToc(TocList & toclist, Buffer const & buf, ParConstIterator &) const { if (type_.empty()) return; diff --git a/src/insets/InsetCaption.h b/src/insets/InsetCaption.h index 2e5fe4febd..476f11bcca 100644 --- a/src/insets/InsetCaption.h +++ b/src/insets/InsetCaption.h @@ -84,7 +84,7 @@ public: /// void setCustomLabel(docstring const & label); /// - void addToToc(TocList &, Buffer const &) const; + void addToToc(TocList &, Buffer const &, ParConstIterator &) const; /// Captions don't accept alignment, spacing, etc. bool forceDefaultParagraphs(idx_type) const { return true; } diff --git a/src/insets/InsetFloat.cpp b/src/insets/InsetFloat.cpp index 1809f6bbcd..c83fb96635 100644 --- a/src/insets/InsetFloat.cpp +++ b/src/insets/InsetFloat.cpp @@ -386,31 +386,6 @@ void InsetFloat::sideways(bool s, BufferParams const & bp) } -void InsetFloat::addToToc(TocList & toclist, Buffer const & buf) const -{ - // Is there a need to provide a list of float insets? - return; - - // Abdel (01/02/2006): I'll let this code for reference in case - // there's a need to do something similar for another kind of - // inset. - ParConstIterator pit = par_const_iterator_begin(*this); - ParConstIterator end = par_const_iterator_end(*this); - - // Find a caption layout in one of the (child inset's) pars - for (; pit != end; ++pit) { - if (pit->layout()->labeltype == LABEL_SENSITIVE) { - Toc & toc = toclist[params_.type]; - docstring const str = - convert(toc.size() + 1) - + ". " + pit->asString(buf, false); - toc.push_back(TocItem(pit, 0, str)); - return; - } - } -} - - string const InsetFloatMailer::name_("float"); InsetFloatMailer::InsetFloatMailer(InsetFloat & inset) diff --git a/src/insets/InsetFloat.h b/src/insets/InsetFloat.h index febbc1dd21..21abf3be59 100644 --- a/src/insets/InsetFloat.h +++ b/src/insets/InsetFloat.h @@ -82,8 +82,6 @@ public: /// void sideways(bool s, BufferParams const &); /// - void addToToc(TocList &, Buffer const &) const; - /// bool showInsetDialog(BufferView *) const; /// InsetFloatParams const & params() const { return params_; } diff --git a/src/insets/InsetInclude.cpp b/src/insets/InsetInclude.cpp index 05bc607bb0..5c14ba8a0f 100644 --- a/src/insets/InsetInclude.cpp +++ b/src/insets/InsetInclude.cpp @@ -881,8 +881,21 @@ void InsetInclude::addPreview(graphics::PreviewLoader & ploader) const } -void InsetInclude::addToToc(TocList & toclist, Buffer const & buffer) const +void InsetInclude::addToToc(TocList & toclist, Buffer const & buffer, ParConstIterator & pit) const { + if (isListings(params_)) { + InsetListingsParams params(params_.getOptions()); + string caption = params.getParamValue("caption"); + if (!caption.empty()) { + Toc & toc = toclist["listing"]; + docstring const str = convert(toc.size() + 1) + + ". " + params_["filename"]; + // This inset does not have a valid ParConstIterator + // so it has to use the iterator of its parent paragraph + toc.push_back(TocItem(pit, 0, str)); + } + return; + } Buffer const * const childbuffer = getChildBuffer(buffer, params_); if (!childbuffer) return; diff --git a/src/insets/InsetInclude.h b/src/insets/InsetInclude.h index 34acab4a41..873521592e 100644 --- a/src/insets/InsetInclude.h +++ b/src/insets/InsetInclude.h @@ -95,7 +95,7 @@ public: /// void addPreview(graphics::PreviewLoader &) const; /// - void addToToc(TocList &, Buffer const &) const; + void addToToc(TocList &, Buffer const &, ParConstIterator &) const; /// void updateLabels(Buffer const & buffer) const; /// diff --git a/src/insets/InsetWrap.cpp b/src/insets/InsetWrap.cpp index 45a5d8ebdf..ee37625c87 100644 --- a/src/insets/InsetWrap.cpp +++ b/src/insets/InsetWrap.cpp @@ -234,13 +234,6 @@ bool InsetWrap::showInsetDialog(BufferView * bv) const } -void InsetWrap::addToToc(TocList & toclist, Buffer const & buf) const -{ - // Is there a need to provide a list of wrap insets? - return; -} - - string const InsetWrapMailer::name_("wrap"); InsetWrapMailer::InsetWrapMailer(InsetWrap & inset) diff --git a/src/insets/InsetWrap.h b/src/insets/InsetWrap.h index c2ec7d9716..d8f5acae93 100644 --- a/src/insets/InsetWrap.h +++ b/src/insets/InsetWrap.h @@ -66,8 +66,6 @@ public: /// bool insetAllowed(Inset::Code) const; /// - void addToToc(TocList &, Buffer const &) const; - /// bool showInsetDialog(BufferView *) const; /// InsetWrapParams const & params() const { return params_; }