]> git.lyx.org Git - features.git/commitdiff
addToToc, pass parent ParConstIterator, fix bug 3711
authorBo Peng <bpeng@lyx.org>
Tue, 5 Jun 2007 17:24:11 +0000 (17:24 +0000)
committerBo Peng <bpeng@lyx.org>
Tue, 5 Jun 2007 17:24:11 +0000 (17:24 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18680 a592a061-630c-0410-9148-cb99ea01b6c8

src/TocBackend.cpp
src/insets/Inset.h
src/insets/InsetCaption.cpp
src/insets/InsetCaption.h
src/insets/InsetFloat.cpp
src/insets/InsetFloat.h
src/insets/InsetInclude.cpp
src/insets/InsetInclude.h
src/insets/InsetWrap.cpp
src/insets/InsetWrap.h

index 5adc71d48615cfd33bd1c701a1ebe86dad1b74ad..db72abdff387379ac4f3ef4566010934a3458d7f 100644 (file)
@@ -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())
index a6b5090ef458b42e6c29a0c72c36a15a864ebef5..c98dcc3a973c1ac506c982ccd5bd34087ad821c6 100644 (file)
@@ -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, ...)
index 81643de19fadb966413eef6c50418371d2fed6a6..831032b039b31a79bd351a5cf40eb7b0d6ba396a 100644 (file)
@@ -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;
index 2e5fe4febd3d16567ba33d396eb02f0d316d354b..476f11bcca5b98a8846d7a9bfdc6dd7f97a277ca 100644 (file)
@@ -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; }
 
index 1809f6bbcd12c5e7095d41a98492d8cc18c0abb6..c83fb96635906cebc028f5192fbd17cbab618eff 100644 (file)
@@ -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<docstring>(toc.size() + 1)
-                               + ". " + pit->asString(buf, false);
-                       toc.push_back(TocItem(pit, 0, str));
-                       return;
-               }
-       }
-}
-
-
 string const InsetFloatMailer::name_("float");
 
 InsetFloatMailer::InsetFloatMailer(InsetFloat & inset)
index febbc1dd213491f3872af975d6c0a4e17445be83..21abf3be595e5fb734c58ff77116e9136f81491a 100644 (file)
@@ -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_; }
index 05bc607bb02cb729eabea7dfccf0b7b6e4b0c95c..5c14ba8a0f4fa15a9aa831b8c3623c5bd7660e83 100644 (file)
@@ -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<docstring>(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;
index 34acab4a41c80c92f087e6d4ca1a847f48b4311f..873521592e0029eba0bd483603bfa28f6162321b 100644 (file)
@@ -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;
        ///
index 45a5d8ebdfc14b2998e0296005c73695677b36f5..ee37625c873c168abd4f191675628c69d3a7101c 100644 (file)
@@ -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)
index c2ec7d9716a3cea410d65d8b7de0dd6370d21e1f..d8f5acae931da6dc6f78566c0cdca06022196049 100644 (file)
@@ -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_; }